Add a few more methods to Swarm and PollParameters (#721)

This commit is contained in:
Pierre Krieger
2018-12-04 13:54:04 +01:00
committed by GitHub
parent b727cad62a
commit 10d76d64d0
3 changed files with 60 additions and 10 deletions

View File

@ -56,10 +56,11 @@ use libp2p::{
fn main() {
env_logger::init();
// Create a random PeerId
let local_key = secio::SecioKeyPair::ed25519_generated().unwrap();
let local_peer_id = local_key.to_peer_id();
println!("Local peer id: {:?}", local_peer_id);
let local_pub_key = local_key.to_public_key();
println!("Local peer id: {:?}", local_pub_key.clone().into_peer_id());
// Set up a an encrypted DNS-enabled TCP Transport over the Mplex protocol
let transport = libp2p::CommonTransport::new()
@ -75,9 +76,9 @@ fn main() {
// Create a Swarm to manage peers and events
let mut swarm = {
let mut behaviour = libp2p::floodsub::FloodsubBehaviour::new(local_peer_id);
let mut behaviour = libp2p::floodsub::FloodsubBehaviour::new(local_pub_key.clone().into_peer_id());
behaviour.subscribe(floodsub_topic.clone());
libp2p::Swarm::new(transport, behaviour, libp2p::core::topology::MemoryTopology::empty())
libp2p::Swarm::new(transport, behaviour, libp2p::core::topology::MemoryTopology::empty(), local_pub_key)
};
// Listen on all interfaces and whatever port the OS assigns