📖
[Deprecated] Launchpad Curriculum
  • README
  • About Launchpad
  • Launchpad Learning Resources
    • The Protocol Labs Network
      • What is the PL Network?
      • Teams in the PL Network
      • Protocol Labs Culture
      • Where We are Headed
      • Open Source Stewardship
      • Open Source Contribution
    • IPFS
      • IPFS Setup (Tutorial)
      • Mutable Content
      • IPFS Public DHT
      • Who Uses IPFS
      • How IPFS Works
      • Data Transfer
      • IPFS Subsystems & Architecture
      • The IPFS Gateways
      • The IPFS API (Tutorial)
      • IPFS Resources
    • IPLD
      • Content Addressing & CIDs
      • Graphs: Merkle DAGs
      • The IPLD Data Model
      • IPLD & IPFS
      • Codecs
      • IPLD Schemas
      • Paths & Selectors
      • Distributed Data Structures
      • The CAR Format
      • IPLD Resources
    • libp2p
      • Core Concepts
      • libp2p Connections and Users
      • Decentralized Messaging
      • Gossipsub
      • Distributed Networking Solutions
      • Nat Traversal and Hole Punching
      • libp2p Resources
    • Filecoin
      • How Filecoin Works
      • Filecoin Cryptoeconomics
      • The Filecoin Protocol
      • Drand
      • Progress & Future Work
      • Filecoin Resources
  • Other Resources
    • Pre-Requisites
      • Web3 & Protocol Labs
      • Building Web3
      • Web3 Tools
    • Protocol Labs Toolkits & SDKs
      • Textile
      • Ceramic
      • Fleek
      • Web3.Storage
      • Piñata
    • Built On IPFS and Filecoin
    • Additional Learning
Powered by GitBook
On this page
  • Circuit Relays
  • Publish/Subscribe
  • Resources
Edit on GitHub
  1. Launchpad Learning Resources
  2. libp2p

Distributed Networking Solutions

Pubsub and Circuit Relays allow distributed networking

PreviousGossipsubNextNat Traversal and Hole Punching

Last updated 2 years ago

Circuit Relays

In some cases, peers might not be publicly reachable. For example, consider that peer A wants to connect to B, but peer B is behind a firewall that does not allow incoming connections.

To solve this issue, libp2p provides a protocol called . When a peer is not reachable by other peers, another machine can relay messages for that peer. Consider the following diagram:

  1. A is not reachable, so it asks C to listen on its behalf.

  2. B establishes a connection to C in an attempt to communicate with A.

  3. C relays messages from B to A.

Note that A starts the connection to C because A is not publicly accessible.

Multiaddresses

When sending messages over a circuit relay, we must know how to reach the relay machine (i.e., the machine that is acting as a bridge). In the previous example, B has to find out how to reach C.

/ip4/127.0.0.1/tcp/2330/p2p/PEER_ID_OF_C/p2p-circuit/p2p/PEER_ID_OF_A

You can read the previous address like: "Make a connection to 127.0.0.1 at TCP port 2330, which is the address of the peer C. Then, perform a circuit relay to peer A".

Publish/Subscribe

A PubSub (Publish/Subscribe) system allows peers to only receive messages of a specific type. A publisher sends messages of a specific type to subscribers of that type. For example, consider a chat application with a chat group called music. Users interested subscribe to the group; when someone sends a message to the group, only those subscribed receive the message.

In libp2p, peers subscribe and send messages to topics. The concept is pretty similar to messaging systems (e.g., Kafka), but libp2p allows this behavior in a decentralized way. The main implementations of the protocol are Floodsub and Gossipsub.

In Floodsub, the first implementation of the pub/sub protocol, messages are delivered to all the connected nodes of a peer. For example, consider the following diagram.

  1. Peer 1 is connected to Peer 2 and Peer 3; Peer 2 and Peer 3 are connected to Peer 4.

  2. Peer 1 publishes a message, which is sent to Peer 2 and Peer 3.

  3. Both Peer 2 and Peer 3 forward the message to Peer 4.

FloodSub is simple, reliable, and highly resistant to malicious actors and censors, but the main problem of FloodSub is that it duplicates messages, thus using a lot of bandwidth. In the previous example, Peer 4 receives the message twice.

Resources

In the course of creating and researching distributed apps, there were a number of problems encountered that the libp2p project addressed. The following video is a workshop that covers some of the issues found in distributed networking.

identify circuit relays by using the IDs of the peers involved. The following is a sample circuit relay multiaddress.

You can get more information about circuit relays in the and the .

, the protocol developed after FloodSub, tries to reduce the number of duplicate messages (i.e., bandwidth) by taking a different approach. Gossipsub is covered later in the Launchpad curriculum.

You can get more information about PubSub in the .

Multiaddresses
libp2p documentation
Circuit Relay v2 specs
Gossipsub
libp2p documentation
Circuit Relay v2
Circuit relay example
Floodsub message delivery