diff --git a/protocols/gossipsub/examples/chat.rs b/protocols/gossipsub/examples/chat.rs index a083a80a179..d770cc69c95 100644 --- a/protocols/gossipsub/examples/chat.rs +++ b/protocols/gossipsub/examples/chat.rs @@ -18,8 +18,8 @@ fn main() { // Create a random PeerId let local_key = secio::SecioKeyPair::ed25519_generated().unwrap(); - let local_pub_key = local_key.to_public_key(); - println!("Local peer id: {:?}", local_pub_key.clone().into_peer_id()); + let local_peer_id = local_key.to_peer_id(); + println!("Local peer id: {:?}", local_peer_id); // Set up an encrypted TCP Transport over the Mplex and Yamux protocols let transport = libp2p::build_development_transport(local_key); @@ -44,14 +44,9 @@ fn main() { Duration::from_secs(60), ); // build a gossipsub network behaviour - let mut gossipsub = - gossipsub::Gossipsub::new(local_pub_key.clone().into_peer_id(), gossipsub_config); + let mut gossipsub = gossipsub::Gossipsub::new(local_peer_id.clone(), gossipsub_config); gossipsub.subscribe(topic.clone()); - libp2p::Swarm::new( - transport, - gossipsub, - libp2p::core::topology::MemoryTopology::empty(local_pub_key), - ) + libp2p::Swarm::new(transport, gossipsub, local_peer_id) }; // Listen on all interfaces and whatever port the OS assigns diff --git a/protocols/gossipsub/src/layer.rs b/protocols/gossipsub/src/layer.rs index d9616c394a4..8fa7c47cd36 100644 --- a/protocols/gossipsub/src/layer.rs +++ b/protocols/gossipsub/src/layer.rs @@ -28,7 +28,7 @@ use libp2p_core::swarm::{ }; use libp2p_core::{ protocols_handler::{OneShotHandler, ProtocolsHandler}, - PeerId, + Multiaddr, PeerId, }; use libp2p_floodsub::{Topic, TopicHash}; use mcache::MessageCache; @@ -999,7 +999,7 @@ impl Gossipsub { } } -impl NetworkBehaviour for Gossipsub +impl NetworkBehaviour for Gossipsub where TSubstream: AsyncRead + AsyncWrite, { @@ -1010,6 +1010,10 @@ where Default::default() } + fn addresses_of_peer(&self, _: &PeerId) -> Vec { + Vec::new() + } + fn inject_connected(&mut self, id: PeerId, _: ConnectedPoint) { // We need to send our subscriptions to the newly-connected node. let mut subscriptions = vec![]; @@ -1104,6 +1108,8 @@ where // remove peer from peer_topics let was_in = self.peer_topics.remove(id); debug_assert!(was_in.is_some()); + + //TODO: Reconnect due to inactivity } fn inject_node_event(&mut self, propagation_source: PeerId, event: InnerMessage) { @@ -1155,7 +1161,7 @@ where fn poll( &mut self, - _: &mut PollParameters, + _: &mut PollParameters, ) -> Async< NetworkBehaviourAction< ::InEvent, @@ -1234,7 +1240,6 @@ pub enum NodeType { #[cfg(test)] mod tests { use super::*; - use libp2p_core::topology::MemoryTopology; use libp2p_floodsub::TopicBuilder; // helper functions for testing @@ -1273,7 +1278,8 @@ mod tests { for _ in 0..peer_no { let peer = PeerId::random(); peers.push(peer.clone()); - as NetworkBehaviour>::inject_connected(&mut gs, + as NetworkBehaviour>::inject_connected( + &mut gs, peer.clone(), dummy_connected_point.clone(), );