-
Notifications
You must be signed in to change notification settings - Fork 999
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
Removing the handler
field from FromSwarm::ConnectionClosed
in favor of ConnectionHandler::poll_close
#3046
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
BTW: the fact that May I suggest the very simple solution of putting both the |
I'd prefer a solution where we don't need to employ this.
With "reason" you mean the value returned in Overall, I agree with you that the error should be fed back to the |
I proposed |
@elenaf9 suggested in #3099 (comment), that we could just remove the handler from the |
Hi, we don't use this functionality atm 👍 |
FromSwarm::ConnectionClosed
not being Clone
handler
field from FromSwarm::ConnectionClosed
With #3927, removing the Fundamentally, the only use of returning the We could also solve this differently:
This would allow a Thoughts? |
How about adding the following. Enabling a graceful shutdown of a modified swarm/src/handler.rs
@@ -158,6 +158,15 @@ pub trait ConnectionHandler: Send + 'static {
>,
>;
+ /// Gracefully close the [`ConnectionHandler`].
+ ///
+ /// Implementations may transfer one or more events to their [`NetworkBehaviour`] implementation
+ /// by emitting [`Poll::Ready`] with [`Self::ToBehaviour`]. Implementations should eventually
+ /// return [`Poll::Ready(None)`] to signal successful closing.
+ fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::ToBehaviour>> {
+ Poll::Ready(None)
+ }
+
/// Adds a closure that turns the input event into something else.
fn map_in_event<TNewIn, TMap>(self, map: TMap) -> MapInEvent<Self, TNewIn, TMap>
where (Note the default implementation.) |
This is a great idea! I'll update the original issue description with this solution. |
handler
field from FromSwarm::ConnectionClosed
handler
field from FromSwarm::ConnectionClosed
in favor of ConnectionHandler::poll_close
Instead of transferring the `ConnectionHandler` back in a event to the `NetworkBehaviour`, we introduce `ConnectionHandler::poll_close`. This function will be polled like a `Stream` and can emit events that will be delivered to the `NetworkBehaviour`. Resolves: libp2p#3046. Pull-Request: libp2p#4076.
Currently,
FromSwarm::ConnectionClosed
contains ahandler
field which makes handling the event klunky in many ways:Clone
SwarmEvent
andFromSwarm
despite them containing the same dataThe usecase for returning the handler is to allow the behaviour to extract data from a closed connection which would other get lost as connections can close at any point. Nothing is currently using this functionality but it makes sense in general so we want to keep it.
We can solve this by adding a
poll_close
function as described by @mxinden below: #3046 (comment)Upon closing a connection,
poll_close
would be called until it returnsReady(None)
and all returned events would be delivered to the behaviour.The text was updated successfully, but these errors were encountered: