diff --git a/Cargo.lock b/Cargo.lock index 4cb44a7241d7..03d69000a611 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2629,7 +2629,7 @@ dependencies = [ [[package]] name = "libp2p-autonat" -version = "0.12.0" +version = "0.12.1" dependencies = [ "async-std", "async-trait", @@ -2808,7 +2808,7 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.44.1" +version = "0.45.0" dependencies = [ "async-std", "asynchronous-codec", @@ -3198,7 +3198,7 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.26.1" +version = "0.27.0" dependencies = [ "anyhow", "async-std", @@ -3247,7 +3247,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.44.1" +version = "0.44.2" dependencies = [ "async-std", "either", diff --git a/Cargo.toml b/Cargo.toml index 44fd5c03ea88..3ac4fd48d280 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,14 +74,14 @@ asynchronous-codec = { version = "0.7.0" } futures-bounded = { version = "0.2.3", path = "misc/futures-bounded" } libp2p = { version = "0.53.2", path = "libp2p" } libp2p-allow-block-list = { version = "0.3.0", path = "misc/allow-block-list" } -libp2p-autonat = { version = "0.12.0", path = "protocols/autonat" } +libp2p-autonat = { version = "0.12.1", path = "protocols/autonat" } libp2p-connection-limits = { version = "0.3.1", path = "misc/connection-limits" } libp2p-core = { version = "0.41.2", path = "core" } libp2p-dcutr = { version = "0.11.0", path = "protocols/dcutr" } libp2p-dns = { version = "0.41.1", path = "transports/dns" } libp2p-floodsub = { version = "0.44.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.46.1", path = "protocols/gossipsub" } -libp2p-identify = { version = "0.44.1", path = "protocols/identify" } +libp2p-identify = { version = "0.45.0", path = "protocols/identify" } libp2p-identity = { version = "0.2.8" } libp2p-kad = { version = "0.45.3", path = "protocols/kad" } libp2p-mdns = { version = "0.45.1", path = "protocols/mdns" } @@ -97,10 +97,10 @@ libp2p-pnet = { version = "0.24.0", path = "transports/pnet" } libp2p-quic = { version = "0.10.2", path = "transports/quic" } libp2p-relay = { version = "0.17.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.14.0", path = "protocols/rendezvous" } -libp2p-request-response = { version = "0.26.1", path = "protocols/request-response" } +libp2p-request-response = { version = "0.27.0", path = "protocols/request-response" } libp2p-server = { version = "0.12.5", path = "misc/server" } -libp2p-swarm = { version = "0.44.1", path = "swarm" } libp2p-swarm-derive = { version = "=0.35.1", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. +libp2p-swarm = { version = "0.44.2", path = "swarm" } libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" } libp2p-tcp = { version = "0.41.0", path = "transports/tcp" } libp2p-tls = { version = "0.3.0", path = "transports/tls" } diff --git a/protocols/autonat/CHANGELOG.md b/protocols/autonat/CHANGELOG.md index 1259dd01fd41..484bb11b97a4 100644 --- a/protocols/autonat/CHANGELOG.md +++ b/protocols/autonat/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.12.1 - unreleased + +- Allow temporary use of deprecated `libp2p_request_response::add_address`. + See [PR 4371](https://github.com/libp2p/rust-libp2p/pull/4371) + ## 0.12.0 - Remove `Clone`, `PartialEq` and `Eq` implementations on `Event` and its sub-structs. diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index a1ecae7ccab6..4f44c2fb7a9b 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -3,8 +3,8 @@ name = "libp2p-autonat" edition = "2021" rust-version = { workspace = true } description = "NAT and firewall detection for libp2p" -version = "0.12.0" authors = ["David Craven ", "Elena Frank "] +version = "0.12.1" license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 22c74b28cae8..00681fdba84b 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.45.0 - unreleased + +- Emit `ToSwarm::NewExternalAddrOfPeer` when identified new peer. `PeerCache` uses `libp2p_swarm::PeerAddresses` + See [PR 4371](https://github.com/libp2p/rust-libp2p/pull/4371) + ## 0.44.1 - Ensure `Multiaddr` handled and returned by `Behaviour` are `/p2p` terminated. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 8168a3a3fc6e..2b257bc0a6bd 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-identify" edition = "2021" rust-version = { workspace = true } description = "Nodes identifcation protocol for libp2p" -version = "0.44.1" +version = "0.45.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index f013ff6265c5..953163af1ac6 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -273,7 +273,19 @@ impl NetworkBehaviour for Behaviour { let observed = info.observed_addr.clone(); self.events - .push_back(ToSwarm::GenerateEvent(Event::Received { peer_id, info })); + .push_back(ToSwarm::GenerateEvent(Event::Received { + peer_id, + info: info.clone(), + })); + + filter_new_external_addrs(&self.discovered_peers.get(&peer_id), &info.listen_addrs) + .iter() + .for_each(|address| { + self.events.push_back(ToSwarm::NewExternalAddrOfPeer { + peer_id, + addr: address.clone(), + }) + }); match self.our_observed_addresses.entry(id) { Entry::Vacant(not_yet_observed) => { @@ -444,6 +456,20 @@ fn multiaddr_matches_peer_id(addr: &Multiaddr, peer_id: &PeerId) -> bool { true } +fn filter_new_external_addrs( + cached_addrs: &[Multiaddr], + listen_addrs: &Vec, +) -> Vec { + let mut new_addresses = Vec::::new(); + + for address in listen_addrs { + if !cached_addrs.contains(address) { + new_addresses.push(address.clone()); + } + } + new_addresses +} + struct PeerCache(Option); impl PeerCache { @@ -495,4 +521,50 @@ mod tests { )); assert!(multiaddr_matches_peer_id(&addr_without_peer_id, &peer_id)); } + + #[test] + fn filter_new_external_addrs_leaves_new_addrs() { + let addr: Multiaddr = "/ip4/147.75.69.143/tcp/4001" + .parse() + .expect("failed to parse multiaddr"); + + let addr1: Multiaddr = "/ip4/147.75.69.143/tcp/4002" + .parse() + .expect("failed to parse multiaddr"); + + let old_addr: Multiaddr = "/memory/1234".parse().unwrap(); + let old_addr1: Multiaddr = "/memory/1233".parse().unwrap(); + let old_addr2: Multiaddr = "/memory/1235".parse().unwrap(); + + let old_addrs: Vec = [old_addr, old_addr1, old_addr2].to_vec(); + + let new_addrs = Vec::from([addr, addr1]); + + assert_eq!( + filter_new_external_addrs(&old_addrs, &new_addrs), + new_addrs.clone(), + ); + } + + #[test] + fn filter_new_external_addrs_filter_duplicates() { + let addr: Multiaddr = "/ip4/147.75.69.143/tcp/4001" + .parse() + .expect("failed to parse multiaddr"); + + let addr1: Multiaddr = "/ip4/147.75.69.143/tcp/4002" + .parse() + .expect("failed to parse multiaddr"); + + let old_addr: Multiaddr = "/memory/1234".parse().unwrap(); + let old_addr1: Multiaddr = "/memory/1233".parse().unwrap(); + let old_addr2: Multiaddr = "/memory/1235".parse().unwrap(); + + let mut old_addrs: Vec = [old_addr, old_addr1, old_addr2].to_vec(); + + let new_addrs = Vec::from([addr.clone(), addr1.clone()]); + old_addrs.append(&mut new_addrs.clone()); + + assert_eq!(filter_new_external_addrs(&old_addrs, &new_addrs), []) + } } diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index d53ff479ee28..6ca52ba33040 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.27.0 - unreleased + +- Deprecate `libp2p_request_response::add_address`. `Behaviour` `addresses` field uses `libp2p_swarm::PeerAddresses`. + See [PR 4371](https://github.com/libp2p/rust-libp2p/pull/4371) + ## 0.26.1 - Derive `PartialOrd` and `Ord` for `{Out,In}boundRequestId`. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 6da25e24862c..0e231d4ee1ab 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-request-response" edition = "2021" rust-version = { workspace = true } description = "Generic Request/Response Protocols" -version = "0.26.1" +version = "0.27.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -19,7 +19,7 @@ libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } rand = "0.8" -serde = { version = "1.0", optional = true} +serde = { version = "1.0", optional = true } serde_json = { version = "1.0.108", optional = true } smallvec = "1.11.2" tracing = "0.1.37" @@ -40,7 +40,7 @@ libp2p-yamux = { workspace = true } rand = "0.8" libp2p-swarm-test = { path = "../../swarm-test" } futures_ringbuf = "0.4.0" -serde = { version = "1.0", features = ["derive"]} +serde = { version = "1.0", features = ["derive"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index d6ebeaea5247..978716290a15 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm" edition = "2021" rust-version = { workspace = true } description = "The libp2p swarm" -version = "0.44.1" +version = "0.44.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p"