diff --git a/Cargo.lock b/Cargo.lock index fff233de361..d4350c0496b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2928,7 +2928,7 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.46.1" +version = "0.46.2" dependencies = [ "arrayvec", "async-std", diff --git a/Cargo.toml b/Cargo.toml index 63b3befc8b2..bd6018b024f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,7 +86,7 @@ libp2p-floodsub = { version = "0.45.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.47.0", path = "protocols/gossipsub" } libp2p-identify = { version = "0.45.0", path = "protocols/identify" } libp2p-identity = { version = "0.2.9" } -libp2p-kad = { version = "0.46.1", path = "protocols/kad" } +libp2p-kad = { version = "0.46.2", path = "protocols/kad" } libp2p-mdns = { version = "0.46.0", path = "protocols/mdns" } libp2p-memory-connection-limits = { version = "0.3.0", path = "misc/memory-connection-limits" } libp2p-metrics = { version = "0.15.0", path = "misc/metrics" } diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index a41d6b9a131..f4e25e0de05 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.46.2 + +- Emit `ToSwarm::NewExternalAddrOfPeer`. + See [PR 5549](https://github.com/libp2p/rust-libp2p/pull/5549) + ## 0.46.1 - Use new provider record update strategy to prevent Sybil attack. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index a00959fced6..11a670933db 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-kad" edition = "2021" rust-version = { workspace = true } description = "Kademlia protocol for libp2p" -version = "0.46.1" +version = "0.46.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index fc3d8a1adaa..a541648707a 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -2562,13 +2562,19 @@ where // Drain applied pending entries from the routing table. if let Some(entry) = self.kbuckets.take_applied_pending() { let kbucket::Node { key, value } = entry.inserted; + let peer_id = key.into_preimage(); + self.queued_events + .push_back(ToSwarm::NewExternalAddrOfPeer { + peer_id, + address: value.first().clone(), + }); let event = Event::RoutingUpdated { bucket_range: self .kbuckets .bucket(&key) .map(|b| b.range()) .expect("Self to never be applied from pending."), - peer: key.into_preimage(), + peer: peer_id, is_new_peer: true, addresses: value, old_peer: entry.evicted.map(|n| n.key.into_preimage()), diff --git a/protocols/kad/tests/client_mode.rs b/protocols/kad/tests/client_mode.rs index 6aceeb27263..2c8d11beac7 100644 --- a/protocols/kad/tests/client_mode.rs +++ b/protocols/kad/tests/client_mode.rs @@ -23,14 +23,21 @@ async fn server_gets_added_to_routing_table_by_client() { let server_peer_id = *server.local_peer_id(); async_std::task::spawn(server.loop_on_next()); - let peer = client + let external_event_peer = client + .wait(|e| match e { + SwarmEvent::NewExternalAddrOfPeer { peer_id, .. } => Some(peer_id), + _ => None, + }) + .await; + let routing_updated_peer = client .wait(|e| match e { SwarmEvent::Behaviour(Kad(RoutingUpdated { peer, .. })) => Some(peer), _ => None, }) .await; - assert_eq!(peer, server_peer_id); + assert_eq!(external_event_peer, server_peer_id); + assert_eq!(routing_updated_peer, server_peer_id); } #[async_std::test] @@ -126,6 +133,12 @@ async fn set_client_to_server_mode() { let server_peer_id = *server.local_peer_id(); + let peer_id = client + .wait(|e| match e { + SwarmEvent::NewExternalAddrOfPeer { peer_id, .. } => Some(peer_id), + _ => None, + }) + .await; let client_event = client.wait(|e| match e { SwarmEvent::Behaviour(Kad(RoutingUpdated { peer, .. })) => Some(peer), _ => None, @@ -138,6 +151,7 @@ async fn set_client_to_server_mode() { let (peer, info) = futures::future::join(client_event, server_event).await; assert_eq!(peer, server_peer_id); + assert_eq!(peer_id, server_peer_id); assert!(info .protocols .iter()