Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(relay/client): only try to forward handler events once #5765

Merged
merged 9 commits into from
Jan 27, 2025
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 4 additions & 0 deletions protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.19.1

- Remove duplicated forwarding of pending events to connection handler.

## 0.19.0

- Deprecate `void` crate.
Expand Down
2 changes: 1 addition & 1 deletion protocols/relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>", "Max Inden <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
28 changes: 11 additions & 17 deletions protocols/relay/src/priv_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,14 @@ impl NetworkBehaviour for Behaviour {
local_addr: &Multiaddr,
remote_addr: &Multiaddr,
) -> Result<THandler<Self>, 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 {
jxs marked this conversation as resolved.
Show resolved Hide resolved
handler.on_behaviour_event(event)
}

Expand All @@ -188,13 +190,15 @@ impl NetworkBehaviour for Behaviour {
_: Endpoint,
_: PortUse,
) -> Result<THandler<Self>, 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)
}

Expand All @@ -208,21 +212,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)
Expand Down
Loading