Method: NATS#process_connect_init

Defined in:
lib/nats/client.rb

#process_connect_init(info) ⇒ Object

:nodoc:

[View source]

934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
# File 'lib/nats/client.rb', line 934

def process_connect_init(info) # :nodoc:
  # Each JSON parser uses a different key/value pair to use symbol keys
  # instead of strings when parsing. Passing all three pairs assures each
  # parser gets what it needs. For the json gem :symbolize_name, for yajl
  # :symbolize_keys, and for oj :symbol_keys.
  @server_info = JSON.parse(info, :symbolize_keys => true, :symbolize_names => true, :symbol_keys => true)

  case
  when (server_using_secure_connection? and client_using_secure_connection?)
    # Allow parameterizing secure connection via EM#start_tls directly if present.
    start_tls(@tls || {})
  when (server_using_secure_connection? and !client_using_secure_connection?)
    # Call unbind since there is a configuration mismatch between client/server
    # anyway and communication cannot happen in this state.
    err_cb.call(NATS::ClientError.new('TLS/SSL required by server'))
    close_connection_after_writing
  when (client_using_secure_connection? and !server_using_secure_connection?)
    err_cb.call(NATS::ClientError.new('TLS/SSL not supported by server'))
    close_connection_after_writing
  else
    # Otherwise, use a regular connection.
  end

  # Check whether there no echo is supported by the server.
  if @options[:no_echo]
    if @server_info[:proto].nil? || @server_info[:proto] < 1
      err_cb.call(NATS::ServerError.new('No echo option not supported by this server'))
      close_connection_after_writing
    end
  end
  send_connect_command

  # Only initial INFO command is treated specially for auth reasons,
  # the rest are processed asynchronously to discover servers.
  @parse_state = AWAITING_CONTROL_LINE
  process_info(info)
  process_connect

  if @server_info[:auth_required]
    current = server_pool.first
    current[:auth_required] = true

    # Send pending connect followed by ping/pong to ensure we're authorized.
    queue_server_rt { current[:auth_ok] = true }
  end
  flush_pending
end