feat(swarm): rename Custom variant to NotifyBehaviour

Rename `ConnectionHandlerEvent::Custom` to `ConnectionHandlerEvent::NotifyBehaviour`.

Related #3848.

Pull-Request: #3955.
This commit is contained in:
Thomas Coratger
2023-05-16 21:20:00 +02:00
committed by GitHub
parent fbd471cd79
commit 9f3c85164c
18 changed files with 221 additions and 175 deletions

View File

@@ -263,7 +263,7 @@ where
requested_substreams.push(SubstreamRequested::new(user_data, timeout, upgrade));
continue; // Poll handler until exhausted.
}
Poll::Ready(ConnectionHandlerEvent::Custom(event)) => {
Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(event)) => {
return Poll::Ready(Ok(Event::Handler(event)));
}
Poll::Ready(ConnectionHandlerEvent::Close(err)) => {

View File

@@ -101,7 +101,7 @@ use std::{cmp::Ordering, error, fmt, io, task::Context, task::Poll, time::Durati
pub trait ConnectionHandler: Send + 'static {
/// A type representing the message(s) a [`NetworkBehaviour`](crate::behaviour::NetworkBehaviour) can send to a [`ConnectionHandler`] via [`ToSwarm::NotifyHandler`](crate::behaviour::ToSwarm::NotifyHandler)
type FromBehaviour: fmt::Debug + Send + 'static;
/// A type representing message(s) a [`ConnectionHandler`] can send to a [`NetworkBehaviour`](crate::behaviour::NetworkBehaviour) via [`ConnectionHandlerEvent::Custom`].
/// A type representing message(s) a [`ConnectionHandler`] can send to a [`NetworkBehaviour`](crate::behaviour::NetworkBehaviour) via [`ConnectionHandlerEvent::NotifyBehaviour`].
type ToBehaviour: fmt::Debug + Send + 'static;
/// The type of errors returned by [`ConnectionHandler::poll`].
type Error: error::Error + fmt::Debug + Send + 'static;
@@ -508,8 +508,8 @@ pub enum ConnectionHandlerEvent<TConnectionUpgrade, TOutboundOpenInfo, TCustom,
/// We learned something about the protocols supported by the remote.
ReportRemoteProtocols(ProtocolSupport),
/// Other event.
Custom(TCustom),
/// Event that is sent to a [`NetworkBehaviour`](crate::behaviour::NetworkBehaviour).
NotifyBehaviour(TCustom),
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -539,7 +539,9 @@ impl<TConnectionUpgrade, TOutboundOpenInfo, TCustom, TErr>
protocol: protocol.map_info(map),
}
}
ConnectionHandlerEvent::Custom(val) => ConnectionHandlerEvent::Custom(val),
ConnectionHandlerEvent::NotifyBehaviour(val) => {
ConnectionHandlerEvent::NotifyBehaviour(val)
}
ConnectionHandlerEvent::Close(val) => ConnectionHandlerEvent::Close(val),
ConnectionHandlerEvent::ReportRemoteProtocols(support) => {
ConnectionHandlerEvent::ReportRemoteProtocols(support)
@@ -562,7 +564,9 @@ impl<TConnectionUpgrade, TOutboundOpenInfo, TCustom, TErr>
protocol: protocol.map_upgrade(map),
}
}
ConnectionHandlerEvent::Custom(val) => ConnectionHandlerEvent::Custom(val),
ConnectionHandlerEvent::NotifyBehaviour(val) => {
ConnectionHandlerEvent::NotifyBehaviour(val)
}
ConnectionHandlerEvent::Close(val) => ConnectionHandlerEvent::Close(val),
ConnectionHandlerEvent::ReportRemoteProtocols(support) => {
ConnectionHandlerEvent::ReportRemoteProtocols(support)
@@ -582,7 +586,9 @@ impl<TConnectionUpgrade, TOutboundOpenInfo, TCustom, TErr>
ConnectionHandlerEvent::OutboundSubstreamRequest { protocol } => {
ConnectionHandlerEvent::OutboundSubstreamRequest { protocol }
}
ConnectionHandlerEvent::Custom(val) => ConnectionHandlerEvent::Custom(map(val)),
ConnectionHandlerEvent::NotifyBehaviour(val) => {
ConnectionHandlerEvent::NotifyBehaviour(map(val))
}
ConnectionHandlerEvent::Close(val) => ConnectionHandlerEvent::Close(val),
ConnectionHandlerEvent::ReportRemoteProtocols(support) => {
ConnectionHandlerEvent::ReportRemoteProtocols(support)
@@ -602,7 +608,9 @@ impl<TConnectionUpgrade, TOutboundOpenInfo, TCustom, TErr>
ConnectionHandlerEvent::OutboundSubstreamRequest { protocol } => {
ConnectionHandlerEvent::OutboundSubstreamRequest { protocol }
}
ConnectionHandlerEvent::Custom(val) => ConnectionHandlerEvent::Custom(val),
ConnectionHandlerEvent::NotifyBehaviour(val) => {
ConnectionHandlerEvent::NotifyBehaviour(val)
}
ConnectionHandlerEvent::Close(val) => ConnectionHandlerEvent::Close(map(val)),
ConnectionHandlerEvent::ReportRemoteProtocols(support) => {
ConnectionHandlerEvent::ReportRemoteProtocols(support)

View File

@@ -76,7 +76,9 @@ where
>,
> {
self.inner.poll(cx).map(|ev| match ev {
ConnectionHandlerEvent::Custom(ev) => ConnectionHandlerEvent::Custom((self.map)(ev)),
ConnectionHandlerEvent::NotifyBehaviour(ev) => {
ConnectionHandlerEvent::NotifyBehaviour((self.map)(ev))
}
ConnectionHandlerEvent::Close(err) => ConnectionHandlerEvent::Close(err),
ConnectionHandlerEvent::OutboundSubstreamRequest { protocol } => {
ConnectionHandlerEvent::OutboundSubstreamRequest { protocol }

View File

@@ -157,7 +157,9 @@ where
}
if !self.events_out.is_empty() {
return Poll::Ready(ConnectionHandlerEvent::Custom(self.events_out.remove(0)));
return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(
self.events_out.remove(0),
));
} else {
self.events_out.shrink_to_fit();
}

View File

@@ -227,8 +227,8 @@ where
>,
> {
match self.proto1.poll(cx) {
Poll::Ready(ConnectionHandlerEvent::Custom(event)) => {
return Poll::Ready(ConnectionHandlerEvent::Custom(Either::Left(event)));
Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(event)) => {
return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(Either::Left(event)));
}
Poll::Ready(ConnectionHandlerEvent::Close(event)) => {
return Poll::Ready(ConnectionHandlerEvent::Close(Either::Left(event)));
@@ -247,8 +247,10 @@ where
};
match self.proto2.poll(cx) {
Poll::Ready(ConnectionHandlerEvent::Custom(event)) => {
return Poll::Ready(ConnectionHandlerEvent::Custom(Either::Right(event)));
Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(event)) => {
return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(Either::Right(
event,
)));
}
Poll::Ready(ConnectionHandlerEvent::Close(event)) => {
return Poll::Ready(ConnectionHandlerEvent::Close(Either::Right(event)));