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

Create ListenersEvent::Closed on Swarm::remove_listener #2261

Merged
merged 6 commits into from
Oct 11, 2021

Conversation

elenaf9
Copy link
Contributor

@elenaf9 elenaf9 commented Oct 2, 2021

Discussion #2113.
Create a ListenersEvent::Closed when a listener is removed via Swarm::remove_listener.
This makes it more consistent with Swarm::listen_on, and also informs the Swarm about the associated expired addresses.

I initially tried to realize it via a Stream implementation on the connection::Listener, so that it would just return Poll::Ready(None) if the listener was removed (see this commit). But due to Listener being wrapped in a Pin it is a bit more complicated, whereas this Draft now is only a very minimal change.

Note: 0efe82c introduces a minor API change so that remove_listener returns a boolean instead of Result<(), ()>. This 1. more consistent with other methods like remove_external_address, and 2. follows the clippy lint of result_unit_err.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favor of this change.

core/src/connection/listeners.rs Outdated Show resolved Hide resolved
@elenaf9 elenaf9 marked this pull request as ready for review October 6, 2021 23:06
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! One question inline.

let listener_project = listener.as_mut().project();
self.pending_events.push_back(ListenersEvent::Closed {
listener_id: *listener_project.id,
addresses: listener_project.addresses.drain(..).collect(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would std::mem::replace also work here? Slightly more readable IMO.

@mxinden
Copy link
Member

mxinden commented Oct 9, 2021

Giving others a chance to comment on the latest changes. Will merge early next week in case there are no further comments.

@mxinden mxinden merged commit 7718d1d into libp2p:master Oct 11, 2021
@mxinden
Copy link
Member

mxinden commented Oct 11, 2021

Thanks @elenaf9!

@elenaf9 elenaf9 deleted the core/close-listener branch October 12, 2021 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants