class DRb::DRbSSLSocket
drbssl://<host>:<port>?<option>
. The option is optional
The URI for a DRb socket over SSL is:
The protocol for DRb over an SSL socket
def self.open(uri, config)
'drbssl://localhost:0'
above, +config+ is our+uri+ is the URI we are connected to,
DRb.start_service 'drbssl://localhost:0', front, config
connecting to a remote object:
with the SSL connected. This is called from DRb::start_service or while
Return an DRb::DRbSSLSocket instance as a client-side connection,
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
def self.open_server(uri, config)
'drbssl://localhost:0'
above, +config+ is our+uri+ is the URI we are connected to,
DRb.start_service 'drbssl://localhost:0', front, config
connecting to a remote object:
the SSL connected. This is called from DRb::start_service or while
Returns a DRb::DRbSSLSocket instance as a server-side connection, with
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
def self.parse_uri(uri) # :nodoc:
Raises DRbBadScheme or DRbBadURI if +uri+ is not matching or malformed
Expects drbssl://...
Parse the dRuby +uri+ for an SSL connection.
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
def self.uri_option(uri, config) # :nodoc:
The +config+ is completely unused, so passing nil is sufficient.
Returns an option-less uri and the option => [uri,option]
additional options appended in the +uri+.
This is a convenience method to parse +uri+ and separate out any
def self.uri_option(uri, config) # :nodoc: host, port, option = parse_uri(uri) return "drbssl://#{host}:#{port}", option end
def accept # :nodoc:
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
def close # :nodoc:
Closes the SSL stream before closing the dRuby connection.
def close # :nodoc: if @ssl @ssl.close @ssl = nil end super end
def initialize(uri, soc, config, is_established)
+is_established+ is a boolean of whether +soc+ is currently established
+config+ is our configuration. Either a Hash or SSLConfig
+soc+ is the tcp socket we are bound to.
+uri+ is the URI we are connected to.
Create a DRb::DRbSSLSocket instance.
def initialize(uri, soc, config, is_established) @ssl = is_established ? soc : nil super(uri, soc.to_io, config) end
def stream; @ssl; end # :nodoc:
Returns the SSL stream
def stream; @ssl; end # :nodoc: