From 8d8094c2acf39c7d25b2f9e662e07b5e067cdd50 Mon Sep 17 00:00:00 2001 From: sergerad Date: Sat, 23 Nov 2024 07:07:20 +1300 Subject: [PATCH] RM unused network fn --- p2p/src/lib.rs | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs index f59b847..2ef6ef2 100644 --- a/p2p/src/lib.rs +++ b/p2p/src/lib.rs @@ -21,6 +21,7 @@ pub struct Network { } impl Network { + /// Creates a new [Network] with Gossipsub and Mdns. pub fn new() -> Result> { let mut swarm = libp2p::SwarmBuilder::with_new_identity() .with_tokio() @@ -73,6 +74,7 @@ impl Network { Ok(Self { swarm }) } + /// Starts the network event loop as an async task. pub fn start(mut outbound: Receiver<(Vec, String)>) -> Receiver { let (tx, rx) = tokio::sync::mpsc::channel(32); let mut network = Network::new().unwrap(); @@ -116,39 +118,4 @@ impl Network { }); rx } - - pub async fn poll(&mut self) -> Result, Box> { - select! { - event = self.swarm.select_next_some() => match event { - SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(mdns::Event::Discovered(list))) => { - for (peer_id, _multiaddr) in list { - println!("mDNS discovered a new peer: {peer_id}"); - self.swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id); - } - Ok(None) - }, - SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(mdns::Event::Expired(list))) => { - for (peer_id, _multiaddr) in list { - println!("mDNS discover peer has expired: {peer_id}"); - self.swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id); - } - Ok(None) - }, - SwarmEvent::Behaviour(MyBehaviourEvent::Gossipsub(gossipsub::Event::Message { - propagation_source: _peer_id, - message_id: _id, - message, - })) => { - Ok(Some(message)) - }, - SwarmEvent::NewListenAddr { address, .. } => { - println!("Local node is listening on {address}"); - Ok(None) - } - _ => { - Ok(None) - } - } - } - } }