From 2f19be28138cc4551439fba9f08cfc23f1efcc76 Mon Sep 17 00:00:00 2001 From: manasnagaraj Date: Wed, 18 Dec 2024 19:56:12 -0500 Subject: [PATCH] some fixes --- protocols/mdns/src/behaviour.rs | 39 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index c8da7226caa..2eadef9c088 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -22,6 +22,16 @@ mod iface; mod socket; mod timer; +use futures::{channel::mpsc, Stream, StreamExt}; +use if_watch::IfEvent; +use libp2p_core::{transport::PortUse, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; +use libp2p_swarm::{ + behaviour::FromSwarm, dummy, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, + THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, +}; +use smallvec::SmallVec; +use std::collections::VecDeque; use std::{ cmp, collections::hash_map::{Entry, HashMap}, @@ -34,17 +44,7 @@ use std::{ task::{Context, Poll}, time::Instant, }; -use std::collections::VecDeque; -use futures::{channel::mpsc, Stream, StreamExt}; -use if_watch::IfEvent; -use libp2p_core::{transport::PortUse, Endpoint, Multiaddr}; -use libp2p_identity::PeerId; -use libp2p_swarm::{ - behaviour::FromSwarm, dummy, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, - THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, -}; -use smallvec::SmallVec; - +use std::convert::Infallible; use self::iface::InterfaceState; use crate::{ behaviour::{socket::AsyncSocket, timer::Builder}, @@ -190,7 +190,7 @@ where local_peer_id: PeerId, /// Pending behaviour events to be emitted. - pending_events: VecDeque, + pending_events: VecDeque>, } impl

Behaviour

@@ -310,7 +310,7 @@ where ) -> Poll>> { // Checking for pending events and emit them if let Some(event) = self.pending_events.pop_front() { - return Poll::Ready(ToSwarm::GenerateEvent(event)); + return Poll::Ready(event); } // Poll ifwatch. @@ -368,15 +368,19 @@ where } else { tracing::info!(%peer, address=%addr, "discovered peer on address"); self.discovered_nodes.push((peer, addr.clone(), expiration)); - discovered.push((peer, addr)); + discovered.push((peer, addr.clone())); - self.pending_events.push_back(Event::NewExternalAddr(addr.clone())); + self.pending_events + .push_back(ToSwarm::NewExternalAddrOfPeer { + peer_id: peer, + address: addr, + }); } } if !discovered.is_empty() { let event = Event::Discovered(discovered); - return Poll::Ready(ToSwarm::GenerateEvent(event)); + self.pending_events.push_back(ToSwarm::GenerateEvent(event)); } // Emit expired event. let now = Instant::now(); @@ -411,9 +415,6 @@ pub enum Event { /// Discovered nodes through mDNS. Discovered(Vec<(PeerId, Multiaddr)>), - /// The multiaddress is reachable externally. - NewExternalAddr(Multiaddr), - /// The given combinations of `PeerId` and `Multiaddr` have expired. /// /// Each discovered record has a time-to-live. When this TTL expires and the address hasn't