123456789_123456789_123456789_123456789_123456789_

Class: DRb::DRbSSLSocket

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, DRbTCPSocket
Instance Chain:
self, DRbTCPSocket
Inherits: DRb::DRbTCPSocket
Defined in: lib/drb/ssl.rb

Overview

The protocol for ::DRb over an SSL socket

The URI for a ::DRb socket over SSL is: drbssl://<host>:<port>?<option>. The option is optional

Class Method Summary

DRbTCPSocket - Inherited

.getservername

Returns the hostname of this server.

.new

Create a new DRbTCPSocket instance.

.open

Open a client connection to uri (DRb URI string) using configuration config.

.open_server

Open a server listening for connections at uri using configuration config.

.open_server_inaddr_any

For the families available for host, returns a TCPServer on port.

.uri_option

Parse uri into a [uri, option] pair.

.parse_uri

Instance Attribute Summary

DRbTCPSocket - Inherited

#alive?

Check to see if this connection is alive.

#uri

Get the URI that we are connected to.

Instance Method Summary

  • #accept Internal use only
  • #close Internal use only

    Closes the SSL stream before closing the dRuby connection.

  • #stream Internal use only

    Returns the SSL stream.

DRbTCPSocket - Inherited

#accept

On the server side, for an instance returned by #open_server, accept a client connection and return a new instance to handle the server’s side of this client-server session.

#close

Close the connection.

#peeraddr

Get the address of our TCP peer (the other end of the socket we are bound to.

#recv_reply

On the client side, receive a reply from the server.

#recv_request

On the server side, receive a request from the client.

#send_reply

On the server side, send a reply to the client.

#send_request

On the client side, send a request to the server.

#set_sockopt,
#shutdown

Graceful shutdown.

#stream

Get the socket.

#accept_or_shutdown, #close_shutdown_pipe

Constructor Details

.new(uri, soc, config, is_established) ⇒ DRbSSLSocket

Create a DRbSSLSocket instance.

DRb.uri is the URI we are connected to. soc is the tcp socket we are bound to. DRb.config is our configuration. Either a Hash or DRbSSLSocket::SSLConfig is_established is a boolean of whether soc is currently established

This is called automatically based on the ::DRb protocol.

[ GitHub ]

  
# File 'lib/drb/ssl.rb', line 314

def initialize(uri, soc, config, is_established)
  @ssl = is_established ? soc : nil
  super(uri, soc.to_io, config)
end

Class Method Details

.open(uri, config)

Return an DRbSSLSocket instance as a client-side connection, with the SSL connected. This is called from DRb.start_service or while connecting to a remote object:

DRb.start_service 'drbssl://localhost:0', front, config

DRb.uri is the URI we are connected to, 'drbssl://localhost:0' above, DRb.config is our configuration. Either a Hash or DRbSSLSocket::SSLConfig

[ GitHub ]

  
# File 'lib/drb/ssl.rb', line 259

def self.open(uri, config)
  host, port, = parse_uri(uri)
  soc = TCPSocket.open(host, port)
  ssl_conf = SSLConfig::new(config)
  ssl_conf.setup_ssl_context
  ssl = ssl_conf.connect(soc)
  self.new(uri, ssl, ssl_conf, true)
end

.open_server(uri, config)

Returns a DRbSSLSocket instance as a server-side connection, with the SSL connected. This is called from DRb.start_service or while connecting to a remote object:

DRb.start_service 'drbssl://localhost:0', front, config

DRb.uri is the URI we are connected to, 'drbssl://localhost:0' above, DRb.config is our configuration. Either a Hash or DRbSSLSocket::SSLConfig

[ GitHub ]

  
# File 'lib/drb/ssl.rb', line 277

def self.open_server(uri, config)
  uri = 'drbssl://:0' unless uri
  host, port, = parse_uri(uri)
  if host.size == 0
    host = getservername
    soc = open_server_inaddr_any(host, port)
  else
    soc = TCPServer.open(host, port)
  end
  port = soc.addr[1] if port == 0
  @uri = "drbssl://#{host}:#{port}"

  ssl_conf = SSLConfig.new(config)
  ssl_conf.setup_certificate
  ssl_conf.setup_ssl_context
  self.new(@uri, soc, ssl_conf, false)
end

.parse_uri(uri)

This method is for internal use only.

Parse the dRuby DRb.uri for an SSL connection.

Expects drbssl://…

Raises DRbBadScheme or DRbBadURI if DRb.uri is not matching or malformed

[ GitHub ]

  
# File 'lib/drb/ssl.rb', line 238

def self.parse_uri(uri) # :nodoc:
  if /\Adrbssl:\/\/(.*?):(\d+)(\?(.*))?\z/ =~ uri
    host = $1
    port = $2.to_i
    option = $4
    [host, port, option]
  else
    raise(DRbBadScheme, uri) unless uri.start_with?('drbssl:')
    raise(DRbBadURI, 'can\'t parse uri:' + uri)
  end
end

.uri_option(uri, config)

This method is for internal use only.

This is a convenience method to parse DRb.uri and separate out any additional options appended in the DRb.uri.

Returns an option-less uri and the option => [uri,option]

The DRb.config is completely unused, so passing nil is sufficient.

[ GitHub ]

  
# File 'lib/drb/ssl.rb', line 301

def self.uri_option(uri, config) # :nodoc:
  host, port, option = parse_uri(uri)
  return "drbssl://#{host}:#{port}", option
end

Instance Method Details

#accept

This method is for internal use only.
[ GitHub ]

  
# File 'lib/drb/ssl.rb', line 331

def accept # :nodoc:
  begin
  while true
    soc = accept_or_shutdown
    return nil unless soc
    break if (@acl ? @acl.allow_socket?(soc) : true)
    soc.close
  end
  begin
    ssl = @config.accept(soc)
  rescue Exception
    soc.close
    raise
  end
  self.class.new(uri, ssl, @config, true)
  rescue OpenSSL::SSL::SSLError
    warn("#{$!.message} (#{$!.class})", uplevel: 0) if @config[:verbose]
    retry
  end
end

#close

This method is for internal use only.

Closes the SSL stream before closing the dRuby connection.

[ GitHub ]

  
# File 'lib/drb/ssl.rb', line 323

def close # :nodoc:
  if @ssl
    @ssl.close
    @ssl = nil
  end
  super
end

#stream

This method is for internal use only.

Returns the SSL stream

[ GitHub ]

  
# File 'lib/drb/ssl.rb', line 320

def stream; @ssl; end # :nodoc: