Sha256: 26b50e5d6b4c3a43335cee0478d53468cbb7c9ea581582c118ed262b1e3704c2

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Sockit
  module Connection

    def direct_connect(socket, remote_host, remote_port, local_host=nil, local_port=nil)
      Sockit.enabled? and log(:yellow, "Directly connecting to #{remote_host}:#{remote_port}")
      socket.__send__(:initialize_tcp, remote_host, remote_port, local_host=nil, local_port=nil)
      Sockit.enabled? and log(:green, "Connected to #{remote_host}:#{remote_port}")
    end

    def connect(socket, host, port)
      log(:yellow, "Connecting to SOCKS v#{config.version} server #{config.host}:#{config.port}")

      # when doing proxy mode on SS5; we seemingly need to resolve all names first.
      host = Sockit.resolve(host)

      data = case config.version.to_i
      when 4 then
        build_v4_connection_request(host, port)
      when 5 then
        build_v5_connection_request(host, port)
      end
      data = data.flatten.join

      log(:yellow, "Requesting SOCKS v#{config.version} connection to #{host}:#{port}")
      dump(:write, data)
      socket.write(data)

      log(:yellow, "Waiting for SOCKS v#{config.version} connection reply")
      host, port = case config.version.to_i
      when 4 then
        process_v4_connection_response(socket)
      when 5 then
        process_v5_connection_response(socket)
      end
      log(:green, [host, port].inspect)

      log(:green, "Connected to #{host}:#{port} via SOCKS v#{config.version} server #{config.host}:#{config.port}")
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sockit-1.2.3 lib/sockit/connection.rb