This article may incorporate text from a large language model .(September 2025) |
libp2p | |
---|---|
Original author(s) | Protocol Labs |
Developer(s) | The libp2p community |
Initial release | c. 2016 |
Stable release | Various (per implementation) |
Written in | Go, JavaScript, Rust, Python, Java, Nim, C++ |
Operating system | Cross-platform |
Type | Network stack, P2P |
License | MIT License, Apache License 2.0 |
Website | libp2p github |
libp2p is a modular network stack and open-source library that allows developers to build decentralised, peer-to-peer (P2P) applications. It originated as a core component of the InterPlanetary File System (IPFS) and was later extracted into a standalone project to serve a wider range of decentralised systems. [1]
The primary goal of libp2p is to provide a comprehensive set of tools for handling the common but complex networking challenges of P2P systems, such as peer discovery, routing, identity management, and secure communication, independent of the underlying network transport. Its modular architecture allows developers to select, configure, and combine different components to best suit their application's needs.
libp2p is a specification with multiple implementations across various programming languages, making it a versatile choice for a wide array of projects in the Web3 and decentralised technology space. Major projects like Ethereum's consensus layer [2] and Filecoin [3] use libp2p as their foundational networking layer.
libp2p was conceived by Juan Benet and the team at Protocol Labs during the development of IPFS. The team recognised that building a robust P2P network required solving a set of recurring problems that were not specific to file sharing. Instead of creating a monolithic networking layer tightly coupled to IPFS, they designed a modular and extensible framework that could be abstracted away and used by any P2P application.
The project was separated from the main IPFS codebase to encourage independent development and adoption. This decision proved successful, as libp2p has become a fundamental building block for many other decentralised protocols, allowing their developers to focus on application-level logic rather than reinventing the networking wheel. The project is maintained as an open-source initiative with contributions from a global community of developers.
libp2p is built around a set of core concepts that, when combined, provide a complete P2P networking solution.
In a libp2p network, every node, or "peer," is uniquely identified by a PeerID. A PeerID is the cryptographic hash of a peer's public key. This design provides a secure and verifiable identity system. When two peers communicate, they can use the other's public key to encrypt communications and verify signatures, ensuring authenticity and preventing impersonation. [4]
To address the challenge of locating peers across different network protocols and locations, libp2p uses a format called multiaddress (or multiaddr). A multiaddr is a self-describing network address that encapsulates multiple layers of addressing information. This format allows for future-proofing and explicit communication of how to connect to a peer.
For example, a multiaddr might look like:
This describes a peer accessible via an IPv4 address 192.168.1.100, using the TCP protocol on port 8001. Another example, pointing to the same peer via the QUIC protocol, might be:
A peer can have multiple multiaddrs, advertising all the ways it can be reached.
libp2p is transport-agnostic, meaning it can operate over various network transport protocols. It treats each protocol as a pluggable module. Common transports include:
A libp2p node can listen for incoming connections on multiple transports simultaneously, increasing the likelihood of successful connections between peers in different network environments.
To avoid the overhead of opening a new connection for every piece of communication, libp2p relies on stream multiplexing. [5] This allows multiple independent, bi-directional streams to run concurrently over a single underlying transport connection, enabling different application-level protocols to operate without interference.
libp2p achieves this in two ways:
When a peer initiates a new stream to another peer, they need to agree on what protocol they will use on that stream. libp2p uses a mechanism called multistream-select for this. The initiating peer proposes a protocol identifier (e.g., /ipfs/bitswap/1.2.0), and the listening peer either accepts it or rejects it. This allows peers to support multiple protocols and versions simultaneously and ensures that both sides of a conversation understand each other.
Finding other peers in a decentralised network is a fundamental challenge. libp2p provides several mechanisms for peer discovery:
libp2p establishes secure communication channels between peers by default. When two peers connect, they upgrade their connection to a secure channel using protocols like TLS 1.3 or Noise. This ensures all communication is encrypted and authenticated, protecting against eavesdropping and man-in-the-middle attacks.
For applications requiring real-time, many-to-many communication, libp2p includes a publish/subscribe (PubSub) system. The most widely used implementation is GossipSub, a scalable and resilient gossip protocol that propagates messages through the network by having peers gossip with a random subset of their neighbours. This is used extensively for tasks like block and transaction propagation in blockchain networks.
As libp2p is a specification, there are multiple interoperable implementations in different programming languages. This allows developers to choose the language that best fits their project. As of 2025, the most mature implementations are:
Other official implementations include: [6]
{{cite web}}
: CS1 maint: numeric names: authors list (link)