mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-30 11:11:21 +00:00
fix(swarm): external address candidate only after address translation
Pull-Request: #4158.
This commit is contained in:
parent
b6b8844123
commit
b4c7dfca63
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3104,7 +3104,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libp2p-swarm"
|
name = "libp2p-swarm"
|
||||||
version = "0.43.0"
|
version = "0.43.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"either",
|
"either",
|
||||||
|
@ -87,7 +87,7 @@ libp2p-quic = { version = "0.8.0-alpha", path = "transports/quic" }
|
|||||||
libp2p-relay = { version = "0.16.0", path = "protocols/relay" }
|
libp2p-relay = { version = "0.16.0", path = "protocols/relay" }
|
||||||
libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" }
|
libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" }
|
||||||
libp2p-request-response = { version = "0.25.0", path = "protocols/request-response" }
|
libp2p-request-response = { version = "0.25.0", path = "protocols/request-response" }
|
||||||
libp2p-swarm = { version = "0.43.0", path = "swarm" }
|
libp2p-swarm = { version = "0.43.1", path = "swarm" }
|
||||||
libp2p-swarm-derive = { version = "0.33.0", path = "swarm-derive" }
|
libp2p-swarm-derive = { version = "0.33.0", path = "swarm-derive" }
|
||||||
libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" }
|
libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" }
|
||||||
libp2p-tcp = { version = "0.40.0", path = "transports/tcp" }
|
libp2p-tcp = { version = "0.40.0", path = "transports/tcp" }
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
## 0.43.0
|
## 0.43.1 - unreleased
|
||||||
|
|
||||||
|
- Do not announce external address candidate before address translation, unless translation does not apply.
|
||||||
|
This will prevent ephemeral TCP addresses being announced as external address candidates.
|
||||||
|
See [PR 4158].
|
||||||
|
|
||||||
|
|
||||||
|
## 0.43.0
|
||||||
|
|
||||||
- Allow `NetworkBehaviours` to create and remove listeners.
|
- Allow `NetworkBehaviours` to create and remove listeners.
|
||||||
See [PR 3292].
|
See [PR 3292].
|
||||||
|
@ -3,7 +3,7 @@ name = "libp2p-swarm"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = { workspace = true }
|
rust-version = { workspace = true }
|
||||||
description = "The libp2p swarm"
|
description = "The libp2p swarm"
|
||||||
version = "0.43.0"
|
version = "0.43.1"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
|
@ -1062,14 +1062,8 @@ where
|
|||||||
self.pending_event = Some((peer_id, handler, event));
|
self.pending_event = Some((peer_id, handler, event));
|
||||||
}
|
}
|
||||||
ToSwarm::NewExternalAddrCandidate(addr) => {
|
ToSwarm::NewExternalAddrCandidate(addr) => {
|
||||||
self.behaviour
|
// Apply address translation to the candidate address.
|
||||||
.on_swarm_event(FromSwarm::NewExternalAddrCandidate(
|
|
||||||
NewExternalAddrCandidate { addr: &addr },
|
|
||||||
));
|
|
||||||
|
|
||||||
// Generate more candidates based on address translation.
|
|
||||||
// For TCP without port-reuse, the observed address contains an ephemeral port which needs to be replaced by the port of a listen address.
|
// For TCP without port-reuse, the observed address contains an ephemeral port which needs to be replaced by the port of a listen address.
|
||||||
|
|
||||||
let translated_addresses = {
|
let translated_addresses = {
|
||||||
let mut addrs: Vec<_> = self
|
let mut addrs: Vec<_> = self
|
||||||
.listened_addrs
|
.listened_addrs
|
||||||
@ -1083,11 +1077,20 @@ where
|
|||||||
addrs.dedup();
|
addrs.dedup();
|
||||||
addrs
|
addrs
|
||||||
};
|
};
|
||||||
for addr in translated_addresses {
|
|
||||||
|
// If address translation yielded nothing, broacast the original candidate address.
|
||||||
|
if translated_addresses.is_empty() {
|
||||||
self.behaviour
|
self.behaviour
|
||||||
.on_swarm_event(FromSwarm::NewExternalAddrCandidate(
|
.on_swarm_event(FromSwarm::NewExternalAddrCandidate(
|
||||||
NewExternalAddrCandidate { addr: &addr },
|
NewExternalAddrCandidate { addr: &addr },
|
||||||
));
|
));
|
||||||
|
} else {
|
||||||
|
for addr in translated_addresses {
|
||||||
|
self.behaviour
|
||||||
|
.on_swarm_event(FromSwarm::NewExternalAddrCandidate(
|
||||||
|
NewExternalAddrCandidate { addr: &addr },
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToSwarm::ExternalAddrConfirmed(addr) => {
|
ToSwarm::ExternalAddrConfirmed(addr) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user