swarm/: Make NodeHandlerWrapper an impl detail of connection (#2523)

Previously one would wrap a `ProtocolsHandler` into a
`NodeHandlerWrapper` as early as possible, even though the functionality
of `NodeHandlerWrapper` is only needed within `mod connection`.

This commit makes `NodeHandlerWrapper` an implementation detail of `mod
connection`, thus neither `mod protocols_handler`, `mod pool` nor the
root level (`libp2p-swarm`) need to bother about the abstraction.

In addition to the above, this commit:

- Renames `NodeHandlerWrapper` to `HandlerWrapper`. The word `Node` is
  outdated.
- Removes `NodeHandlerWrapperBuilder`. With this simplification it is no
  longer needed.
- Folds `NodeHandlerWrapperError` into `ConnectionError`. No need for
  upper layers to be aware of the fact that `ProtocolHandler`s are
  wrapped.
This commit is contained in:
Max Inden
2022-02-18 11:32:58 +01:00
committed by GitHub
parent eeb3504d5f
commit 2ff9acee22
7 changed files with 123 additions and 195 deletions

View File

@ -42,7 +42,6 @@ pub mod either;
mod map_in;
mod map_out;
pub mod multi;
mod node_handler;
mod one_shot;
mod select;
@ -55,10 +54,6 @@ use std::{cmp::Ordering, error, fmt, task::Context, task::Poll, time::Duration};
pub use dummy::DummyProtocolsHandler;
pub use map_in::MapInEvent;
pub use map_out::MapOutEvent;
pub use node_handler::{
NodeHandlerWrapper, NodeHandlerWrapperBuilder, NodeHandlerWrapperError,
NodeHandlerWrapperEvent, NodeHandlerWrapperOutboundOpenInfo,
};
pub use one_shot::{OneShotHandler, OneShotHandlerConfig};
pub use select::{IntoProtocolsHandlerSelect, ProtocolsHandlerSelect};
@ -222,17 +217,6 @@ pub trait ProtocolsHandler: Send + 'static {
{
ProtocolsHandlerSelect::new(self, other)
}
/// Creates a builder that allows creating a `NodeHandler` that handles this protocol
/// exclusively.
///
/// > **Note**: This method should not be redefined in a custom `ProtocolsHandler`.
fn into_node_handler_builder(self) -> NodeHandlerWrapperBuilder<Self>
where
Self: Sized,
{
IntoProtocolsHandler::into_node_handler_builder(self)
}
}
/// Configuration of inbound or outbound substream protocol(s)
@ -493,15 +477,6 @@ pub trait IntoProtocolsHandler: Send + 'static {
{
IntoProtocolsHandlerSelect::new(self, other)
}
/// Creates a builder that will allow creating a `NodeHandler` that handles this protocol
/// exclusively.
fn into_node_handler_builder(self) -> NodeHandlerWrapperBuilder<Self>
where
Self: Sized,
{
NodeHandlerWrapperBuilder::new(self)
}
}
impl<T> IntoProtocolsHandler for T