class RaptorIO::Socket::Comm

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

See {RaptorIO::Socket::Comm::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?`

Public Class Methods

from_uri(uri, opts = {}) click to toggle source

@param uri [URI]

# File lib/raptor-io/socket/comm.rb, line 28
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

Public Instance Methods

create( options ) click to toggle source

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

@option options :switch_board [SwitchBoard] @option options :port [Fixnum] Optional based on proto @option options :protocol [Symbol]

* `:tcp`
* `:udp`

@return [RaptorIO::Socket]

# File lib/raptor-io/socket/comm.rb, line 63
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) click to toggle source

Connect to a host over TCP.

@abstract

@option options :peer_host [String,IPAddr] @option options :peer_port [Fixnum] @option options :local_host [String,IPAddr] @option options :local_port [Fixnum] @return [RaptorIO::Socket::TCP]

# File lib/raptor-io/socket/comm.rb, line 103
def create_tcp(options)
  raise NotImplementedError
end
create_tcp_server(options) click to toggle source

Create a TCP server listening on :local_port

@abstract

@option options :local_host [String,IPAddr] @option options :local_port [Fixnum] @option options :ssl_context [OpenSSL::SSL::Context]

# File lib/raptor-io/socket/comm.rb, line 126
def create_tcp_server(options)
  raise NotImplementedError
end
create_udp(options) click to toggle source

Create a UDP socket bound to the given :peer_host

@abstract

@option options :peer_host [String,IPAddr] @option options :peer_port [Fixnum] @option options :local_host [String,IPAddr] @option options :local_port [Fixnum]

# File lib/raptor-io/socket/comm.rb, line 115
def create_udp(options)
  raise NotImplementedError
end
create_udp_server(options) click to toggle source

Create a UDP server listening on :local_port

@abstract

@option options :local_host [String,IPAddr] @option options :local_port [Fixnum]

# File lib/raptor-io/socket/comm.rb, line 136
def create_udp_server(options)
  raise NotImplementedError
end
resolve( hostname ) click to toggle source

Resolves a hostname to an IP address using this comm.

@abstract

@param [String] hostname

# File lib/raptor-io/socket/comm.rb, line 81
def resolve( hostname )
  raise NotImplementedError
end
reverse_resolve( ip_address ) click to toggle source

Resolves an IP address to a hostname using this comm.

@abstract

@param ip_address [String]

# File lib/raptor-io/socket/comm.rb, line 90
def reverse_resolve( ip_address )
  raise NotImplementedError
end