mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-23 06:41: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:
@ -239,8 +239,8 @@ impl<TCodec> ConnectionHandler for Handler<TCodec>
|
||||
where
|
||||
TCodec: Codec + Send + Clone + 'static,
|
||||
{
|
||||
type InEvent = RequestProtocol<TCodec>;
|
||||
type OutEvent = Event<TCodec>;
|
||||
type FromBehaviour = RequestProtocol<TCodec>;
|
||||
type ToBehaviour = Event<TCodec>;
|
||||
type Error = StreamUpgradeError<io::Error>;
|
||||
type InboundProtocol = ResponseProtocol<TCodec>;
|
||||
type OutboundProtocol = RequestProtocol<TCodec>;
|
||||
@ -281,7 +281,7 @@ where
|
||||
SubstreamProtocol::new(proto, request_id).with_timeout(self.substream_timeout)
|
||||
}
|
||||
|
||||
fn on_behaviour_event(&mut self, request: Self::InEvent) {
|
||||
fn on_behaviour_event(&mut self, request: Self::FromBehaviour) {
|
||||
self.keep_alive = KeepAlive::Yes;
|
||||
self.outbound.push_back(request);
|
||||
}
|
||||
@ -293,8 +293,9 @@ where
|
||||
fn poll(
|
||||
&mut self,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<ConnectionHandlerEvent<RequestProtocol<TCodec>, RequestId, Self::OutEvent, Self::Error>>
|
||||
{
|
||||
) -> Poll<
|
||||
ConnectionHandlerEvent<RequestProtocol<TCodec>, RequestId, Self::ToBehaviour, Self::Error>,
|
||||
> {
|
||||
// Check for a pending (fatal) error.
|
||||
if let Some(err) = self.pending_error.take() {
|
||||
// The handler will not be polled again by the `Swarm`.
|
||||
|
@ -683,7 +683,7 @@ where
|
||||
TCodec: Codec + Send + Clone + 'static,
|
||||
{
|
||||
type ConnectionHandler = Handler<TCodec>;
|
||||
type OutEvent = Event<TCodec::Request, TCodec::Response>;
|
||||
type ToSwarm = Event<TCodec::Request, TCodec::Response>;
|
||||
|
||||
fn handle_established_inbound_connection(
|
||||
&mut self,
|
||||
@ -878,7 +878,7 @@ where
|
||||
&mut self,
|
||||
_: &mut Context<'_>,
|
||||
_: &mut impl PollParameters,
|
||||
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
|
||||
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
|
||||
if let Some(ev) = self.pending_events.pop_front() {
|
||||
return Poll::Ready(ev);
|
||||
} else if self.pending_events.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD {
|
||||
|
Reference in New Issue
Block a user