-
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
swarm/: include ListenerId in SwarmEvents #2123
Conversation
Note: one of the the relay tests ( |
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.
Implementation looks good to me! I actually have a direct use for this in the tests for the rendezvous protocol! :)
When glancing over the code, I noticed that the relay tests might benefit from this aswell.
@thomaseizinger do you mean by doing something like this?:
I could add that, just wanted to know first whether the change in this PR is generally desired. What do you think @mxinden? |
Yep, that is what I was thinking. To be fair, for this case it doesn't matter much because comparing the address also works :) |
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.
Exposing ListenerId
on NewListenAddr
, ExpiredListenAddr
and ListenerClosed
sounds good to me. Thanks for the patch @elenaf9!
It allows to map the event back to a previously called swarm.listen_on(). This is especially useful if swarm.listen_on() was called with an zeroed Multiaddress (e.g. /ip4/0.0.0.0/tcp/0), and the actual new address should be mapped back to the newly created listener, without blocking.
Just a note: a single listen_on
might cause multiple NewListenAddr
events.
Would you mind adding a note to Swarm::listen_on
and Swarm::remove_listener
mentioning that they cause one or more NewListenAddr
or ExpiredListenAddr
events with the same ListenerId
. I could imagine this being helpful for newcomers.
Also, could you add an entry to swarm/CHANGELOG.md
?
swarm/src/lib.rs
Outdated
ExpiredListenAddr{ | ||
/// The listener that is no longer listening on the address. | ||
listener_id: ListenerId, | ||
/// The new address that is being listened on. |
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.
/// The new address that is being listened on. | |
/// The expired address. |
Sounds good, I'll do that. Just one note (related to Discussion #2113): If I'm not mistaken |
Right. My bad. Thanks @elenaf9! |
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.
Thanks @elenaf9!
Just a couple of nit picks on naming in relay/tests/lib
to be consistent with the other variable names. Other than that this is good to go from my side.
Co-authored-by: Max Inden <[email protected]>
This PR drafts a change that I'd like to suggest:
I think it would be useful if in case of
SwarmEvent
s associated with a listener (e.g.SwarmEvent::NewListenAddr
), the event would include the id of the associated listener.It allows to map the event back to a previously called
swarm.listen_on()
. This is especially useful ifswarm.listen_on()
was called with an zeroed Multiaddress (e.g./ip4/0.0.0.0/tcp/0
), and the actual new address should be mapped back to the newly created listener, without blocking.Since this information is already in the
NetworkEvent
that the ExpandedSwarm receives, I don't see a reason to not include it, especially since the user already has to deal withListenerId
s.