Introduction to libp2p | Lesson 1 of 6

Why do we need libp2p?

libp2p logo

libp2p is a modular network stack that evolved out of IPFS to become an independent project.

In order to explain why libp2p is such an important piece of the decentralized web, we need to take a few steps back and understand where it came from. libp2p's initial implementation began inside of IPFS, a peer-to-peer file sharing system. Let's start by exploring the networking problems that IPFS was built to tackle.

Web 2.0

We've grown to love the internet and use it in many aspects of our everyday lives, for studying, connecting with friends and family, shopping, managing our finances, and much more.

We've become dependent on the internet to a point where we really need it to be reliable and safe, but that's not really the case in this day and age. We've all experienced connectivity issues, and we also feel that our identity and data are not safe across the multiple online services that we use daily.

For example, if you want to send a photo to a friend that lives in the same street, the number of service providers the photo passes through is too high: your phone will capture the image and send it through the network until it reaches the application servers (possibly overseas); the server will then store the photo in a database, analyze it for facial recognition to suggest tagging friends in the picture, and send a notification to your friend's device; and finally your friend will check the notification and load the photo from the overseas database.

There are so many things that can go wrong in this scenario, and the truth is, you probably didn't want the photo to be stored in some far away database which you can't delete. You just wanted to share your photo directly with your friend.

Location Addressing vs Content Addressing

A lot of the issues that we face come from using a location addressing approach to find the content the user is looking for, and serving it from that address. For example, we expect our libp2p logo to be available at https://proto.school/tutorial-assets/T0009L01-libp2p-logo.svg, but what if the server of this website is down? What if the DNS server is down? What if the image was converted to a PNG file and so the new location is T0009L01-libp2p-logo.png? What if you are in a country that has blocked the proto.school domain? All of these issues are common ones and are caused by location addressing, where we try to find the content we need by its location.

IPFS, however, approaches this problem in a different way by using content addressing instead. If we know the CID (Content IDentifier) of our libp2p logo instead of its location, we can simply ask the network who has the image with this CID. The advantages in this approach are very appealing since they solve all the other issues previously mentioned, but to get it right there are other problems that need to be tackled first, specifically within networking.

Networks are complex

To have a web powered by Content Addressing, we need to redesign and re-imagine how computer networks work. Networks are very complex systems that have their own rules and restrictions, and so when designing these systems, we need to take into account a lot of situations and use cases:

  • Firewalls: You might have a firewall installed in your laptop that blocks or restricts specific connections.
  • NAT: Your home WiFi router with NAT (Network Address Translation), which translates your local IP address of your laptop to a single IP address that networks outside your home can connect to.
  • High latency networks: These networks have very slow connections and leave users waiting a long time to see their content.
  • Reliability: There are many networks scattered around the world, and more often than not, a lot of users encounter slow networks that don't have robust systems in place to offer good connectivity to users. Connections drop frequently and users are left with a subpar network system that doesn't serve the users as it should.
  • Roaming: Mobile addressing is another situation where we need to guarantee that the users' devices remain uniquely discoverable when navigating through different networks across the world. Currently they work in a distributed system that requires a lot of coordination points and connections, but the best solution would be a decentralized one.
  • Censorship: In the current state of the web, blocking a website at a specific website domain is relatively easy to do if you are a governmental entity. This is useful to block illegal activity, but becomes a problem when, for example, an authoritarian regime wants to remove access to resources from its population.
  • Runtimes with different properties: There are numerous types of runtimes around, such as IoT (Internet of Things) devices (Raspberry Pi, Arduino, etc) which are gaining a lot of adoption. Because they're built with limited resources, their runtimes often use different protocols that make a lot of assumptions about their runtime.
  • Innovation is very slow: Even the most successful companies with a lot of resources can take decades to develop and deploy new protocols.
  • Data Privacy: Consumers have become increasingly concerned lately about the growing number of companies that do not respect users' privacy.

Ouch, this is a long list! But these are the issues that IPFS had to solve in order to create successful P2P (Peer-to-Peer) communications.

The truth is, as we will see in the next lesson, IPFS is not the first project to try and solve these issues and create a P2P network.

Take the quiz!

What is the relationship between libp2p and IPFS?

Oops, you haven't selected the right answer yet!