Overview of what is libp2p?

Tram Ho

This is an article in series on an in-depth look at IPFS. And this article will give you the most general knowledge about libp2p.

What is libp2p? its meaning

What is libp2p?

We can summarize the definition with only one sentence. libp2p is a collection of modules on protocols, specifications and libraries that enables the development of peer-to-peer applications.

Peer-to-peer basics

In fact, there will be dozens of knowledge behind a sentence defined above. Get started with p2p applications with the concepts you can read here

A P2P network is a network in which participants (called peers or nodes) communicate directly with each other. This does not mean that all peers must be identical, some may have different roles in the network. One of the defining features of p2p networks is that they do not require a server as in the Client / Server model

Because the definition of a peer-to-peer network is quite broad, there are many different types of systems built. The most prominent examples of file-sharing networks are BitTorrent and, more recently, the popularity of blockchain networks that also communicate in P2P style.

So what does libp2p solve?

Although peer-to-peer networks have many advantages over the client / server model, there are also special challenges and it requires special solutions and a lot of practice time to overcome. In the process of addressing these challenges and building IPFS, the contributors of IPFS have built solutions in a modular way that can be reassembled and made into libp2p . Although libp2p is developed from IPFS, it does not require or depend on IPFS, many projects (including ZuckBucks’ Libra) use libp2p as their network transport layer. In my article I will try to outline briefly the major issues that are addressed by libp2p


In fact, the foundation of libP2P targets the transport layer, responsible for transmitting and receiving data between peers in the p2p network. Libp2p provides a simple interface that can be adjusted to support good and future protocols, allowing libp2p applications to operate in multiple environments regardless of time.


In a world with billions of networked devices, there’s a constant question of how do you know if the person you’re chatting with is the one you know, or is someone else pretending to be? libp2p uses public key cryptography as an identifier in peer-to-peer networks that serves two purposes.

  • First, it gives each peer a unique name as PeerId .
  • The second is to allow everyone in the network to communicate securely with each other. (Person A sends an encrypted message using public key of person B so only person B has his own private key to decode and read that message)


It is important that we can send and receive data between peers securely. This means that we can trust the identities of the peer we are communicating with and not any third party can read or change them.

Libp2p provides an enhanced connection by transmitting data over the encrypted channel . This process is flexible and can support many traditional encryption methods. The default is now secio

Peer Routing

When you want to send a message to another person, you need two main information: their PeerId and their location online to connect.

There are many cases where we only have the peer PeerId we want to contact and we need a way to find their network address. Peer routing is the process of discovering addresses by applying the “knowledge” of other peers.

In a peer routing system a peer can provide us with the peer address we need as long as they have one. Otherwise it will redirect our request to another peer that will most likely have. As we communicate with more and more peers, we not only increase the chance of finding the peer we are looking for, but also update the network more fully, allowing us to answer routing queries of other peers . Also libp2p uses Kademlia routing algorithm

Content Discovery

Unlike the client server model, we just need to query the server and search for the data. On the p2p network, there is no server to search for, so finding a defect will become extremely difficult. That’s why Libp2p provides a content routing interface that can help us find, download and verify the comprehensiveness of the data we need to find.

Messaging / PubSub

Sending messages from one peer to another is always the most important issue for peer-to-peer systems and pub / sub is an extremely important pattern. The pub / sub definition is a system in which peers subscribe to topics they are interested in and peer submit posts to the topic called public.

In a pub / sub peer-to-peer system, it is a little different from a regular pub / sub system.

  • Reliability : All messages must be sent to all peer subscribed topics.
  • Speed (speed): The message must be sent quickly
  • Efficiency (effective): The network will not exist too many duplicate copies of messages
  • Resilience : The peer can join or exit the network without interrupting it.
  • Scale (scalability): Topics that can handle a large number of registered users and handle a large number of messages
  • Simplicity : The system must be simple enough to understand and implement. The peer also needs to save less data

libp2p defines a pubsub interface so that messages can be sent to all peer subscriptions on the same topic. The current interface has 2 implementations.

  • floodsub uses a network flooding strategy that transmits successively to all peers, but this solution does not work.
  • gossipsub is the current protocol being used by libp2p. Just as the gossip name is rumored, peers talk about the messages they see with other peers.

Some photos to summarize

Libp2p is considered the networking layer of IPFS

A collection of p2p protocols

IPFS is made up of libp2p modules


Currently libp2p supports the following languages

There are also several other languages, such as java and python, which will soon be supported


Share the news now

Source : Viblo