-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
refactor: split NetworkEventListenerProvider
#12972
refactor: split NetworkEventListenerProvider
#12972
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.
this looks great already.
will take a closer look once rfr, but this is exactly what we wanted.
I hope you didn't encounter too many conflicts while working on this -.-
Thanks but I wonder if we can remove |
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 but I wonder if we can remove SessionEstablished from PeerEvent, and only have ActivePeerSession in NetworkEvent
I think this is fine because we can easily a NetworkEvent into a PeerEvent
otherwise there is always this double case if both events are emitted, and it can result in doing the same action, or do we need both ?
but I think I get your point that this currently requires a another peer_events_sender
channel?
since we can extract PeerEvent from NetworkEvent, we can avoid this if we change the Stream
type that NetworkPeersEvents::event_listener
returns.
we can introduce a helper wrapper type that holds Pin<Box<Stream Item = PeerEvent> + Send + Sync>
this way we can use the generic EventStream<NetworkEvent<R>>;
but convert the NetworkEvent
to PeerEvent
, erasing the generic
crates/net/network/src/network.rs
Outdated
/// Sender for basic peer lifecycle events. | ||
peer_events_sender: EventSender<PeerEvent>, |
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.
oh I think this is likely not necessary because peerEvent is a subset of of NetworkEvent now, so we can use the same event channel if we change the stream type
crates/net/network-api/src/events.rs
Outdated
#[auto_impl::auto_impl(&, Arc)] | ||
pub trait NetworkPeersEvents: Send + Sync { | ||
/// Creates a new [`PeerEvent`] listener channel. | ||
fn peer_events(&self) -> EventStream<PeerEvent>; |
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.
instead of EventStream
this could return a static BoxStream
(or ideally a newtype wrapper) of EventStream<NetworkEvent>.map(Into)
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!
cc @Rjected this unblocks more progress on txmanager
/// Handles session establishment and peer transactions initialization. | ||
fn handle_peer_session( | ||
&mut self, | ||
info: SessionInfo, | ||
messages: PeerRequestSender<PeerRequest<N>>, | ||
) { |
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, nice additional cleanup
Closes #12861.
TODO:
network.md