Crates.io | libp2prs-floodsub |
lib.rs | libp2prs-floodsub |
version | 0.3.0 |
source | src |
created_at | 2021-01-14 12:37:25.245103 |
updated_at | 2021-04-23 08:17:46.567192 |
description | Floodsub protocol for libp2p |
homepage | |
repository | https://github.com/netwarps/libp2p-rs |
max_upload_size | |
id | 341891 |
size | 114,690 |
the baseline flooding protocol
This is the canonical pubsub implementation for libp2p-rs.
let floodsub = FloodSub::new(FloodsubConfig::new(local_peer_id));
let handler = floodsub.handler();
let swarm = Swarm::new(keys.public())
.with_transport(Box::new(tu))
.with_protocol(Box::new(handler))
.with_ping(PingConfig::new().with_unsolicited(true).with_interval(Duration::from_secs(1)))
.with_identify(IdentifyConfig::new(false));
let floodsub_control = floodsub.control();
floodsub.start(swarm.control());
// listen on
swarm.listen_on(vec![listen_addr]).unwrap();
// start swarm
swarm.start();
// new connection
swarm_control.new_connection(remote_peer_id).await.unwrap();
subscribe
task::spawn(async move {
let sub = control.subscribe(b"test").await;
if let Some(mut sub) = sub {
loop {
if let Some(msg) = sub.ch.next().await { log::info!("recived: {:?}", msg.data) }
}
}
});
publish
floodsub_control.publish(Topic::new(b"test"), msg).await;
ls
floodsub_control.ls().await;
getPeers
floodsub_control.get_peers(Topic::new(b"test"));