From 935e903fced7ec006db38731df14676fcc93cd2d Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Wed, 25 Dec 2024 13:57:40 +0700 Subject: [PATCH 1/3] relay: remove duplicate forwarding of handler events --- protocols/relay/src/priv_client.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index 7ac9b716700..1aaef156c96 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -208,21 +208,11 @@ impl NetworkBehaviour for Behaviour { connection_id, endpoint, .. - }) => { - if !endpoint.is_relayed() { - self.directly_connected_peers - .entry(peer_id) - .or_default() - .push(connection_id); - } - - if let Some(event) = self.pending_handler_commands.remove(&connection_id) { - self.queued_actions.push_back(ToSwarm::NotifyHandler { - peer_id, - handler: NotifyHandler::One(connection_id), - event: Either::Left(event), - }) - } + }) if !endpoint.is_relayed() => { + self.directly_connected_peers + .entry(peer_id) + .or_default() + .push(connection_id); } FromSwarm::ConnectionClosed(connection_closed) => { self.on_connection_closed(connection_closed) From adb8660b5e88a0399cad2a0ee0fc3bb1e82609bf Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Wed, 25 Dec 2024 14:14:44 +0700 Subject: [PATCH 2/3] relay: also rm pending handler event if connection is relayed --- protocols/relay/src/priv_client.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index 1aaef156c96..b8be01a2ea0 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -168,12 +168,14 @@ impl NetworkBehaviour for Behaviour { local_addr: &Multiaddr, remote_addr: &Multiaddr, ) -> Result, ConnectionDenied> { + let pending_handler_command = self.pending_handler_commands.remove(&connection_id); + if local_addr.is_relayed() { return Ok(Either::Right(dummy::ConnectionHandler)); } let mut handler = Handler::new(self.local_peer_id, peer, remote_addr.clone()); - if let Some(event) = self.pending_handler_commands.remove(&connection_id) { + if let Some(event) = pending_handler_command { handler.on_behaviour_event(event) } @@ -188,13 +190,15 @@ impl NetworkBehaviour for Behaviour { _: Endpoint, _: PortUse, ) -> Result, ConnectionDenied> { + let pending_handler_command = self.pending_handler_commands.remove(&connection_id); + if addr.is_relayed() { return Ok(Either::Right(dummy::ConnectionHandler)); } let mut handler = Handler::new(self.local_peer_id, peer, addr.clone()); - if let Some(event) = self.pending_handler_commands.remove(&connection_id) { + if let Some(event) = pending_handler_command { handler.on_behaviour_event(event) } From 1b8c4301a55304c1fd87e069bd2b015d841bed07 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Sun, 26 Jan 2025 15:50:04 +0700 Subject: [PATCH 3/3] relay: bump version, add changelog entry --- Cargo.lock | 2 +- Cargo.toml | 2 +- protocols/relay/CHANGELOG.md | 4 ++++ protocols/relay/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a811dcc6de9..f5ebfaeb1f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3191,7 +3191,7 @@ dependencies = [ [[package]] name = "libp2p-relay" -version = "0.19.0" +version = "0.19.1" dependencies = [ "asynchronous-codec", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 4b92b086326..72373a564a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,7 @@ libp2p-ping = { version = "0.46.0", path = "protocols/ping" } libp2p-plaintext = { version = "0.43.0", path = "transports/plaintext" } libp2p-pnet = { version = "0.26.0", path = "transports/pnet" } libp2p-quic = { version = "0.12.0", path = "transports/quic" } -libp2p-relay = { version = "0.19.0", path = "protocols/relay" } +libp2p-relay = { version = "0.19.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.16.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.28.0", path = "protocols/request-response" } libp2p-server = { version = "0.12.6", path = "misc/server" } diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index e60dcfb7596..549c545c036 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.19.1 + +- Remove duplicated forwarding of pending events to connection handler. + ## 0.19.0 - Deprecate `void` crate. diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 23715fc86de..bd34fa7ee34 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.19.0" +version = "0.19.1" authors = ["Parity Technologies ", "Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p"