mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 09:41:34 +00:00
Add IntoProtocolsHandler::inbound_protocol
. (#1099)
This commit is contained in:
committed by
Pierre Krieger
parent
61b236172b
commit
fd0e48bf37
@ -429,9 +429,11 @@ pub trait IntoProtocolsHandler {
|
|||||||
/// The `PeerId` is the id of the node the handler is going to handle.
|
/// The `PeerId` is the id of the node the handler is going to handle.
|
||||||
fn into_handler(self, remote_peer_id: &PeerId) -> Self::Handler;
|
fn into_handler(self, remote_peer_id: &PeerId) -> Self::Handler;
|
||||||
|
|
||||||
|
/// Return the handler's inbound protocol.
|
||||||
|
fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol;
|
||||||
|
|
||||||
/// Builds an implementation of `IntoProtocolsHandler` that handles both this protocol and the
|
/// Builds an implementation of `IntoProtocolsHandler` that handles both this protocol and the
|
||||||
/// other one together.
|
/// other one together.
|
||||||
#[inline]
|
|
||||||
fn select<TProto2>(self, other: TProto2) -> IntoProtocolsHandlerSelect<Self, TProto2>
|
fn select<TProto2>(self, other: TProto2) -> IntoProtocolsHandlerSelect<Self, TProto2>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
@ -441,7 +443,6 @@ pub trait IntoProtocolsHandler {
|
|||||||
|
|
||||||
/// Creates a builder that will allow creating a `NodeHandler` that handles this protocol
|
/// Creates a builder that will allow creating a `NodeHandler` that handles this protocol
|
||||||
/// exclusively.
|
/// exclusively.
|
||||||
#[inline]
|
|
||||||
fn into_node_handler_builder(self) -> NodeHandlerWrapperBuilder<Self>
|
fn into_node_handler_builder(self) -> NodeHandlerWrapperBuilder<Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
@ -455,10 +456,13 @@ where T: ProtocolsHandler
|
|||||||
{
|
{
|
||||||
type Handler = Self;
|
type Handler = Self;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn into_handler(self, _: &PeerId) -> Self {
|
fn into_handler(self, _: &PeerId) -> Self {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
|
||||||
|
self.listen_protocol().into_upgrade()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How long the connection should be kept alive.
|
/// How long the connection should be kept alive.
|
||||||
|
@ -82,6 +82,10 @@ where
|
|||||||
proto2: self.proto2.into_handler(remote_peer_id),
|
proto2: self.proto2.into_handler(remote_peer_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
|
||||||
|
SelectUpgrade::new(self.proto1.inbound_protocol(), self.proto2.inbound_protocol())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of `ProtocolsHandler` that combines two protocols into one.
|
/// Implementation of `ProtocolsHandler` that combines two protocols into one.
|
||||||
|
@ -442,9 +442,7 @@ where TBehaviour: NetworkBehaviour,
|
|||||||
pub fn build(mut self) -> Swarm<TTransport, TBehaviour> {
|
pub fn build(mut self) -> Swarm<TTransport, TBehaviour> {
|
||||||
let supported_protocols = self.behaviour
|
let supported_protocols = self.behaviour
|
||||||
.new_handler()
|
.new_handler()
|
||||||
.into_handler(&self.local_peer_id)
|
.inbound_protocol()
|
||||||
.listen_protocol()
|
|
||||||
.into_upgrade()
|
|
||||||
.protocol_info()
|
.protocol_info()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|info| info.protocol_name().to_vec())
|
.map(|info| info.protocol_name().to_vec())
|
||||||
|
@ -161,6 +161,14 @@ where
|
|||||||
inner: self.inner.map(|h| h.into_handler(remote_peer_id))
|
inner: self.inner.map(|h| h.into_handler(remote_peer_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
|
||||||
|
if let Some(inner) = self.inner.as_ref() {
|
||||||
|
EitherUpgrade::A(inner.inbound_protocol())
|
||||||
|
} else {
|
||||||
|
EitherUpgrade::B(DeniedUpgrade)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of `ProtocolsHandler` that can be in the disabled state.
|
/// Implementation of `ProtocolsHandler` that can be in the disabled state.
|
||||||
|
Reference in New Issue
Block a user