libp2p is the networking stack of IPFS, but extracted away from IPFS, becoming a first class project and a dependency of IPFS itself.
This way, libp2p is able to grow further without being attached specifically to IPFS, gaining its own ecosystem and community. IPFS simply becomes one of the many users of libp2p.
This way each project can solely focus on their own objectives:
Finding, connecting and authenticating any process in the network is a bold claim to make. So how has libp2p done it? The answer is modularity.
libp2p has identified specific pieces that can makeup a network stack:
For the purpose of this tutorial, you don't need to understand what all of these pieces are, but it's important to understand how many components there are to consider when building a network stack. If you want to learn more about these individual components, you can check out the Concepts page in libp2p's documentation.
A user can choose the specific pieces they need and compose their own configuration, tailored for their use cases. All of those pieces have very well defined interfaces that enable interoperability and easy upgrades, creating a future-proof networking stack.
By providing consistent interfaces, libp2p enables the creation of an ecosystem of interoperable modules. Think of the interfaces as the studs on the top of your LEGO bricks and connection points underneath them... LEGO can create an endless variety of new pieces that will fit together perfectly, so long as they all use the same method to stick together.
Let's compare it to furniture shopping. Sure, you can spend long weeks searching for the perfect couch you like that will fit your living room perfectly, but in the end, it's still not exactly as you wanted it to be. What if instead, you could go to an online store that allowed you to order your own couch, set up with exactly the colors you materials you wanted. This couch company has identified the basic building blocks that make up a couch (1-seater, 2-seater or 3-seater? With or without chaise lounge? Velvet, fiber or leather?), and has provided a web service that allows customers to customize the couch they want. No matter what pieces you choose, they're designed to fit together perfectly. And if you change your mind a month later, you can swap out the fabric or add an extra seat, no problem. This is the modularity that libp2p provides. It has formalized networking's building blocks into interfaces (Transport, Discovery, etc) so that they can be implemented in different ways (TCP, UDP, etc).
For example, let's look at the Transport interface. Transports are a collection of foundational protocols that define how data is transferred. Even within this one module, there are many decisions to make, such as how many bytes are sent with each chunk of data, whether they should be verified for integrity individually or all at once, etc.
We can see seven modules that implement the transport interface.
So if we want to switch the transport protocol from TCP
to WebSockets
we can do that easily by simply switching from js-libp2p-tcp
to js-libp2p-websockets
.
If we're missing a module that needs to be implemented, we can create the module and its interface ourselves and use the test suite provided with the interface to validate its implementation. Accordingly, you could plug in our own libp2p-mail
transport like any other available libp2p transport.
Feeling stuck? We'd love to hear what's confusing so we can improve this lesson. Please share your questions and feedback.