Class: RSocks::TargetConnectionHandler

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/r_socks/target_connection_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, config, connect_data = nil) ⇒ TargetConnectionHandler

Returns a new instance of TargetConnectionHandler.



7
8
9
10
11
12
13
# File 'lib/r_socks/target_connection_handler.rb', line 7

def initialize(client, config, connect_data = nil)
  @client = client
  @config = config
  @connect_data = connect_data
  @forward_connection = !@connect_data.nil?
  @forward_success = false
end

Instance Method Details

#assign_user_and_password(username, password) ⇒ Object



15
16
17
18
# File 'lib/r_socks/target_connection_handler.rb', line 15

def assign_user_and_password(username, password)
  @username = username
  @password = password
end

#connection_completedObject



20
21
22
23
24
25
26
# File 'lib/r_socks/target_connection_handler.rb', line 20

def connection_completed
  if @connect_data
    send_data(@connect_data)
  else
    response_proxy_connect_ready
  end
end

#proxy_target_unboundObject



37
38
39
# File 'lib/r_socks/target_connection_handler.rb', line 37

def proxy_target_unbound
  close_connection
end

#receive_data(data) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/r_socks/target_connection_handler.rb', line 28

def receive_data(data)
  if @forward_connection && !@forward_success
    if data == RSocks::HttpProxyResponseCodes::SUCCESS
      @forward_success = true
      response_proxy_connect_ready
    end
  end
end

#unbindObject



41
42
43
44
45
46
# File 'lib/r_socks/target_connection_handler.rb', line 41

def unbind
  @client.close_connection_after_writing
  if @config.unbind_handler
    @config.unbind_handler.call(get_proxied_bytes, @username, @password)
  end
end