mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-19 22:21:21 +00:00
swarm(-derive)/: Rename references of protocol handler to connection handler (#2640)
This commit is contained in:
parent
d21cd5fed7
commit
d97893d293
@ -1,3 +1,9 @@
|
|||||||
|
# 0.27.2 [unreleased]
|
||||||
|
|
||||||
|
- Replace references of Protocol Handler with Connection Handler. See [PR 2640].
|
||||||
|
|
||||||
|
[PR 2640]: https://github.com/libp2p/rust-libp2p/pull/2640
|
||||||
|
|
||||||
# 0.27.1
|
# 0.27.1
|
||||||
|
|
||||||
- Allow mixing of ignored fields. See [PR 2570].
|
- Allow mixing of ignored fields. See [PR 2570].
|
||||||
|
@ -3,7 +3,7 @@ name = "libp2p-swarm-derive"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.56.1"
|
rust-version = "1.56.1"
|
||||||
description = "Procedural macros of libp2p-core"
|
description = "Procedural macros of libp2p-core"
|
||||||
version = "0.27.1"
|
version = "0.27.2"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
|
@ -50,8 +50,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
|||||||
let net_behv_event_proc = quote! {::libp2p::swarm::NetworkBehaviourEventProcess};
|
let net_behv_event_proc = quote! {::libp2p::swarm::NetworkBehaviourEventProcess};
|
||||||
let either_ident = quote! {::libp2p::core::either::EitherOutput};
|
let either_ident = quote! {::libp2p::core::either::EitherOutput};
|
||||||
let network_behaviour_action = quote! {::libp2p::swarm::NetworkBehaviourAction};
|
let network_behaviour_action = quote! {::libp2p::swarm::NetworkBehaviourAction};
|
||||||
let into_protocols_handler = quote! {::libp2p::swarm::IntoConnectionHandler};
|
let into_connection_handler = quote! {::libp2p::swarm::IntoConnectionHandler};
|
||||||
let protocols_handler = quote! {::libp2p::swarm::ConnectionHandler};
|
let connection_handler = quote! {::libp2p::swarm::ConnectionHandler};
|
||||||
let into_proto_select_ident = quote! {::libp2p::swarm::IntoConnectionHandlerSelect};
|
let into_proto_select_ident = quote! {::libp2p::swarm::IntoConnectionHandlerSelect};
|
||||||
let peer_id = quote! {::libp2p::core::PeerId};
|
let peer_id = quote! {::libp2p::core::PeerId};
|
||||||
let connection_id = quote! {::libp2p::core::connection::ConnectionId};
|
let connection_id = quote! {::libp2p::core::connection::ConnectionId};
|
||||||
@ -371,7 +371,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// The [`ConnectionHandler`] associated type.
|
// The [`ConnectionHandler`] associated type.
|
||||||
let protocols_handler_ty = {
|
let connection_handler_ty = {
|
||||||
let mut ph_ty = None;
|
let mut ph_ty = None;
|
||||||
for field in data_struct_fields.iter() {
|
for field in data_struct_fields.iter() {
|
||||||
let ty = &field.ty;
|
let ty = &field.ty;
|
||||||
@ -402,7 +402,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
|||||||
|
|
||||||
match out_handler {
|
match out_handler {
|
||||||
Some(h) => {
|
Some(h) => {
|
||||||
out_handler = Some(quote! { #into_protocols_handler::select(#h, #builder) })
|
out_handler = Some(quote! { #into_connection_handler::select(#h, #builder) })
|
||||||
}
|
}
|
||||||
ref mut h @ None => *h = Some(builder),
|
ref mut h @ None => *h = Some(builder),
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
|||||||
|
|
||||||
match out_handler {
|
match out_handler {
|
||||||
Some(h) => {
|
Some(h) => {
|
||||||
out_handler = Some(quote! { #into_protocols_handler::select(#h, #builder) })
|
out_handler = Some(quote! { #into_connection_handler::select(#h, #builder) })
|
||||||
}
|
}
|
||||||
ref mut h @ None => *h = Some(builder),
|
ref mut h @ None => *h = Some(builder),
|
||||||
}
|
}
|
||||||
@ -530,11 +530,11 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
|||||||
impl #impl_generics #trait_to_impl for #name #ty_generics
|
impl #impl_generics #trait_to_impl for #name #ty_generics
|
||||||
#where_clause
|
#where_clause
|
||||||
{
|
{
|
||||||
type ConnectionHandler = #protocols_handler_ty;
|
type ConnectionHandler = #connection_handler_ty;
|
||||||
type OutEvent = #out_event;
|
type OutEvent = #out_event;
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||||
use #into_protocols_handler;
|
use #into_connection_handler;
|
||||||
#new_handler
|
#new_handler
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,7 +552,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
|||||||
#(#inject_address_change_stmts);*
|
#(#inject_address_change_stmts);*
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_connection_closed(&mut self, peer_id: &#peer_id, connection_id: &#connection_id, endpoint: &#connected_point, handlers: <Self::ConnectionHandler as #into_protocols_handler>::Handler, remaining_established: usize) {
|
fn inject_connection_closed(&mut self, peer_id: &#peer_id, connection_id: &#connection_id, endpoint: &#connected_point, handlers: <Self::ConnectionHandler as #into_connection_handler>::Handler, remaining_established: usize) {
|
||||||
#(#inject_connection_closed_stmts);*
|
#(#inject_connection_closed_stmts);*
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,7 +596,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
|||||||
&mut self,
|
&mut self,
|
||||||
peer_id: #peer_id,
|
peer_id: #peer_id,
|
||||||
connection_id: #connection_id,
|
connection_id: #connection_id,
|
||||||
event: <<Self::ConnectionHandler as #into_protocols_handler>::Handler as #protocols_handler>::OutEvent
|
event: <<Self::ConnectionHandler as #into_connection_handler>::Handler as #connection_handler>::OutEvent
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
#(#inject_node_event_stmts),*
|
#(#inject_node_event_stmts),*
|
||||||
|
@ -8,9 +8,12 @@
|
|||||||
|
|
||||||
- Rename `IncomingInfo::to_connected_point` to `IncomingInfo::create_connected_point`. See [PR 2620].
|
- Rename `IncomingInfo::to_connected_point` to `IncomingInfo::create_connected_point`. See [PR 2620].
|
||||||
|
|
||||||
|
- Rename `TProtoHandler` to `TConnectionHandler`, `ToggleProtoHandler` to `ToggleConnectionHandler`, `ToggleIntoProtoHandler` to `ToggleIntoConnectionHandler`. See [PR 2640].
|
||||||
|
|
||||||
[PR 2529]: https://github.com/libp2p/rust-libp2p/pull/2529
|
[PR 2529]: https://github.com/libp2p/rust-libp2p/pull/2529
|
||||||
[PR 2610]: https://github.com/libp2p/rust-libp2p/pull/2610
|
[PR 2610]: https://github.com/libp2p/rust-libp2p/pull/2610
|
||||||
[PR 2620]: https://github.com/libp2p/rust-libp2p/pull/2620
|
[PR 2620]: https://github.com/libp2p/rust-libp2p/pull/2620
|
||||||
|
[PR 2640]: https://github.com/libp2p/rust-libp2p/pull/2640
|
||||||
|
|
||||||
# 0.35.0
|
# 0.35.0
|
||||||
|
|
||||||
|
@ -70,11 +70,11 @@ impl<TBehaviour> NetworkBehaviour for Toggle<TBehaviour>
|
|||||||
where
|
where
|
||||||
TBehaviour: NetworkBehaviour,
|
TBehaviour: NetworkBehaviour,
|
||||||
{
|
{
|
||||||
type ConnectionHandler = ToggleIntoProtoHandler<TBehaviour::ConnectionHandler>;
|
type ConnectionHandler = ToggleIntoConnectionHandler<TBehaviour::ConnectionHandler>;
|
||||||
type OutEvent = TBehaviour::OutEvent;
|
type OutEvent = TBehaviour::OutEvent;
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||||
ToggleIntoProtoHandler {
|
ToggleIntoConnectionHandler {
|
||||||
inner: self.inner.as_mut().map(|i| i.new_handler()),
|
inner: self.inner.as_mut().map(|i| i.new_handler()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,9 +223,9 @@ where
|
|||||||
params: &mut impl PollParameters,
|
params: &mut impl PollParameters,
|
||||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||||
if let Some(inner) = self.inner.as_mut() {
|
if let Some(inner) = self.inner.as_mut() {
|
||||||
inner
|
inner.poll(cx, params).map(|action| {
|
||||||
.poll(cx, params)
|
action.map_handler(|h| ToggleIntoConnectionHandler { inner: Some(h) })
|
||||||
.map(|action| action.map_handler(|h| ToggleIntoProtoHandler { inner: Some(h) }))
|
})
|
||||||
} else {
|
} else {
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
}
|
||||||
@ -244,22 +244,22 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of `IntoConnectionHandler` that can be in the disabled state.
|
/// Implementation of `IntoConnectionHandler` that can be in the disabled state.
|
||||||
pub struct ToggleIntoProtoHandler<TInner> {
|
pub struct ToggleIntoConnectionHandler<TInner> {
|
||||||
inner: Option<TInner>,
|
inner: Option<TInner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TInner> IntoConnectionHandler for ToggleIntoProtoHandler<TInner>
|
impl<TInner> IntoConnectionHandler for ToggleIntoConnectionHandler<TInner>
|
||||||
where
|
where
|
||||||
TInner: IntoConnectionHandler,
|
TInner: IntoConnectionHandler,
|
||||||
{
|
{
|
||||||
type Handler = ToggleProtoHandler<TInner::Handler>;
|
type Handler = ToggleConnectionHandler<TInner::Handler>;
|
||||||
|
|
||||||
fn into_handler(
|
fn into_handler(
|
||||||
self,
|
self,
|
||||||
remote_peer_id: &PeerId,
|
remote_peer_id: &PeerId,
|
||||||
connected_point: &ConnectedPoint,
|
connected_point: &ConnectedPoint,
|
||||||
) -> Self::Handler {
|
) -> Self::Handler {
|
||||||
ToggleProtoHandler {
|
ToggleConnectionHandler {
|
||||||
inner: self
|
inner: self
|
||||||
.inner
|
.inner
|
||||||
.map(|h| h.into_handler(remote_peer_id, connected_point)),
|
.map(|h| h.into_handler(remote_peer_id, connected_point)),
|
||||||
@ -276,11 +276,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of [`ConnectionHandler`] that can be in the disabled state.
|
/// Implementation of [`ConnectionHandler`] that can be in the disabled state.
|
||||||
pub struct ToggleProtoHandler<TInner> {
|
pub struct ToggleConnectionHandler<TInner> {
|
||||||
inner: Option<TInner>,
|
inner: Option<TInner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TInner> ConnectionHandler for ToggleProtoHandler<TInner>
|
impl<TInner> ConnectionHandler for ToggleConnectionHandler<TInner>
|
||||||
where
|
where
|
||||||
TInner: ConnectionHandler,
|
TInner: ConnectionHandler,
|
||||||
{
|
{
|
||||||
@ -426,7 +426,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::handler::DummyConnectionHandler;
|
use crate::handler::DummyConnectionHandler;
|
||||||
|
|
||||||
/// A disabled [`ToggleProtoHandler`] can receive listen upgrade errors in
|
/// A disabled [`ToggleConnectionHandler`] can receive listen upgrade errors in
|
||||||
/// the following two cases:
|
/// the following two cases:
|
||||||
///
|
///
|
||||||
/// 1. Protocol negotiation on an incoming stream failed with no protocol
|
/// 1. Protocol negotiation on an incoming stream failed with no protocol
|
||||||
@ -435,14 +435,14 @@ mod tests {
|
|||||||
/// 2. When combining [`ConnectionHandler`] implementations a single
|
/// 2. When combining [`ConnectionHandler`] implementations a single
|
||||||
/// [`ConnectionHandler`] might be notified of an inbound upgrade error
|
/// [`ConnectionHandler`] might be notified of an inbound upgrade error
|
||||||
/// unrelated to its own upgrade logic. For example when nesting a
|
/// unrelated to its own upgrade logic. For example when nesting a
|
||||||
/// [`ToggleProtoHandler`] in a
|
/// [`ToggleConnectionHandler`] in a
|
||||||
/// [`ConnectionHandlerSelect`](crate::protocols_handler::ConnectionHandlerSelect)
|
/// [`ConnectionHandlerSelect`](crate::connection_handler::ConnectionHandlerSelect)
|
||||||
/// the former might receive an inbound upgrade error even when disabled.
|
/// the former might receive an inbound upgrade error even when disabled.
|
||||||
///
|
///
|
||||||
/// [`ToggleProtoHandler`] should ignore the error in both of these cases.
|
/// [`ToggleConnectionHandler`] should ignore the error in both of these cases.
|
||||||
#[test]
|
#[test]
|
||||||
fn ignore_listen_upgrade_error_when_disabled() {
|
fn ignore_listen_upgrade_error_when_disabled() {
|
||||||
let mut handler = ToggleProtoHandler::<DummyConnectionHandler> { inner: None };
|
let mut handler = ToggleConnectionHandler::<DummyConnectionHandler> { inner: None };
|
||||||
|
|
||||||
handler.inject_listen_upgrade_error(Either::Right(()), ConnectionHandlerUpgrErr::Timeout);
|
handler.inject_listen_upgrade_error(Either::Right(()), ConnectionHandlerUpgrErr::Timeout);
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,10 @@ where
|
|||||||
/// Begins an orderly shutdown of the connection, returning the connection
|
/// Begins an orderly shutdown of the connection, returning the connection
|
||||||
/// handler and a `Future` that resolves when connection shutdown is complete.
|
/// handler and a `Future` that resolves when connection shutdown is complete.
|
||||||
pub fn close(self) -> (THandler, Close<StreamMuxerBox>) {
|
pub fn close(self) -> (THandler, Close<StreamMuxerBox>) {
|
||||||
(self.handler.into_protocols_handler(), self.muxing.close().0)
|
(
|
||||||
|
self.handler.into_connection_handler(),
|
||||||
|
self.muxing.close().0,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Polls the handler and the substream, forwarding events from the former to the latter and
|
/// Polls the handler and the substream, forwarding events from the former to the latter and
|
||||||
|
@ -42,35 +42,35 @@ use std::{error, fmt, pin::Pin, task::Context, task::Poll, time::Duration};
|
|||||||
/// - Driving substream upgrades
|
/// - Driving substream upgrades
|
||||||
/// - Handling connection timeout
|
/// - Handling connection timeout
|
||||||
// TODO: add a caching system for protocols that are supported or not
|
// TODO: add a caching system for protocols that are supported or not
|
||||||
pub struct HandlerWrapper<TProtoHandler>
|
pub struct HandlerWrapper<TConnectionHandler>
|
||||||
where
|
where
|
||||||
TProtoHandler: ConnectionHandler,
|
TConnectionHandler: ConnectionHandler,
|
||||||
{
|
{
|
||||||
/// The underlying handler.
|
/// The underlying handler.
|
||||||
handler: TProtoHandler,
|
handler: TConnectionHandler,
|
||||||
/// Futures that upgrade incoming substreams.
|
/// Futures that upgrade incoming substreams.
|
||||||
negotiating_in: FuturesUnordered<
|
negotiating_in: FuturesUnordered<
|
||||||
SubstreamUpgrade<
|
SubstreamUpgrade<
|
||||||
TProtoHandler::InboundOpenInfo,
|
TConnectionHandler::InboundOpenInfo,
|
||||||
InboundUpgradeApply<
|
InboundUpgradeApply<
|
||||||
Substream<StreamMuxerBox>,
|
Substream<StreamMuxerBox>,
|
||||||
SendWrapper<TProtoHandler::InboundProtocol>,
|
SendWrapper<TConnectionHandler::InboundProtocol>,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
/// Futures that upgrade outgoing substreams.
|
/// Futures that upgrade outgoing substreams.
|
||||||
negotiating_out: FuturesUnordered<
|
negotiating_out: FuturesUnordered<
|
||||||
SubstreamUpgrade<
|
SubstreamUpgrade<
|
||||||
TProtoHandler::OutboundOpenInfo,
|
TConnectionHandler::OutboundOpenInfo,
|
||||||
OutboundUpgradeApply<
|
OutboundUpgradeApply<
|
||||||
Substream<StreamMuxerBox>,
|
Substream<StreamMuxerBox>,
|
||||||
SendWrapper<TProtoHandler::OutboundProtocol>,
|
SendWrapper<TConnectionHandler::OutboundProtocol>,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
/// For each outbound substream request, how to upgrade it. The first element of the tuple
|
/// For each outbound substream request, how to upgrade it. The first element of the tuple
|
||||||
/// is the unique identifier (see `unique_dial_upgrade_id`).
|
/// is the unique identifier (see `unique_dial_upgrade_id`).
|
||||||
queued_dial_upgrades: Vec<(u64, SendWrapper<TProtoHandler::OutboundProtocol>)>,
|
queued_dial_upgrades: Vec<(u64, SendWrapper<TConnectionHandler::OutboundProtocol>)>,
|
||||||
/// Unique identifier assigned to each queued dial upgrade.
|
/// Unique identifier assigned to each queued dial upgrade.
|
||||||
unique_dial_upgrade_id: u64,
|
unique_dial_upgrade_id: u64,
|
||||||
/// The currently planned connection & handler shutdown.
|
/// The currently planned connection & handler shutdown.
|
||||||
@ -79,7 +79,7 @@ where
|
|||||||
substream_upgrade_protocol_override: Option<upgrade::Version>,
|
substream_upgrade_protocol_override: Option<upgrade::Version>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TProtoHandler: ConnectionHandler> std::fmt::Debug for HandlerWrapper<TProtoHandler> {
|
impl<TConnectionHandler: ConnectionHandler> std::fmt::Debug for HandlerWrapper<TConnectionHandler> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("HandlerWrapper")
|
f.debug_struct("HandlerWrapper")
|
||||||
.field("negotiating_in", &self.negotiating_in)
|
.field("negotiating_in", &self.negotiating_in)
|
||||||
@ -94,9 +94,9 @@ impl<TProtoHandler: ConnectionHandler> std::fmt::Debug for HandlerWrapper<TProto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TProtoHandler: ConnectionHandler> HandlerWrapper<TProtoHandler> {
|
impl<TConnectionHandler: ConnectionHandler> HandlerWrapper<TConnectionHandler> {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
handler: TProtoHandler,
|
handler: TConnectionHandler,
|
||||||
substream_upgrade_protocol_override: Option<upgrade::Version>,
|
substream_upgrade_protocol_override: Option<upgrade::Version>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -110,7 +110,7 @@ impl<TProtoHandler: ConnectionHandler> HandlerWrapper<TProtoHandler> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn into_protocols_handler(self) -> TProtoHandler {
|
pub(crate) fn into_connection_handler(self) -> TConnectionHandler {
|
||||||
self.handler
|
self.handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,22 +224,22 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type OutboundOpenInfo<TProtoHandler> = (
|
pub type OutboundOpenInfo<TConnectionHandler> = (
|
||||||
u64,
|
u64,
|
||||||
<TProtoHandler as ConnectionHandler>::OutboundOpenInfo,
|
<TConnectionHandler as ConnectionHandler>::OutboundOpenInfo,
|
||||||
Duration,
|
Duration,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<TProtoHandler> HandlerWrapper<TProtoHandler>
|
impl<TConnectionHandler> HandlerWrapper<TConnectionHandler>
|
||||||
where
|
where
|
||||||
TProtoHandler: ConnectionHandler,
|
TConnectionHandler: ConnectionHandler,
|
||||||
{
|
{
|
||||||
pub fn inject_substream(
|
pub fn inject_substream(
|
||||||
&mut self,
|
&mut self,
|
||||||
substream: Substream<StreamMuxerBox>,
|
substream: Substream<StreamMuxerBox>,
|
||||||
// The first element of the tuple is the unique upgrade identifier
|
// The first element of the tuple is the unique upgrade identifier
|
||||||
// (see `unique_dial_upgrade_id`).
|
// (see `unique_dial_upgrade_id`).
|
||||||
endpoint: SubstreamEndpoint<OutboundOpenInfo<TProtoHandler>>,
|
endpoint: SubstreamEndpoint<OutboundOpenInfo<TConnectionHandler>>,
|
||||||
) {
|
) {
|
||||||
match endpoint {
|
match endpoint {
|
||||||
SubstreamEndpoint::Listener => {
|
SubstreamEndpoint::Listener => {
|
||||||
@ -290,7 +290,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inject_event(&mut self, event: TProtoHandler::InEvent) {
|
pub fn inject_event(&mut self, event: TConnectionHandler::InEvent) {
|
||||||
self.handler.inject_event(event);
|
self.handler.inject_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,8 +303,8 @@ where
|
|||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
) -> Poll<
|
) -> Poll<
|
||||||
Result<
|
Result<
|
||||||
Event<OutboundOpenInfo<TProtoHandler>, TProtoHandler::OutEvent>,
|
Event<OutboundOpenInfo<TConnectionHandler>, TConnectionHandler::OutEvent>,
|
||||||
Error<TProtoHandler::Error>,
|
Error<TConnectionHandler::Error>,
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
while let Poll::Ready(Some((user_data, res))) = self.negotiating_in.poll_next_unpin(cx) {
|
while let Poll::Ready(Some((user_data, res))) = self.negotiating_in.poll_next_unpin(cx) {
|
||||||
|
@ -27,15 +27,15 @@ use libp2p_core::Multiaddr;
|
|||||||
use std::{fmt::Debug, marker::PhantomData, task::Context, task::Poll};
|
use std::{fmt::Debug, marker::PhantomData, task::Context, task::Poll};
|
||||||
|
|
||||||
/// Wrapper around a protocol handler that turns the input event into something else.
|
/// Wrapper around a protocol handler that turns the input event into something else.
|
||||||
pub struct MapInEvent<TProtoHandler, TNewIn, TMap> {
|
pub struct MapInEvent<TConnectionHandler, TNewIn, TMap> {
|
||||||
inner: TProtoHandler,
|
inner: TConnectionHandler,
|
||||||
map: TMap,
|
map: TMap,
|
||||||
marker: PhantomData<TNewIn>,
|
marker: PhantomData<TNewIn>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TProtoHandler, TMap, TNewIn> MapInEvent<TProtoHandler, TNewIn, TMap> {
|
impl<TConnectionHandler, TMap, TNewIn> MapInEvent<TConnectionHandler, TNewIn, TMap> {
|
||||||
/// Creates a `MapInEvent`.
|
/// Creates a `MapInEvent`.
|
||||||
pub(crate) fn new(inner: TProtoHandler, map: TMap) -> Self {
|
pub(crate) fn new(inner: TConnectionHandler, map: TMap) -> Self {
|
||||||
MapInEvent {
|
MapInEvent {
|
||||||
inner,
|
inner,
|
||||||
map,
|
map,
|
||||||
@ -44,20 +44,21 @@ impl<TProtoHandler, TMap, TNewIn> MapInEvent<TProtoHandler, TNewIn, TMap> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TProtoHandler, TMap, TNewIn> ConnectionHandler for MapInEvent<TProtoHandler, TNewIn, TMap>
|
impl<TConnectionHandler, TMap, TNewIn> ConnectionHandler
|
||||||
|
for MapInEvent<TConnectionHandler, TNewIn, TMap>
|
||||||
where
|
where
|
||||||
TProtoHandler: ConnectionHandler,
|
TConnectionHandler: ConnectionHandler,
|
||||||
TMap: Fn(TNewIn) -> Option<TProtoHandler::InEvent>,
|
TMap: Fn(TNewIn) -> Option<TConnectionHandler::InEvent>,
|
||||||
TNewIn: Debug + Send + 'static,
|
TNewIn: Debug + Send + 'static,
|
||||||
TMap: Send + 'static,
|
TMap: Send + 'static,
|
||||||
{
|
{
|
||||||
type InEvent = TNewIn;
|
type InEvent = TNewIn;
|
||||||
type OutEvent = TProtoHandler::OutEvent;
|
type OutEvent = TConnectionHandler::OutEvent;
|
||||||
type Error = TProtoHandler::Error;
|
type Error = TConnectionHandler::Error;
|
||||||
type InboundProtocol = TProtoHandler::InboundProtocol;
|
type InboundProtocol = TConnectionHandler::InboundProtocol;
|
||||||
type OutboundProtocol = TProtoHandler::OutboundProtocol;
|
type OutboundProtocol = TConnectionHandler::OutboundProtocol;
|
||||||
type InboundOpenInfo = TProtoHandler::InboundOpenInfo;
|
type InboundOpenInfo = TConnectionHandler::InboundOpenInfo;
|
||||||
type OutboundOpenInfo = TProtoHandler::OutboundOpenInfo;
|
type OutboundOpenInfo = TConnectionHandler::OutboundOpenInfo;
|
||||||
|
|
||||||
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
|
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
|
||||||
self.inner.listen_protocol()
|
self.inner.listen_protocol()
|
||||||
|
@ -28,32 +28,32 @@ use std::fmt::Debug;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
/// Wrapper around a protocol handler that turns the output event into something else.
|
/// Wrapper around a protocol handler that turns the output event into something else.
|
||||||
pub struct MapOutEvent<TProtoHandler, TMap> {
|
pub struct MapOutEvent<TConnectionHandler, TMap> {
|
||||||
inner: TProtoHandler,
|
inner: TConnectionHandler,
|
||||||
map: TMap,
|
map: TMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TProtoHandler, TMap> MapOutEvent<TProtoHandler, TMap> {
|
impl<TConnectionHandler, TMap> MapOutEvent<TConnectionHandler, TMap> {
|
||||||
/// Creates a `MapOutEvent`.
|
/// Creates a `MapOutEvent`.
|
||||||
pub(crate) fn new(inner: TProtoHandler, map: TMap) -> Self {
|
pub(crate) fn new(inner: TConnectionHandler, map: TMap) -> Self {
|
||||||
MapOutEvent { inner, map }
|
MapOutEvent { inner, map }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TProtoHandler, TMap, TNewOut> ConnectionHandler for MapOutEvent<TProtoHandler, TMap>
|
impl<TConnectionHandler, TMap, TNewOut> ConnectionHandler for MapOutEvent<TConnectionHandler, TMap>
|
||||||
where
|
where
|
||||||
TProtoHandler: ConnectionHandler,
|
TConnectionHandler: ConnectionHandler,
|
||||||
TMap: FnMut(TProtoHandler::OutEvent) -> TNewOut,
|
TMap: FnMut(TConnectionHandler::OutEvent) -> TNewOut,
|
||||||
TNewOut: Debug + Send + 'static,
|
TNewOut: Debug + Send + 'static,
|
||||||
TMap: Send + 'static,
|
TMap: Send + 'static,
|
||||||
{
|
{
|
||||||
type InEvent = TProtoHandler::InEvent;
|
type InEvent = TConnectionHandler::InEvent;
|
||||||
type OutEvent = TNewOut;
|
type OutEvent = TNewOut;
|
||||||
type Error = TProtoHandler::Error;
|
type Error = TConnectionHandler::Error;
|
||||||
type InboundProtocol = TProtoHandler::InboundProtocol;
|
type InboundProtocol = TConnectionHandler::InboundProtocol;
|
||||||
type OutboundProtocol = TProtoHandler::OutboundProtocol;
|
type OutboundProtocol = TConnectionHandler::OutboundProtocol;
|
||||||
type InboundOpenInfo = TProtoHandler::InboundOpenInfo;
|
type InboundOpenInfo = TConnectionHandler::InboundOpenInfo;
|
||||||
type OutboundOpenInfo = TProtoHandler::OutboundOpenInfo;
|
type OutboundOpenInfo = TConnectionHandler::OutboundOpenInfo;
|
||||||
|
|
||||||
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
|
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
|
||||||
self.inner.listen_protocol()
|
self.inner.listen_protocol()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user