mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 16:51:34 +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:
@ -179,8 +179,8 @@ where
|
||||
TProto1: ConnectionHandler,
|
||||
TProto2: ConnectionHandler,
|
||||
{
|
||||
type InEvent = Either<TProto1::InEvent, TProto2::InEvent>;
|
||||
type OutEvent = Either<TProto1::OutEvent, TProto2::OutEvent>;
|
||||
type FromBehaviour = Either<TProto1::FromBehaviour, TProto2::FromBehaviour>;
|
||||
type ToBehaviour = Either<TProto1::ToBehaviour, TProto2::ToBehaviour>;
|
||||
type Error = Either<TProto1::Error, TProto2::Error>;
|
||||
type InboundProtocol = SelectUpgrade<
|
||||
SendWrapper<<TProto1 as ConnectionHandler>::InboundProtocol>,
|
||||
@ -201,7 +201,7 @@ where
|
||||
SubstreamProtocol::new(choice, (i1, i2)).with_timeout(timeout)
|
||||
}
|
||||
|
||||
fn on_behaviour_event(&mut self, event: Self::InEvent) {
|
||||
fn on_behaviour_event(&mut self, event: Self::FromBehaviour) {
|
||||
match event {
|
||||
Either::Left(event) => self.proto1.on_behaviour_event(event),
|
||||
Either::Right(event) => self.proto2.on_behaviour_event(event),
|
||||
@ -222,7 +222,7 @@ where
|
||||
ConnectionHandlerEvent<
|
||||
Self::OutboundProtocol,
|
||||
Self::OutboundOpenInfo,
|
||||
Self::OutEvent,
|
||||
Self::ToBehaviour,
|
||||
Self::Error,
|
||||
>,
|
||||
> {
|
||||
|
Reference in New Issue
Block a user