Difference between revisions of "LibP2P"
(→Modules: Add links to modules.) |
m (→Modules: Add kad and discv5 to peer discovery.) |
||
Line 46: | Line 46: | ||
* [https://github.com/libp2p/js-libp2p-mdns @libp2p/mdns] | * [https://github.com/libp2p/js-libp2p-mdns @libp2p/mdns] | ||
* [https://github.com/libp2p/js-libp2p-webrtc-star @libp2p/webrtc-star] | * [https://github.com/libp2p/js-libp2p-webrtc-star @libp2p/webrtc-star] | ||
+ | * [https://github.com/ChainSafe/discv5 @chainsafe/discv5] | ||
+ | * [https://github.com/libp2p/js-libp2p-kad-dht @libp2p/kad-dht] | ||
PubSub | PubSub |
Revision as of 23:30, 15 September 2022
Contents
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.
- Specification: Private Networks PSK V1
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.
- Documentation: https://docs.testground.ai/
- Repository: https://github.com/testground/testground
js-libp2p
Modules
Encryption
Multiplexers
Transports
Peer Discovery
- @libp2p/bootstrap
- @libp2p/pubsub-peer-discovery
- @libp2p/mdns
- @libp2p/webrtc-star
- @chainsafe/discv5
- @libp2p/kad-dht
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.