Expand description
Episub: Proximity Aware Epidemic PubSub for libp2p
This behaviour implements a large-scale gossiping protocol that is based on three main ideas introduced by the following papers:
- Epidemic Broadcast Trees, 2007 (DOI: 10.1109/SRDS.2007.27)
- HyParView: a membership protocol for reliable gossip-based broadcast, 2007 (DOI: 10.1109/DSN.2007.56)
- GoCast: Gossip-enhanced Overlay Multicast for Fast and Dependable Group Communication, 2005
Those ideas were first compiled into one protocol originally by @vyzo in https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/episub.md
This implementation introduces a number of small changes to the original proposal that surfaced during implementation and testing of this code.
§Usage Examples
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)) => {}
}
}Structs§
- Config
- Configuration paramaters for Episub
- Episub
- Network behaviour that handles the Episub protocol.
- Peer
Authorizer
Enums§
- Episub
Event - Event that can be emitted by the episub behaviour.
- Episub
Handler Error - Format
Error - Errors associated with converting values from wire format to internal represenation
- Publish
Error - Error associated with publishing a gossipsub message.
- RpcError
- Errors associated with RPC calls between active nodes