libp2p is a modular framework and protocol suite for developing peer-to-peer applications. Originally part of the IPFS project, libp2p has evolved to meet the needs of a growing community of developers and users, and has recently been incorporated into the networking spec for Ethereum 2.0.
Other language implementations are in developmement, but if your favorite language isn’t quite there yet, the libp2p daemon allows you to run “libp2p as a service” in an external process. Check out the supported language bindings to see if there’s already a binding for your language.
- Ensures secure, multiplexed streams between connected peers. Security and multiplexing protocols are modular, and peers can negotiate supported configurations.
- Pluggable transport modules allow support for TCP, WebSockets, QUIC & WebRTC (if supported by the language / runtime). Nodes can support multiple transports for interop / network flexibility.
- Kademlia-like DHT provides peer routing (to lookup network addresses by peer id), content routing (to look up content / service providers by hash key), and a public key lookup service.
- Extensible PubSub protocol allows broadcast messaging to peers that are subscribed to a topic.
- Can automatically traverse (some) consumer NATs using UPnP.
- Local peer discovery using mDNS.
- Circuit relay protocol allows peers behind NAT boundaries to communicate, using a relay node as intermediary.
Some background info that may be helpful:
The Eth 2.0 p2p networking spec details how Eth 2 will use libp2p for both testnet and mainnet configurations.
- Peer identity is based on public keys, so starting a node requires generating a keypair or loading one from disk.
- The core abstraction for communication between peers is the Stream - a
reliable, ordered channel that’s multiplexed over some transport connection.
Streams are cheap to open once the initial connection is made, so it’s okay to
open a new stream for a quick request/reply sequence.
- See The Req/Resp Domain for protocol ids, framing logic, etc used in eth 2.0 request / response protocols.
The Eth 2 testnet and mainnet will use discv5 to advertise peers in each pubsub topic. For local development and testing, you’ll need to use some other peer discovery mechanism.
- mDNS discovery will return all nearby libp2p peers that are using mDNS, so if you use it at a hackathon, don’t be surprised if you discover a bunch of peers that don’t speak your custom protocol and error out when you try to dial them.
If you’re working with go, be sure to check out the examples and docs for IPFS Camp 2019! There’s some great material there, including examples for pubsub and writing custom protocols.
Detailed specs are available in the specs repository for most core libp2p wire protocols and abstractions.
Check out the libp2p discussion forums to ask
questions & find out about new developments in libp2p. Tagging Stack Overflow
libp2p is also a good way to get them seen by people in the
#libp2p IRC channel on freenode can also be a good venue for a