From b42523a75cb93996ed25129e5a5e937c193c42ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20RIBEAU?= Date: Thu, 29 Aug 2024 09:36:42 +0200 Subject: [PATCH] fix(relay): malformed reported relayed addr when relay peer is dialer --- Cargo.lock | 2 +- Cargo.toml | 2 +- protocols/relay/CHANGELOG.md | 5 +++++ protocols/relay/Cargo.toml | 2 +- protocols/relay/src/priv_client.rs | 10 +++++++++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f37b652c306..2be3418f7187 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3206,7 +3206,7 @@ dependencies = [ [[package]] name = "libp2p-relay" -version = "0.18.0" +version = "0.18.1" dependencies = [ "asynchronous-codec", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 8d63ac3ee1ee..51947ff5f19e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,7 +97,7 @@ libp2p-ping = { version = "0.45.0", path = "protocols/ping" } libp2p-plaintext = { version = "0.42.0", path = "transports/plaintext" } libp2p-pnet = { version = "0.25.0", path = "transports/pnet" } libp2p-quic = { version = "0.11.1", path = "transports/quic" } -libp2p-relay = { version = "0.18.0", path = "protocols/relay" } +libp2p-relay = { version = "0.18.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.15.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.27.0", path = "protocols/request-response" } libp2p-server = { version = "0.12.7", path = "misc/server" } diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index fc71ccedad5d..d9865a140c11 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.18.1 + +- Fix malformed reported addr when relay peer is dialer. + See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX). + ## 0.18.0 diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 084fec07efdb..16449f57df5b 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-relay" edition = "2021" rust-version = { workspace = true } description = "Communications relaying for libp2p" -version = "0.18.0" +version = "0.18.1" authors = ["Parity Technologies ", "Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index f8d1d9c9eb23..67f1e55164c9 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -164,7 +164,15 @@ impl NetworkBehaviour for Behaviour { if local_addr.is_relayed() { return Ok(Either::Right(dummy::ConnectionHandler)); } - let mut handler = Handler::new(self.local_peer_id, peer, remote_addr.clone()); + + let mut handler = match remote_addr.clone().with_p2p(peer) { + Ok(remote_addr) => Handler::new(self.local_peer_id, peer, remote_addr), + Err(remote_addr) => { + return Err(ConnectionDenied::new(format!( + "addr {remote_addr} contains a PeerId not matching {peer}" + ))) + } + }; if let Some(event) = self.pending_handler_commands.remove(&connection_id) { handler.on_behaviour_event(event)