Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chain-gossip

P2P GossipSub Network with Kademlia DHT

A distributed p2p network with gossipsub and kademlia DHT implemented using rust-libp2p.

Description

Implements a gossipsub network with kademlia DHT, and mDNS for peer discovery. The network can have n number of nodes running locally in different terminals. Each node can propagate messages to all other nodes in the network, and is subscribed to a topic ("transaction"). This network implementation is to demonstrate the use of gossipsub and kademlia DHT in a p2p network to propagating transactions data across the network.

Usage

  • Clone the repository
git clone https://github.com/SAMAD101/chain-gossip.git
  • Change directory to the project root
cd chain-gossip
  • Run in multiple terminals to simulate a network of nodes
cargo run

New peers are automatically discovered and connected to the network using mDNS. Terminate a node by pressing Ctrl+c in the terminal.

Troubleshooting: Publish error: InsufficientPeers

This means the node has no connected peers. If you never see mDNS discovered a new peer: ..., mDNS discovery is being blocked. This is common on macOS, where the firewall or Local Network privacy blocks mDNS multicast traffic (UDP 5353).

Connect nodes manually (works everywhere)

Start the first node and copy its local address:

cargo run
# Local node is listening on /ip4/127.0.0.1/udp/65360/quic-v1

Pass that address to every other node:

cargo run -- /ip4/127.0.0.1/udp/65360/quic-v1

Demo video

chain-gossip.webm

Conclusion

This simple project explores the applicatgion of libp2p in building decentralized networks which can be used in context of blockchain networks.