Core Concepts

The Building Blocks of libp2p

Concepts

This is an annotated version of this libp2p doc

libp2p covers a lot of ground, and may involve unfamiliar terminology and concepts. This section defines some basic vocabulary and links to to the core information about these concepts.

To communicate on the internet, you need to use an agreed upon Transport Protocol (most of the internet uses a TCP/IP combination). With libp2p you can listen, dial, and provide addresses (which specify the transport). libp2p makes it possible to use multiaddresses to communicate with different protocols, in a peer-to-peer fashion.

NAT allows many machines with private addressed on a private network to use a single public address, however, it also comes with a firewall, which can make it difficult for two peers to connect.

NAT Traversal is a strategy for making it possible for two peers behing NATs to connect.

libp2p uses STUN Hole-Punching and the TURN Circuit Relay Protocol to give peers direct access to communicate with one another.

Circuit relay is a transport protocol that routes traffic between two peers over a third-party “relay” peer, when NAT Traversal and hole punching aren't an option, the circuit relay can be used to connect them.

Protocols define an application you are using with libp2p and provide the core funcitonality. The libp2p Protocol uses Protocol Ids to identify them, Handler Functions to accept connections, and Binary Streams as a medium.

There are some key defining features of a libp2p protocol, including a protocol negotiation processes, and libp2p uses other protocols defined here to define itself.

A Peer Identity (often written PeerId) is a unique multihash identifier for each peer with a link to their public key.

Flexible networks need flexible addressing systems. Since libp2p is designed to work across a wide variety of networks, we need a way to work with a lot of different addressing schemes in a consistent way.

libp2p uses a flexible addressing system that can work in many different networks and interact with many different addressing schemes. libp2p uses known as a multiaddress (aka multiaddr), which is a convention for encoding multiple layers of addressing information into a single "future-proof" path structure.

libp2p makes it simple to establish encrypted, authenticated communication channels between two peers, but there are other important security issues to consider when building robust peer-to-peer systems.

Identity and Trust

Every libp2p peer is uniquely identified by their peer id, which is derived from a private cryptographic key. Peer ids and their corresponding keys allow us to authenticate remote peers, but it does not provide a authorization out-of-the-box.

Publish/Subscribe is a system where peers congregate around topics they are interested in. Peers interested in a topic are said to be subscribed to that topic

Peers can send messages to topics. Each message gets delivered to all peers subscribed to the topic:

Stream Multiplexing (stream muxing) is a way of sending multiple streams of data over one communication link. It combines multiple signals into one unified signal so it can be transported 'over the wires', then it is demulitiplexed (demuxed) so it can be output and used by separate applications.

This is done to share the transmission bandwidth available between multiple sources to make transmission more efficient.

Where it Fits In

libp2p's multiplexing happens at the application layer, meaning it's not provided by the operating system's network stack.

Multiplex Implementations

Implementations of the multiplexing module include mplex protocol developer for libp2p, yamux by Hashicorp, quic transport protocol which includes a multiplexer, SPDY by Google, and more.

Other Resources

Use Crate libp2p to understand the modules, macros, structs, enums, traits, and functions used for the libp2p implementations

Rust libp2p Tutorial (Optional)

Find the full tutorial here

This tutorial aims to give newcomers a hands-on overview on how to use the Rust libp2p implementation.

Last updated