-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: master
Are you sure you want to change the base?
fix(relay/client): only try to forward handler events once #5765
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch Elena LGTM!
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I feel it was more readable the previous way as it was all on a single line. You mention that:
However, it requires that in handle_established_{in, out}bound_connection the event is also removed when the connection is relayed, in which case the event is simply discarded because the commands are only valid on direct connections.
but this happened before right?
Description
We currently try to forward pending handler events in the relay client behavior twice: in
handle_established_{in, out}bound_connection
and inon_swarm_event()
(introduced in #3328).This is redundant because by the second time we try to forward it there won't be any pending event anymore.
This PR removes the duplicated logic from
on_swarm_event
. Forwarding it inhandle_established_{in, out}bound_connection
is more convenient as we still have direct access to the handler there and don't need to go through the swarm.However, it requires that in
handle_established_{in, out}bound_connection
the event is also removed when the connection is relayed, in which case the event is simply discarded because the commands are only valid on direct connections.Notes & open questions
Change checklist
I have made corresponding changes to the documentationI have added tests that prove my fix is effective or that my feature works