Skip to content

Commit 39ddeec

Browse files
committed
fix(upnp): skip port mapping when an active port mapping is present
1 parent e29dad6 commit 39ddeec

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ libp2p-swarm-test = { version = "0.6.0", path = "swarm-test" }
108108
libp2p-tcp = { version = "0.44.0", path = "transports/tcp" }
109109
libp2p-tls = { version = "0.6.2", path = "transports/tls" }
110110
libp2p-uds = { version = "0.43.0", path = "transports/uds" }
111-
libp2p-upnp = { version = "0.5.0", path = "protocols/upnp" }
111+
libp2p-upnp = { version = "0.6.0", path = "protocols/upnp" }
112112
libp2p-webrtc = { version = "0.9.0-alpha.1", path = "transports/webrtc" }
113113
libp2p-webrtc-utils = { version = "0.4.0", path = "misc/webrtc-utils" }
114114
libp2p-webrtc-websys = { version = "0.4.0", path = "transports/webrtc-websys" }

protocols/upnp/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.6.0
2+
3+
- Skip port mapping when an active port mapping is present.
4+
Previously, the behavior would skip creating new mappings if any mapping
5+
(active or inactive or pending) existed for the same port. Now it correctly only
6+
checks active mappings on the gateway.
7+
See [PR 6127](https://github.com/libp2p/rust-libp2p/pull/6127).
8+
19
## 0.5.0
210

311
- update igd-next to 0.16.1

protocols/upnp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-upnp"
33
edition.workspace = true
44
rust-version.workspace = true
55
description = "UPnP support for libp2p transports"
6-
version = "0.5.0"
6+
version = "0.6.0"
77
license = "MIT"
88
repository = "https://github.com/libp2p/rust-libp2p"
99
keywords = ["peer-to-peer", "libp2p", "networking"]

protocols/upnp/src/behaviour.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,14 @@ impl NetworkBehaviour for Behaviour {
270270
return;
271271
};
272272

273-
if let Some((mapping, _state)) = self
274-
.mappings
275-
.iter()
276-
.find(|(mapping, _state)| mapping.internal_addr.port() == addr.port())
277-
{
273+
if let Some((mapping, _state)) = self.mappings.iter().find(|(mapping, state)| {
274+
matches!(state, MappingState::Active(_))
275+
&& mapping.internal_addr.port() == addr.port()
276+
}) {
278277
tracing::debug!(
279278
multiaddress=%multiaddr,
280279
mapped_multiaddress=%mapping.multiaddr,
281-
"port from multiaddress is already being mapped"
280+
"port from multiaddress is already mapped on the gateway"
282281
);
283282
return;
284283
}

0 commit comments

Comments
 (0)