What is libp2p all about?
libp2p is a toolkit for developing peer-to-peer network applications in a growing variety of languages.
What’s the status of X libp2p feature for my favorite language?
The implementations section of libp2p.io has an overview of the functionality supported by each language implementation. However, some new implementations (e.g. python) are not yet tracked on that page.
For the most up-to-date picture, it’s best to visit the main repo of the implementation:
How do libp2p peers communicate?
When peers interact with each other, each side gets a bidirectional stream that they can read from and write to. From the perspective of a libp2p application, this is a fairly simple pipe that can be used with the language’s native IO facilities. For example, the go implementation extends the standard go
Under the hood, libp2p’s switch (the “dialer machine” that manages connection state) will establish a transport connection (e.g. a TCP stream), negotiate an an encryption mechanism and stream multiplexer with the remote peer, and open a new multiplexed stream for the application to use. If there’s already an open connection the the remote peer, the switch will just open a new multiplexed stream over the existing connection.
The semantics of what gets sent over the libp2p stream is determined by the application protocols in use. Each libp2p stream is “tagged” with a protocol id, which is a unique string containing a name and version, e.g.
/ipfs/id/1.0.0. When new streams are opened, the peers engage in a protocol negotiation process using multistream-select to agree on a supported protocol. Once agreement is reached, the protocol determines what gets sent over the wire.
How do I develop my own application protocols?
libp2p makes very few assumptions about the structure of the data your application wants to send over the wire. As such, there’s no “canonical” or recommended serialization or RPC format.
The protocols used internally by libp2p (e.g. the identify protocol) send messages encoded as protobufs over the wire using a simple length-prefixed encoding, where the size of the message is sent, followed by the serialized protobuf. For details, see go-msgio, which implements the length-prefixed reading and writing in go.
How do peers discover each other?
Local peers can find each other using multicast DNS, if enabled and supported by their libp2p implementation.
libp2p also provides a Kademlia-inspired distributed hash table, which allows peers to discover each other in a distributed fashion.
Can I run libp2p apps in the browser?
Yes! js-libp2p supports browser runtimes, although you are limited to transports supported by browsers, e.g. websockets and WebRTC. Indirect support for other transports can be provided by using a circuit relay peer to act as a “bridge” between the browser and peers using other transports (e.g. TCP).