mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-30 16:31:57 +00:00
feat(swarm): rename associated types for message passing
Previously, the associated types on `NetworkBehaviour` and `ConnectionHandler` carried generic names like `InEvent` and `OutEvent`. These names are _correct_ in that `OutEvent`s are passed out and `InEvent`s are passed in but they don't help users understand how these types are used. In theory, a `ConnectionHandler` could be used separately from `NetworkBehaviour`s but that is highly unlikely. Thus, we rename these associated types to indicate, where the message is going to be sent to: - `NetworkBehaviour::OutEvent` is renamed to `ToSwarm`: It describes the message(s) a `NetworkBehaviour` can emit to the `Swarm`. The user is going to receive those in `SwarmEvent::Behaviour`. - `ConnectionHandler::InEvent` is renamed to `FromBehaviour`: It describes the message(s) a `ConnectionHandler` can receive from its behaviour via `ConnectionHandler::on_swarm_event`. The `NetworkBehaviour` can send it via the `ToSwarm::NotifyHandler` command. - `ConnectionHandler::OutEvent` is renamed to `ToBehaviour`: It describes the message(s) a `ConnectionHandler` can send back to the behaviour via the now also renamed `ConnectionHandlerEvent::NotifyBehaviour` (previously `ConnectionHandlerEvent::Custom`) Resolves: #2854. Pull-Request: #3848.
This commit is contained in:
@@ -237,7 +237,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
handler::relayed::Handler,
|
||||
Either<handler::direct::Handler, dummy::ConnectionHandler>,
|
||||
>;
|
||||
type OutEvent = Event;
|
||||
type ToSwarm = Event;
|
||||
|
||||
fn handle_established_inbound_connection(
|
||||
&mut self,
|
||||
@@ -415,7 +415,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
_cx: &mut Context<'_>,
|
||||
_: &mut impl PollParameters,
|
||||
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
|
||||
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
|
||||
if let Some(event) = self.queued_events.pop_front() {
|
||||
return Poll::Ready(event);
|
||||
}
|
||||
|
@@ -39,8 +39,8 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl ConnectionHandler for Handler {
|
||||
type InEvent = void::Void;
|
||||
type OutEvent = Event;
|
||||
type FromBehaviour = void::Void;
|
||||
type ToBehaviour = Event;
|
||||
type Error = StreamUpgradeError<std::io::Error>;
|
||||
type InboundProtocol = DeniedUpgrade;
|
||||
type OutboundProtocol = DeniedUpgrade;
|
||||
@@ -51,7 +51,7 @@ impl ConnectionHandler for Handler {
|
||||
SubstreamProtocol::new(DeniedUpgrade, ())
|
||||
}
|
||||
|
||||
fn on_behaviour_event(&mut self, _: Self::InEvent) {}
|
||||
fn on_behaviour_event(&mut self, _: Self::FromBehaviour) {}
|
||||
|
||||
fn connection_keep_alive(&self) -> KeepAlive {
|
||||
KeepAlive::No
|
||||
@@ -64,7 +64,7 @@ impl ConnectionHandler for Handler {
|
||||
ConnectionHandlerEvent<
|
||||
Self::OutboundProtocol,
|
||||
Self::OutboundOpenInfo,
|
||||
Self::OutEvent,
|
||||
Self::ToBehaviour,
|
||||
Self::Error,
|
||||
>,
|
||||
> {
|
||||
|
@@ -135,7 +135,7 @@ pub struct Handler {
|
||||
ConnectionHandlerEvent<
|
||||
<Self as ConnectionHandler>::OutboundProtocol,
|
||||
<Self as ConnectionHandler>::OutboundOpenInfo,
|
||||
<Self as ConnectionHandler>::OutEvent,
|
||||
<Self as ConnectionHandler>::ToBehaviour,
|
||||
<Self as ConnectionHandler>::Error,
|
||||
>,
|
||||
>,
|
||||
@@ -254,8 +254,8 @@ impl Handler {
|
||||
}
|
||||
|
||||
impl ConnectionHandler for Handler {
|
||||
type InEvent = Command;
|
||||
type OutEvent = Event;
|
||||
type FromBehaviour = Command;
|
||||
type ToBehaviour = Event;
|
||||
type Error = StreamUpgradeError<
|
||||
Either<protocol::inbound::UpgradeError, protocol::outbound::UpgradeError>,
|
||||
>;
|
||||
@@ -280,7 +280,7 @@ impl ConnectionHandler for Handler {
|
||||
}
|
||||
}
|
||||
|
||||
fn on_behaviour_event(&mut self, event: Self::InEvent) {
|
||||
fn on_behaviour_event(&mut self, event: Self::FromBehaviour) {
|
||||
match event {
|
||||
Command::Connect { obs_addrs } => {
|
||||
self.queued_events
|
||||
@@ -323,7 +323,7 @@ impl ConnectionHandler for Handler {
|
||||
ConnectionHandlerEvent<
|
||||
Self::OutboundProtocol,
|
||||
Self::OutboundOpenInfo,
|
||||
Self::OutEvent,
|
||||
Self::ToBehaviour,
|
||||
Self::Error,
|
||||
>,
|
||||
> {
|
||||
|
Reference in New Issue
Block a user