Libp2p

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
libp2p
Original authorProtocol Labs
DeveloperThe libp2p community
Initial releasec. 2016
Stable release
Various (per implementation)
Repository
  • {{URL|example.com|optional display text}}Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
Written inGo, JavaScript, Rust, Python, Java, Nim, C++
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemCross-platform
    TypeNetwork stack, P2P
    LicenseMIT License, Apache License 2.0
    Websitelibp2p.io
    github.com/libp2p

    libp2p is a modular network stack and open-source library that enables developers to build decentralised, peer-to-peer (P2P) applications. It originated part of the InterPlanetary File System (IPFS) and was later spun off into a standalone project.[1] The software was developed to provide a set of tools for handling the networking challenges of P2P systems. This includes peer discovery, routing, identity management, and secure communication. There are multiple implementations of libp2p across multiple programming languages.[2] Major projects like Ethereum's consensus layer[3] and Filecoin[4] use libp2p as their foundational networking layer.

    History

    [edit | edit source]

    libp2p was developed by Juan Benet and the team at Protocol Labs during the development of IPFS.[5] 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.

    Core Concepts

    [edit | edit source]

    libp2p is built around a set of core concepts that, when combined, provide a complete P2P networking solution.

    Peer Identity (PeerID)

    [edit | edit source]

    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.[6]

    Multiaddress (multiaddr)

    [edit | edit source]

    Locating peers across different network protocols and locations is addressed using multiaddress (or multiaddr).[7] This is a self-describing network address that allows for multiple layers of addressing information.[8] A host can have multiple multiaddrs, advertising all the ways it can be reached.[9]

    For example, a multiaddr might look like:

    /ip4/192.168.1.100/tcp/8001

    This describes a peer accessible via an IPv4 address 192.168.1.100, using the TCP protocol on port 8001.

    Transports

    [edit | edit source]

    libp2p is transport-agnostic, meaning it can operate over various network transport protocols.[9] Common transports include:

    A machine running libp2p can listen for incoming connections on multiple transports simultaneously which increases the likelihood of successful connections between peers across different network environments.[15]

    Stream Multiplexing

    [edit | edit source]

    To reduce the overhead of opening each new connection libp2p relies on stream multiplexing.[16] 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.[17]

    libp2p achieves this in two ways:

    • For transports like TCP that do not natively support streams, libp2p layers a dedicated multiplexer protocol (such as mplex or yamux) on top of the connection.[18]
    • For modern transports like QUIC and WebRTC, libp2p leverages the protocol's built-in, native multiplexing capabilities directly, without needing an additional layer.

    Protocol Negotiation (multistream-select)

    [edit | edit source]

    When a peer initiates a new stream to another peer, libp2p uses a mechanism called multistream-select. The 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.[15]

    Peer Discovery

    [edit | edit source]

    Finding other peers in a decentralised network is a fundamental challenge. libp2p provides several mechanisms for peer discovery:

    • Bootstrap Lists: A list of known, peer addresses used by new nodes to join the network.[19]
    • mDNS: Used for discovering peers on a local area network (LAN).[20]
    • Distributed Hash Table (DHT): For discovering peers on the wider internet, libp2p networks often employs a Kademlia-based DHT. A peer can query the DHT to find the addresses of other peers.[21]

    Secure Communication

    [edit | edit source]

    When two peers connect, they upgrade their connection to a secure channel using protocols like TLS 1.3[22] or Noise.[15] This protects against eavesdropping and man-in-the-middle attacks.[23]

    Publish/Subscribe

    [edit | edit source]

    The most widely used implementation of a publish/subscribe (PubSub) system is GossipSub.[24] This is a scalable and resilient gossip protocol that propagates messages through the network by having peers gossip with a random subset of their neighbours.[25] This is used extensively for tasks like block and transaction propagation in blockchain networks.[26]

    Implementations

    [edit | edit source]

    As libp2p is a specification with multiple implementations in different programming languages. As of 2025, the most mature implementations are:

    Other official implementations include:[27]

    References

    [edit | edit source]
    1. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    6. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    8. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    9. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    10. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    11. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    12. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    13. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    14. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    15. ^ a b c Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    16. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    17. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    18. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    19. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    20. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    21. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    22. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    23. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    24. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    25. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    26. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    27. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).

    Sources

    [edit | edit source]
    • Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).