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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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 {
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