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.

Pull-Request: #4052.
This commit is contained in:
Max Inden
2023-06-09 05:26:24 +02:00
committed by GitHub
parent c2230f9948
commit 2910c985e8
3 changed files with 16 additions and 0 deletions

View File

@ -214,6 +214,7 @@ fn main() -> Result<(), Box<dyn Error>> {
..
})) => {
info!("Relay told us our public address: {:?}", observed_addr);
swarm.add_external_address(observed_addr);
learned_observed_addr = true;
}
event => panic!("{event:?}"),

View File

@ -82,6 +82,14 @@ fn main() -> Result<(), Box<dyn Error>> {
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, .. } => {