LNP-WG / lnp-node

Lightning network protocol daemon (suitable for generalized Lightning Network)
MIT License
145 stars 40 forks source link

Connection service (connectiond) #20

Closed dr-orlovsky closed 4 years ago

dr-orlovsky commented 4 years ago

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():

In forked/spawned version:

From here, all actions must be taken by either forked version or by a daemon launched from the control process:

tg_image_2563057733