Skip to content

Commit

Permalink
RM unused network fn
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Nov 22, 2024
1 parent 65a198b commit 8d8094c
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Network {
}

impl Network {
/// Creates a new [Network] with Gossipsub and Mdns.
pub fn new() -> Result<Self, Box<dyn Error>> {
let mut swarm = libp2p::SwarmBuilder::with_new_identity()
.with_tokio()
Expand Down Expand Up @@ -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<u8>, String)>) -> Receiver<GossipMessage> {
let (tx, rx) = tokio::sync::mpsc::channel(32);
let mut network = Network::new().unwrap();
Expand Down Expand Up @@ -116,39 +118,4 @@ impl Network {
});
rx
}

pub async fn poll(&mut self) -> Result<Option<GossipMessage>, Box<dyn Error>> {
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)
}
}
}
}
}

0 comments on commit 8d8094c

Please sign in to comment.