# libp2p

libp2p, (short for “library peer-to-peer”) is a peer-to-peer (P2P) networking framework that enables the development of P2P applications. It consists of a collection of protocols, specifications, and libraries that facilitate P2P communication between network participants or, in other words, peers.

# P2P basics

P2P networks are decentralized, meaning that participants communicate directly with one another on equal footing. More specifically:

  • P2P networks do not require a privileged set of servers that behave differently from their clients, as in the predominant client-server model.
  • No central server or authority controls the network.

P2P networks can take many forms, including file-sharing systems like BitTorrent, blockchain networks like Bitcoin and Ethereum, and decentralized communication standards like Matrix. These systems all have different challenges and tradeoffs, but they share the goal of improving upon the traditional client-server networking model.

# Background of libp2p and IPFS

libp2p was initially developed as the wire protocol for the IPFS project, but has since phased out into a broader networking stack that a wide range of other projects use as a networking layer. It provides a set of specifications that can be adapted to support various protocols, allowing developers to create libp2p applications that can operate in multiple runtimes and networking environments.

Discovering and connecting with other peers is a key challenge in P2P networking. Before libp2p, each P2P application had to develop its own solution, leading to a lack of reusable, well-documented P2P protocols. The IPFS team looked at existing research and networking applications for inspiration, but found few code implementations that were usable and adaptable. Existing implementations had problems like:

  • Minimal documentation.
  • Restrictive licensing.
  • Outdated code.
  • No point of contact.
  • Being closed source, deprecated, or lacked specifications.
  • Unfriendly APIs.
  • Tight coupling with specific use cases.
  • Lack of upgradeability.

As a result, developers often had to reinvent the wheel each time they needed P2P protocols rather than being able to reuse existing solutions.

libp2p was designed to address these limitations.

# Features

The features of libp2p are listed below. For more information on each feature, click the link to navigate to the appropriate page in the official libp2p documentation (opens new window).

# Publish/subscribe

Publish/Subscribe (PubSub) is a messaging model where peers congregate around topics of interest and exchange messages accordingly. In IPFS, libp2p's PubSub system allows peers to easily join and communicate on topics in real time, providing a scalable and fault-tolerant solution for P2P communication.

One of the key challenges in P2P-based PubSub systems is the prompt and efficient delivery of messages to all subscribers, especially in large and dynamic networks. To overcome these challenges, IPFS utilizes libp2p's GossipSub protocol, which operates by "gossiping" with peers about the messages they have received, enabling an efficient message delivery network.

Check out the libp2p documentation (opens new window) to learn more about PubSub in libp2p.

# Additional resources