There is a consensus that libp2p integration is useful. But i wanted to summarize what benefits we can expect, and maybe figure out more of them. Second part is mostly technicalities and, i hope, they will help people to review relevant changes.
One of the main reasons why libp2p became so popular is a support of variety of transports. Application can connect from browser using websockets. Or using recent implementation of the QUIC protocol. Also it can use existing or implement transport that fits a particular use case. It was mentioned by @mandrigin that our transport stack can be better optimized for mobile. For example, android app is receiving messages when application is in background. This way it can’t get into sleep mode, constantly consumes cpu and gets reported by android OS. We will be able to improve it by implementing HTTP transport or by managing open TCP connections carefully.
We have a problem that status network depends on servers running on digital ocean and gce. It can solved by running sufficient number of desktop clients consistently. But it is practically impossible to connect to, not from, a desktop client. Desktop client doesn’t advertise itself. Most of them are running at home network and do not have publicly routable ip address. Meaning that they have to bypass some kind of NAT to establish network connection with outer world. Libp2p has the same problem, as any other p2p solution, and they already made several tools to address it. We will be able to re-use those tools and infrastructure to bypass NAT, in some cases, and create a network that won’t depend on our cluster.
We still need people to run clients. But it will be a good start if at least 30 people are running discoverable and consistently available desktop clients.
Another nice thing, it will be possible to connect with the whisper network from a browser. It will require re-implementing whisper and status protocol in javascript. So i won’t expect it to happen soon. But at least it will be possible.
initial integration
The first step is to make whisper run with arbitrary stream. Current solution assumes that rlpx stream will be passed by devp2p server. It already accepts abstracts type for reading and writing messages. We need to add an abstract type for peer identity, instead of using p2p.Peer. Libp2p stream will be wrapped by rlp stream. No other changes are necessary in whisper itself.
In current implementation we are using heartbeats between nodes in the network. Heartbeats are implemented in the devp2p server. They are used to ensure that connection won’t get closed if whisper will go idle and to detect flaky peers. We detect flaky peers to let client know that message from mobile device at least reached any peer in the network. It is not a proper solution. But we decided to go with it to provide some feedback to a client. The plan is to add similar heartbeats either as a separate libp2p stream or add keapalive message type to whisper itself.
In status-go we use peer pool that manages discovery to find target number of peers. Peer pool triggers search in multiple discoveries and adds found peers to a server, controlling target number of those peers. Server provides API for adding and removing peers. Dials peers in the background. And allows to get notification when peer was connected/disconnected. We can do exactly same thing but using APIs provided by libp2p. It will require creating common interface for libp2p and devp2p servers.
Servers that will participate in libp2p network will have to advertise all protocols and addresses they are listening on. We will do it using ENR with a special field for multiaddress. If multiaddress is set, record will be added to libp2p server, if not - to devp2p. We could use same topic for discovery, e.g. whisper
for all our relay nodes. But it can be tweaked during development.
Libp2p and devp2p would be physically separate networks. It means that clients running libp2p won’t be able to receive messages from clients running devp2p. The workaround for this problem is to have whisper nodes in the network that run both libp2p and devp2p servers.
what’s next
I plan to wrap up initial integration in a week or two. After that it will be possible to experiment with different transports and start work on exposing desktop clients.
Thanks for reading, if you have questions or concerns please let me know.