From 5fc50d0cac35a9a721373c7d7c274502f5f837a4 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 9 Jun 2023 12:01:17 +0900 Subject: [PATCH] fix(examples): call `Swarm::add_external_address` in dcutr and relay > Observed addresses (aka. external address candidates) of the local node, reported by a remote node > via `libp2p-identify`, are no longer automatically considered confirmed external addresses, in > other words they are no longer trusted by default. Instead users need to confirm the reported > observed address either manually, or by using `libp2p-autonat`. In trusted environments users can > simply extract observed addresses from a `libp2p-identify::Event::Received { info: > libp2p_identify::Info { observed_addr }}` and confirm them via `Swarm::add_external_address`. Follow-up to https://github.com/libp2p/rust-libp2p/pull/3954. --- examples/dcutr/src/main.rs | 1 + examples/relay-server/src/main.rs | 8 ++++++++ protocols/identify/CHANGELOG.md | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index df14e79828b..83b64c98a5e 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -214,6 +214,7 @@ fn main() -> Result<(), Box> { .. })) => { info!("Relay told us our public address: {:?}", observed_addr); + swarm.add_external_address(observed_addr); learned_observed_addr = true; } event => panic!("{event:?}"), diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index cf265e78f05..5a2b61d853a 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -82,6 +82,14 @@ fn main() -> Result<(), Box> { loop { match swarm.next().await.expect("Infinite Stream.") { SwarmEvent::Behaviour(event) => { + if let BehaviourEvent::Identify(identify::Event::Received { + info: identify::Info { observed_addr, .. }, + .. + }) = &event + { + swarm.add_external_address(observed_addr.clone()); + } + println!("{event:?}") } SwarmEvent::NewListenAddr { address, .. } => { diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index f90d8ce3da4..84676095ba9 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,5 +1,10 @@ ## 0.43.0 - unreleased +- Observed addresses (aka. external address candidates) of the local node, reported by a remote node via `libp2p-identify`, are no longer automatically considered confirmed external addresses, in other words they are no longer trusted by default. + Instead users need to confirm the reported observed address either manually, or by using `libp2p-autonat`. + In trusted environments users can simply extract observed addresses from a `libp2p-identify::Event::Received { info: libp2p_identify::Info { observed_addr }}` and confirm them via `Swarm::add_external_address`. + See [PR 3954] and [PR XXX]. + - Remove deprecated `Identify` prefixed symbols. See [PR 3698]. - Raise MSRV to 1.65. See [PR 3715]. @@ -17,7 +22,9 @@ [PR 3698]: https://github.com/libp2p/rust-libp2p/pull/3698 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 [PR 3876]: https://github.com/libp2p/rust-libp2p/pull/3876 +[PR 3954]: https://github.com/libp2p/rust-libp2p/pull/3954 [PR 3980]: https://github.com/libp2p/rust-libp2p/pull/3980 +[PR XXX]: https://github.com/libp2p/rust-libp2p/pull/XXX ## 0.42.2