Class: DRb::DRbSSLSocket

Inherits:
DRbTCPSocket show all
Defined in:
lib/drb/ssl.rb

Defined Under Namespace

Classes: SSLConfig

Instance Attribute Summary

Attributes inherited from DRbTCPSocket

#uri

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from DRbTCPSocket

#alive?, getservername, open_server_inaddr_any, #peeraddr, #recv_reply, #recv_request, #send_reply, #send_request, #set_sockopt

Constructor Details

- (DRbSSLSocket) initialize(uri, soc, config, is_established)

A new instance of DRbSSLSocket



158
159
160
161
# File 'lib/drb/ssl.rb', line 158

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

Class Method Details

+ (Object) open(uri, config)



124
125
126
127
128
129
130
131
132
133
# File 'lib/drb/ssl.rb', line 124

def self.open(uri, config)
  host, port, option = parse_uri(uri)
  host.untaint
  port.untaint
  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

+ (Object) open_server(uri, config)



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/drb/ssl.rb', line 135

def self.open_server(uri, config)
  uri = 'drbssl://:0' unless uri
  host, port, opt = 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

+ (Object) parse_uri(uri)



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/drb/ssl.rb', line 112

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

+ (Object) uri_option(uri, config)



153
154
155
156
# File 'lib/drb/ssl.rb', line 153

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

Instance Method Details

- (Object) accept



173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/drb/ssl.rb', line 173

def accept
  begin
  while true
	soc = @socket.accept
	break if (@acl ? @acl.allow_socket?(soc) : true)
	soc.close
  end
  ssl = @config.accept(soc)
  self.class.new(uri, ssl, @config, true)
  rescue OpenSSL::SSL::SSLError
	warn("#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})") if @config[:verbose]
	retry
  end
end

- (Object) close



165
166
167
168
169
170
171
# File 'lib/drb/ssl.rb', line 165

def close
  if @ssl
	@ssl.close
	@ssl = nil
  end
  super
end

- (Object) stream



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

def stream; @ssl; end