Sha256: d28d656db849527ffaf8158ba5ac0788384fd165d4d6f94d57fc40ff0fe05433

Contents?: true

Size: 938 Bytes

Versions: 1

Compression:

Stored size: 938 Bytes

Contents

require 'eventmachine'
require 'r_socks/http_proxy_response_codes'

module RSocks
  class TargetConnectionHandler < EM::Connection

    def initialize(client, config)
      @client = client
      @config = config
    end

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

    def connection_completed
      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

    def receive_data(data)
      @client.send_data(data)
    end

    def proxy_target_unbound
      close_connection
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
r_socks-0.2.7 lib/r_socks/target_connection_handler.rb