dRuby URIs and protocols: druby://, drbunix: and drbssl://
The three protocols that ship with dRuby, what each URI looks like, and which file to require for UNIX sockets and SSL.
Updated
A dRuby URI names the protocol and the address a service listens on. Three protocols come with the library: druby:// for plain TCP, drbunix: for UNIX domain sockets, and drbssl:// for TCP wrapped in SSL/TLS. The first is always available; the other two are loaded with an extra require.
druby:// (TCP)
require 'drb/drb'
DRb.start_service('druby://localhost:8787', front)
The form is druby://host:port.
druby://localhost:8787listens on the loopback interface only. Use this unless you have a reason not to.druby://localhost:0asks the operating system for any free port. Read the real address back fromDRb.uri.druby://:8787, with the host left out, listens on all network interfaces. That exposes the service to every network the machine is on, so read the safety pages first.DRb.start_servicewith no URI at all picks a port for you. That is the usual choice for clients.
DRb.start_service('druby://localhost:0', front)
puts DRb.uri # => "druby://localhost:51234" (the port varies)
drbunix: (UNIX domain sockets)
require 'drb/drb'
require 'drb/unix'
DRb.start_service('drbunix:/tmp/notebook.sock', front)
The form is drbunix: followed by the path of the socket file. Nothing is opened on the network, so only processes on the same machine can connect, and ordinary file permissions decide which users can. The server accepts a :UNIXFileMode option to set those permissions:
DRb.start_service('drbunix:/tmp/notebook.sock', front, { UNIXFileMode: 0600 })
The client must also require 'drb/unix' before it uses a drbunix: URI. This protocol is not available on platforms without UNIX domain sockets.
drbssl:// (TCP with SSL/TLS)
require 'drb/drb'
require 'drb/ssl'
The form is drbssl://host:port. Certificates, keys and verification settings are passed in the config hash given to DRb.start_service. There is an example on localhost, UNIX sockets and SSL.
The client uses the same URI
Whatever protocol the server uses, the client passes the same string to DRbObject.new_with_uri and must have required the same protocol file.
require 'drb/drb'
require 'drb/unix'
DRb.start_service
notebook = DRbObject.new_with_uri('drbunix:/tmp/notebook.sock')
The client's own service, the one that receives callbacks, does not have to use the same protocol as the server it calls.
Choosing
| Situation | Protocol |
|---|---|
| Processes on one machine | drbunix: or druby://localhost |
| Machines on a trusted private network | druby:// with an ACL |
| Traffic that must be encrypted and authenticated | drbssl:// with client certificates |
No protocol makes it safe to offer dRuby to callers you do not trust.