Next: , Previous: , Up: Netlayers   [Contents][Index]


7.6.3 Unix domain socket

The Unix domain socket netlayer is designed to be a fast and secure means of communication between processes on the same machine. In order for Unix domain sockets to be capability-secure, file names cannot be used. Instead, this netlayer relies on the unique ability of Unix domain sockets to transfer file descriptors. In other words, file descriptors are capabilities but file names are not.

To initiate a connection between two peers without the use of file names, trusted daemons known as “introduction servers” are used. First, an anonymous (not on the file system) Unix domain socket pair is created on peer A. Then, the file descriptor for one of the sockets is passed to the introduction server. Finally, the introduction server will lookup the desired recipient, peer B, and pass the file descriptor to it. Note that the introduction server is only needed for connection establishment; it is not a relay. Once initialization is complete, communication between peers A and B is direct.

Constructor: ^unix-domain-socket-netlayer

Spawn a new Unix domain socket netlayer.

Once spawned the netlayer needs at least one introduction server to be provided. This can be done using the add-server method on the netlayer, which takes one argument, a socket which is already connected to a Unix domain socket introduction server. The method returns a promise which will be fulfilled if the netlayer disconnects from the introduction server provided in the add-server call.

Multiple introduction servers can be used by calling add-server several times.

;; Setup the socket to the intro server.
(define intro-server-sock
  (make-unix-domain-socket))

(define address (make-socket-address AF_UNIX "/tmp/the-intro-server.sock"))
(connect intro-server-sock-sock address)

;; Spawn the netlayer
(define ocapn-vat (spawn-vat #:name "OCapN"))
(define mycapn
  (with-vat ocapn-vat
    (define netlayer (spawn ^unix-domain-socket-netlayer))
    ($ netlayer 'add-server intro-server-sock)
    (spawn-mycapn netlayer)))
Persistence Environment: unix-domain-socket-netlayer-env

Next: libp2p, Previous: TCP + TLS, Up: Netlayers   [Contents][Index]