Connectiond is a lightning peer network connection microservice.
Program operations
Since this daemon must operate external P2P TCP socket, and TCP socket can
be either connected to the remote or accept remote connections; and we need
a daemon per connection, while the incoming TCP socket can't be transferred
between processes using IPC, the only option here is to have two special
cases of the daemon.
The first one will open TCP socket in listening mode and wait for incoming
connections, forking on each one of them, passing the accepted TCP socket to
the child and continuing on listening to the new connections. (In
multi-thread mode, differentiated with --threaded argument, instead of
forking damon will launch a new thread).
The second one will be launched by some control process and then commanded
(through command API) to connect to a specific remote TCP socket.
These two cases are differentiated by a presence command-line option
--listen followed by a listening address to bind (IPv4, IPv6, Tor and TCP
port number) or --connect option followed by a remote address in the same
format.
The overall program logic thus is the following:
In the process starting from main():
Parse cli arguments into a config. There is no config file, since the
daemon can be started only from another control process (lnpd) or by
forking itself.
If --listen argument is present, start a listening version as described
above and open TCP port in listening mode; wait for incoming connections
If --connect argument is present, connect to the remote TCP peer
In forked/spawned version:
Acquire connected TCP socket from the parent
From here, all actions must be taken by either forked version or by a daemon
launched from the control process:
Open control interface socket
Split TCP socket and related transcoders into reading and writing parts
Create bridge ZMQ PAIR socket
Put both TCP socket reading ZMQ bridge write PAIR parts into a thread
("bridge")
Create run loop in the main thread for polling three ZMQ sockets:
Connectiond is a lightning peer network connection microservice.
Program operations
Since this daemon must operate external P2P TCP socket, and TCP socket can be either connected to the remote or accept remote connections; and we need a daemon per connection, while the incoming TCP socket can't be transferred between processes using IPC, the only option here is to have two special cases of the daemon.
The first one will open TCP socket in listening mode and wait for incoming connections, forking on each one of them, passing the accepted TCP socket to the child and continuing on listening to the new connections. (In multi-thread mode, differentiated with
--threaded
argument, instead of forking damon will launch a new thread).The second one will be launched by some control process and then commanded (through command API) to connect to a specific remote TCP socket.
These two cases are differentiated by a presence command-line option
--listen
followed by a listening address to bind (IPv4, IPv6, Tor and TCP port number) or--connect
option followed by a remote address in the same format.The overall program logic thus is the following:
In the process starting from
main()
:lnpd
) or by forking itself.--listen
argument is present, start a listening version as described above and open TCP port in listening mode; wait for incoming connections--connect
argument is present, connect to the remote TCP peerIn forked/spawned version:
From here, all actions must be taken by either forked version or by a daemon launched from the control process: