Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ libp2p-gossipsub = { version = "0.48.0", path = "protocols/gossipsub" }
libp2p-identify = { version = "0.46.1", path = "protocols/identify" }
libp2p-identity = { version = "0.2.10" }
libp2p-kad = { version = "0.47.1", path = "protocols/kad" }
libp2p-mdns = { version = "0.46.1", path = "protocols/mdns" }
libp2p-mdns = { version = "0.46.2", path = "protocols/mdns" }
libp2p-memory-connection-limits = { version = "0.3.1", path = "misc/memory-connection-limits" }
libp2p-metrics = { version = "0.15.0", path = "misc/metrics" }
libp2p-mplex = { version = "0.42.0", path = "muxers/mplex" }
Expand Down
5 changes: 5 additions & 0 deletions protocols/mdns/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.46.2

- Emit `ToSwarm::NewExternalAddrOfPeer` on discovery.
See [PR 5753](https://github.com/libp2p/rust-libp2p/pull/5753)

## 0.46.1

- Upgrade `hickory-proto`.
Expand Down
2 changes: 1 addition & 1 deletion protocols/mdns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-mdns"
edition = "2021"
rust-version = { workspace = true }
version = "0.46.1"
version = "0.46.2"
description = "Implementation of the libp2p mDNS discovery method"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
Expand Down
28 changes: 24 additions & 4 deletions protocols/mdns/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ mod timer;

use std::{
cmp,
collections::hash_map::{Entry, HashMap},
collections::{
hash_map::{Entry, HashMap},
VecDeque,
},
convert::Infallible,
fmt,
future::Future,
io,
Expand Down Expand Up @@ -188,6 +192,9 @@ where
listen_addresses: Arc<RwLock<ListenAddresses>>,

local_peer_id: PeerId,

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

impl<P> Behaviour<P>
Expand All @@ -208,6 +215,7 @@ where
closest_expiration: Default::default(),
listen_addresses: Default::default(),
local_peer_id,
pending_events: Default::default(),
})
}

Expand Down Expand Up @@ -304,6 +312,11 @@ where
&mut self,
cx: &mut Context<'_>,
) -> 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(event);
}
Comment thread
hopinheimer marked this conversation as resolved.
Outdated

// Poll ifwatch.
while let Poll::Ready(Some(event)) = Pin::new(&mut self.if_watch).poll_next(cx) {
match event {
Expand Down Expand Up @@ -359,13 +372,20 @@ 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(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_front(ToSwarm::GenerateEvent(event));
Comment thread
hopinheimer marked this conversation as resolved.
Outdated
}
// Emit expired event.
let now = Instant::now();
Expand All @@ -382,7 +402,7 @@ where
});
if !expired.is_empty() {
let event = Event::Expired(expired);
return Poll::Ready(ToSwarm::GenerateEvent(event));
self.pending_events.push_back(ToSwarm::GenerateEvent(event));
}
if let Some(closest_expiration) = closest_expiration {
let mut timer = P::Timer::at(closest_expiration);
Expand Down