-
Notifications
You must be signed in to change notification settings - Fork 1.2k
swarm/handler: replace inject_* methods #3085
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
Conversation
d926cd2 to
d60c0e7
Compare
on ConnectionHandler implementations
d60c0e7 to
cf9768f
Compare
mxinden
left a comment
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.
Cool to see this work happening. Let us know once this is ready for a review.
swarm/src/handler.rs
Outdated
| #[deprecated( | ||
| since = "0.41.0", | ||
| note = "Handle `StreamEvent::FullyNegotiatedInbound` on `ConnectionHandler::on_event` instead. | ||
| the default of implemention of this inject_*` method delegates to it." |
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 default of implemention of this inject_*` method delegates to it." | |
| The default implementation of this `inject_*` method delegates to it." |
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 Max! addressed.
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.
Cool to see this work happening. Let us know once this is ready for a review.
Thanks Max, yeah I am waiting for #3011 to be merged cause this PR also touches some of the same files to then rebase against master and mark it as ready.
swarm/src/handler.rs
Outdated
|
|
||
| /// Enumeration with the list of the possible stream events | ||
| /// to pass to [`on_event`](ConnectionHandler::on_event). | ||
| pub enum StreamEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { |
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.
An alternative to explore (not saying it is a good idea) would be to take a single trait parameter, namely ConnectionHandler here.
| pub enum StreamEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { | |
| pub enum StreamEvent<'a, Handler: ConnectionHandler> { |
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 for bringing this Max,
yeah it works but we need to relax the sizedness to Handler: ConnectionHandler + ?Sized because on_event's argument event: StreamEvent<Self> which afaik will probably be problematic if we in the future define methods on ConnectionHandler that take self and StreamEvent<Self> cause Self must be Sized and StreamEvent<Self> may be ?Sized. Would you prefer that over the multiple generic parameters?
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.
yeah it works but we need to relax the sizedness to
Handler: ConnectionHandler + ?Sizedbecauseon_event's argumentevent: StreamEvent<Self>which afaik will probably be problematic if we in the future define methods onConnectionHandlerthat takeselfandStreamEvent<Self>causeSelfmust beSizedandStreamEvent<Self>may be?Sized.
I am not sure I am following. In which case would ConnectionHandler not be Sized? In which case would this be problematic?
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 approach you suggest on #3085 (comment):
| pub enum StreamEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { | |
| pub enum StreamEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { |
implies relaxing StreamEvent<Handler> to StreamEvent<Handler: ConnectionHandler + ?Sized>.
thomaseizinger
left a comment
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.
Looking good! Thank you :)
swarm/src/handler.rs
Outdated
| /// informs the handler about an event coming from the outside in the handler. | ||
| fn on_behaviour_event(&mut self, _event: Self::InEvent) {} | ||
|
|
||
| fn on_event( |
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.
Should this be an on_connection_event maybe? It would be nicer to have both on_ handlers use some kind of qualifier.
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.
yeah makes sense, thanks Thomas updated! :)
| match event { | ||
| StreamEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { protocol, info }) => | ||
| { | ||
| #[allow(deprecated)] | ||
| self.inner.inject_fully_negotiated_inbound(protocol, info) | ||
| } | ||
| StreamEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { protocol, info }) => | ||
| { | ||
| #[allow(deprecated)] | ||
| self.inner.inject_fully_negotiated_outbound(protocol, info) | ||
| } | ||
| StreamEvent::AddressChange(AddressChange { new_address }) => | ||
| { | ||
| #[allow(deprecated)] | ||
| self.inner.inject_address_change(new_address) | ||
| } | ||
| StreamEvent::DialUpgradeError(DialUpgradeError { info, error }) => | ||
| { | ||
| #[allow(deprecated)] | ||
| self.inner.inject_dial_upgrade_error(info, error) | ||
| } | ||
| StreamEvent::ListenUpgradeError(ListenUpgradeError { info, error }) => | ||
| { | ||
| #[allow(deprecated)] | ||
| self.inner.inject_listen_upgrade_error(info, error) | ||
| } | ||
| } |
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.
I guess this can be replaced with self.inner.on_event once we remove them right?
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.
yeah exactly, also see #3011 (comment)
swarm/src/handler/pending.rs
Outdated
| use std::task::{Context, Poll}; | ||
| use void::Void; | ||
|
|
||
| use super::{FullyNegotiatedInbound, FullyNegotiatedOutbound, StreamEvent}; |
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.
I'd prefer to not use super imports.
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.
yeah, makes total sense, specailly cause we are already importing with crate::handler. Thanks Thomas, updated!
swarm/src/handler.rs
Outdated
|
|
||
| /// Enumeration with the list of the possible stream events | ||
| /// to pass to [`on_event`](ConnectionHandler::on_event). | ||
| pub enum StreamEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { |
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.
| pub enum StreamEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { | |
| pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { |
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.
updated!
and StreamEvent -> ConnectionEvent.
mxinden
left a comment
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.
Minor comments. Otherwise this looks good to me.
swarm/src/handler.rs
Outdated
| #[deprecated( | ||
| since = "0.41.0", | ||
| note = "Handle `ConnectionEvent::FullyNegotiatedInbound` on `ConnectionHandler::on_connection_event` instead. | ||
| The default of implemention of this `inject_*` method delegates to it." |
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 default of implemention of this `inject_*` method delegates to it." | |
| The default implementation of this `inject_*` method delegates to it." |
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 Max 🙇
swarm/src/handler.rs
Outdated
| ConnectionHandlerSelect::new(self, other) | ||
| } | ||
|
|
||
| /// informs the handler about an event coming from the outside in the handler. |
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.
| /// informs the handler about an event coming from the outside in the handler. | |
| /// Informs the handler about an event from the [`NetworkBehaviour`]. |
I would find this easier to understand. What do you think?
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.
yeah I agree, thanks!
swarm/src/handler.rs
Outdated
| pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { | ||
| /// Informs the handler about the output of a successful upgrade on a new inbound substream. | ||
| FullyNegotiatedInbound(FullyNegotiatedInbound<IP, IOI>), | ||
| /// Informs the handler about successful upgrade on a new outbound stream. |
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.
| /// Informs the handler about successful upgrade on a new outbound stream. | |
| /// Informs the handler about the output of a successful upgrade on a new outbound stream. |
To be consistent with the above.
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.
yeah makes sense, thanks Max!
| fn on_behaviour_event(&mut self, _event: Self::InEvent) {} | ||
|
|
||
| fn on_connection_event( | ||
| &mut self, | ||
| _event: ConnectionEvent< | ||
| Self::InboundProtocol, | ||
| Self::OutboundProtocol, | ||
| Self::InboundOpenInfo, | ||
| Self::OutboundOpenInfo, | ||
| >, | ||
| ) { | ||
| } | ||
| } |
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.
I wonder, once Self::InEvent is called Self::FromBehaviour, should we rename ConnectionEvent to FromConnection?
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.
Works for me, though I suggest not doing that within this pull request.
mxinden
left a comment
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 for the follow-ups.
|
Happy to merge here. Let's give @thomaseizinger antoher chance to review. |
thomaseizinger
left a comment
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.
LGTM!
|
@jxs can you take a look at the CI failure? https://github.com/libp2p/rust-libp2p/actions/runs/3474448909/jobs/5807623337 |
|
This pull request has merge conflicts. Could you please resolve them @jxs? 🙏 |
thanks for noticing Max! Yeah added the missing |
mxinden
left a comment
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.
🚀
Description
Previously, we had one callback for each kind of message that a
ConnectionHandlerwould receive from either itsNetworkBehaviouror the connection itself.With this patch, we combine these functions, resulting in two callbacks:
on_behaviour_eventon_connection_eventResolves #3080.
Links to any relevant issues
ConnectionHandlercounterpart to #3011Open Questions
Change checklist