Crates.io | libp2p-episub |
lib.rs | libp2p-episub |
version | 0.1.13 |
source | src |
created_at | 2021-12-19 00:56:03.201426 |
updated_at | 2022-02-17 14:51:16.001687 |
description | Episub: Proximity Aware Epidemic PubSub for libp2p |
homepage | https://solcial.io/ |
repository | https://github.com/solcial/libp2p-episub |
max_upload_size | |
id | 500193 |
size | 89,736 |
This Rust library implements a libp2p
behaviour for efficient large-scale pub/sub protocol based on ideas the following academic papers:
Originally speced by @vyzo as a successor of Gossipsub.
$ docker-compose up --scale node_n=200 --remove-orphans
First start the audit node and open it in the browser on port 80, you should see a P2P Protocols Lab
empty page.
$ docker-compose up -d node_audit
Then start the bootstrap node
$ docker-compose up -d node_0
You should see it immediately showing up in the labs page, then start 50 peer nodes and watch the network discover itself.
$ docker-compose up --scale node_n=50
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
let transport = libp2p::development_transport(local_key.clone()).await?;
// Create a Swarm to manage peers and events
let mut swarm = libp2p::Swarm::new(transport, Episub::new(), local_peer_id);
// Listen on all interfaces and whatever port the OS assigns
swarm
.listen_on("/ip4/0.0.0.0/tcp/4001".parse().unwrap())
.unwrap();
// subscribe to the topic specified on the command line
swarm.behaviour_mut().subscribe(opts.topic);
swarm.dial(bootstrap).unwrap()
while let Some(event) = swarm.next().await {
match event {
SwarmEvent::Behaviour(EpisubEvent::Message(m, t)) => {
println!("got a message: {:?} on topic {}", m, t);
}
SwarmEvent::Behaviour(EpisubEvent::Subscribed(t)) => {}
SwarmEvent::Behaviour(EpisubEvent::Unsubscribed(t)) => {}
SwarmEvent::Behaviour(EpisubEvent::ActivePeerAdded(p)) => {}
SwarmEvent::Behaviour(EpisubEvent::ActivePeerRemoved(p)) => {}
}
}