Class: RaptorIO::Socket::Comm

Inherits:
Object
  • Object
show all
Defined in:
lib/raptor-io/socket/comm.rb

Overview

Provides the basic interface that a derived class must implement in order to be a routable socket creator.

See Local for an implementation using sockets created with standard Ruby Socket classes.

Subclasses must implement the following methods:

* `resolve`
* `create_tcp`
* `create_tcp_server`
* `create_udp`
* `create_udp_server`
* `support_ipv6?`

Direct Known Subclasses

Local, SAPNI, SOCKS

Defined Under Namespace

Classes: Local, SAPNI, SOCKS

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_uri(uri, opts = {}) ⇒ Object

Parameters:

  • uri (URI)

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/raptor-io/socket/comm.rb', line 29

def self.from_uri(uri, opts = {})
  raise ArgumentError unless uri.kind_of? URI

  prev_comm = opts[:prev_comm] || RaptorIO::Socket::Comm::Local.new

  comm = case uri.scheme.downcase
         when "sapni"
           uri.port ||= 3299
           RaptorIO::Socket::Comm::SAPNI.new(
             sap_host: uri.host,
             sap_port: uri.port,
             sap_comm: prev_comm,
           )
         when "socks"
           uri.port ||= 1080
           RaptorIO::Socket::Comm::SOCKS.new(
             socks_host: uri.host,
             socks_port: uri.port,
             socks_comm: prev_comm,
           )
         end

  comm
end

Instance Method Details

#create(options) ⇒ RaptorIO::Socket

Creates a socket on this Comm based on the supplied uniform parameters.

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :switch_board (SwitchBoard)
  • :port (Fixnum)

    Optional based on proto

  • :protocol (Symbol)
    • ':tcp`

    • ':udp`

Returns:



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

def create( options )
  options = options.dup
  options[:peer_host] = IPAddr.parse(options[:peer_host])

  case options.delete(:protocol)
    when :tcp
      options[:server] ? create_tcp_server(options) : create_tcp(options)

    when :udp
      options[:server] ? create_udp_server(options) : create_udp(options)
  end
end

#create_tcp(options) ⇒ RaptorIO::Socket::TCP

This method is abstract.

Connect to a host over TCP.

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

Returns:

Raises:

  • (NotImplementedError)


104
105
106
# File 'lib/raptor-io/socket/comm.rb', line 104

def create_tcp(options)
  raise NotImplementedError
end

#create_tcp_server(options) ⇒ Object

This method is abstract.

Create a TCP server listening on :local_port

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :local_host (String, IPAddr)
  • :local_port (Fixnum)
  • :ssl_context (OpenSSL::SSL::Context)

Raises:

  • (NotImplementedError)


127
128
129
# File 'lib/raptor-io/socket/comm.rb', line 127

def create_tcp_server(options)
  raise NotImplementedError
end

#create_udp(options) ⇒ Object

This method is abstract.

Create a UDP socket bound to the given :peer_host

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

Raises:

  • (NotImplementedError)


116
117
118
# File 'lib/raptor-io/socket/comm.rb', line 116

def create_udp(options)
  raise NotImplementedError
end

#create_udp_server(options) ⇒ Object

This method is abstract.

Create a UDP server listening on :local_port

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

Raises:

  • (NotImplementedError)


137
138
139
# File 'lib/raptor-io/socket/comm.rb', line 137

def create_udp_server(options)
  raise NotImplementedError
end

#resolve(hostname) ⇒ Object

This method is abstract.

Resolves a hostname to an IP address using this comm.

Parameters:

Raises:

  • (NotImplementedError)


82
83
84
# File 'lib/raptor-io/socket/comm.rb', line 82

def resolve( hostname )
  raise NotImplementedError
end

#reverse_resolve(ip_address) ⇒ Object

This method is abstract.

Resolves an IP address to a hostname using this comm.

Parameters:

Raises:

  • (NotImplementedError)


91
92
93
# File 'lib/raptor-io/socket/comm.rb', line 91

def reverse_resolve( ip_address )
  raise NotImplementedError
end