Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hopinheimer committed Dec 19, 2024
1 parent 35c9814 commit 2f19be2
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions protocols/mdns/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -190,7 +190,7 @@ where
local_peer_id: PeerId,

/// Pending behaviour events to be emitted.
pending_events: VecDeque<Event>,
pending_events: VecDeque<ToSwarm<Event, Infallible>>,
}

impl<P> Behaviour<P>
Expand Down Expand Up @@ -310,7 +310,7 @@ where
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
// 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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f19be2

Please sign in to comment.