libp2prs-floodsub

Crates.iolibp2prs-floodsub
lib.rslibp2prs-floodsub
version0.3.0
sourcesrc
created_at2021-01-14 12:37:25.245103
updated_at2021-04-23 08:17:46.567192
descriptionFloodsub protocol for libp2p
homepage
repositoryhttps://github.com/netwarps/libp2p-rs
max_upload_size
id341891
size114,690
(paradeum)

documentation

README

libp2prs-floodsub

the baseline flooding protocol

This is the canonical pubsub implementation for libp2p-rs.

Usage

step1: create floodsub and get handler

    let floodsub = FloodSub::new(FloodsubConfig::new(local_peer_id));
    let handler = floodsub.handler();

step2: register handler to swarm

    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));

step3: get floodsub control and then start with swarm control

    let floodsub_control = floodsub.control();
    floodsub.start(swarm.control());

step4: start swarm

    // listen on
    swarm.listen_on(vec![listen_addr]).unwrap();
    // start swarm
    swarm.start();
    // new connection
    swarm_control.new_connection(remote_peer_id).await.unwrap();

step5: publish/subscribe/ls/getPeers

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"));

TODO list:

  • config item: sign strict
  • filter repetitive message to prevent over flood
  • blacklist
Commit count: 161

cargo fmt