Class: RaptorIO::Socket::Comm::SOCKS

Inherits:
RaptorIO::Socket::Comm show all
Defined in:
lib/raptor-io/socket/comm/socks.rb

Overview

Communication through a SOCKS proxy

Defined Under Namespace

Modules: AddressTypes, ReplyCodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RaptorIO::Socket::Comm

#create, #create_tcp_server, #create_udp, #create_udp_server, from_uri, #resolve, #reverse_resolve

Constructor Details

#initialize(options = {}) ⇒ SOCKS

Returns a new instance of SOCKS.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):



59
60
61
62
63
# File 'lib/raptor-io/socket/comm/socks.rb', line 59

def initialize(options = {})
  @socks_host = options[:socks_host]
  @socks_port = options[:socks_port].to_i
  @socks_comm = options[:socks_comm]
end

Instance Attribute Details

#socks_commComm

The RaptorIO::Socket::Comm used to connect to the SOCKS server

Returns:



21
22
23
# File 'lib/raptor-io/socket/comm/socks.rb', line 21

def socks_comm
  @socks_comm
end

#socks_hostString

The SOCKS server’s address

Returns:



13
14
15
# File 'lib/raptor-io/socket/comm/socks.rb', line 13

def socks_host
  @socks_host
end

#socks_portFixnum

The SOCKS server’s port

Returns:

  • (Fixnum)


17
18
19
# File 'lib/raptor-io/socket/comm/socks.rb', line 17

def socks_port
  @socks_port
end

Instance Method Details

#create_tcp(options) ⇒ Socket::TCP

Connect to ‘:peer_host`

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

Returns:

Raises:

  • (RaptorIO::Socket::Error::ConnectTimeout)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/raptor-io/socket/comm/socks.rb', line 83

def create_tcp(options)
  @socks_socket = socks_comm.create_tcp(
    peer_host: socks_host,
    peer_port: socks_port
  )

  negotiate_connection(options[:peer_host], options[:peer_port])

  if options[:ssl_context]
    RaptorIO::Socket::TCP::SSL.new(@socks_socket, options)
  else
    RaptorIO::Socket::TCP.new(@socks_socket, options)
  end
end

#support_ipv6?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
# File 'lib/raptor-io/socket/comm/socks.rb', line 66

def support_ipv6?
  begin
    tcp = create_tcp("::1", {})
    tcp.close
    true
  rescue RaptorIO::Error
    nil
  end
end