Module: SocksHandler::SocketSocksify

Defined in:
lib/socks_handler/socket_socksify.rb

Instance Method Summary collapse

Instance Method Details

#tcp(remote_host, remote_port, local_host = nil, local_port = nil, connect_timeout: nil, resolv_timeout: nil, &block) ⇒ Socket

Parameters:

  • remote_host (String)
  • remote_port (Integer, String)
  • local_host (String, nil) (defaults to: nil)
  • local_port (Integer, String) (defaults to: nil)
  • connect_timeout (Integer, Float, nil) (defaults to: nil)
  • resolv_timeout (Integer, Float, nil) (defaults to: nil)

Returns:

  • (Socket)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/socks_handler/socket_socksify.rb', line 12

def tcp(remote_host, remote_port, local_host = nil, local_port = nil, connect_timeout: nil, resolv_timeout: nil, &block)
  rule = SocksHandler::TCP.find_rule(remote_host)
  return super if rule.nil? || rule.direct

  socket = super(rule.host, rule.port, local_host, local_port, connect_timeout: connect_timeout, resolv_timeout: resolv_timeout, &block)
  begin
    SocksHandler::TCP.establish_connection(socket, remote_host, remote_port, rule.username, rule.password)
  rescue
    socket.close
    raise
  end

  socket
end