class RSocks::TargetConnectionHandler

Public Class Methods

new(client, config, connect_data = nil) click to toggle source
# 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

Public Instance Methods

assign_user_and_password(username, password) click to toggle source
# File lib/r_socks/target_connection_handler.rb, line 15
def assign_user_and_password(username, password)
  @username = username
  @password = password
end
connection_completed() click to toggle source
# 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_unbound() click to toggle source
# File lib/r_socks/target_connection_handler.rb, line 37
def proxy_target_unbound
  close_connection
end
receive_data(data) click to toggle source
# 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
unbind() click to toggle source
# 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

Private Instance Methods

response_proxy_connect_ready() click to toggle source
# File lib/r_socks/target_connection_handler.rb, line 50
def response_proxy_connect_ready
  if @config.proxy_type == :http
    @client.send_data(RSocks::HttpProxyResponseCodes::SUCCESS)
  end
  @client.proxy_incoming_to(self, @config.proxy_buffer_size)
  proxy_incoming_to(@client, @config.proxy_buffer_size)
end