LibP2P

From Organic Design wiki
Revision as of 05:53, 16 September 2022 by Saul (talk | contribs) (Modules: Add note on yumux.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Cone.png This article or section is a stub. Stubs are articles that have not yet received substantial attention from the authors. They are short or insufficient pieces of information and require additions to further increase the article's usefulness. The project values stubs as useful first steps toward complete articles.


Private Networks

LibP2P has the concept of private networks that are created by a pre-shared secret key (PSK) which encrypts all traffic leaving the nodes. (This is underneath the standard LibP2P stack so traffic is encrypted twice.) This PSK is also called a swarm key and is also used by IPFS. The swarm key can have the following text format:

/key/swarm/psk/1.0.0/
/base16/
0ff05394c733304ec26b3861ef23a4ffef9cd2e7d2040e028e5e9bb321d2eea3

The first line is the codec of the key, the second line is the format of the key and the last line is the key itself.

PubSub

LibP2P currently has two implementations of PubSub, a naive FloodSub and a GossipSub. FloodSub just floods the network without doing anymore work to reduce waste where GossipSub as the name suggest uses gossip.

Peer Discovery

LibP2P's PubSub has a special topic for peer discovery this works by each peer publishing their own addresses every so often.

Testground

Libp2p has created Testground for testing their protocols. Testground can be scaled from 2 to 10000 nodes.

js-libp2p

Modules

Encryption

Multiplexers

Transports

Peer Discovery

PubSub

DHT

Connection Protector

Connection Timeout

The js libp2p has a connection timeout where it will drop a connection if it doesn't get used in a certain timeframe (< 60s). One way to get around this is to enable PubSub peer discovery and set the interval to a shorter time. It seems there is another way to prevent the connections dropping by tagging that peer:

import { KEEP_ALIVE } from '@libp2p/interface-peer-store/tags'

await peerStore.tagPeer(peerId, KEEP_ALIVE)

PubSub

Peer Discovery

PubSub peer discovery will broadcast the announce addresses to the topic _peer-discovery._p2p._pubsub every interval ms.