mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 17:21: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.
|
||||
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
|
||||
/// other one together.
|
||||
#[inline]
|
||||
fn select<TProto2>(self, other: TProto2) -> IntoProtocolsHandlerSelect<Self, TProto2>
|
||||
where
|
||||
Self: Sized,
|
||||
@ -441,7 +443,6 @@ pub trait IntoProtocolsHandler {
|
||||
|
||||
/// Creates a builder that will allow creating a `NodeHandler` that handles this protocol
|
||||
/// exclusively.
|
||||
#[inline]
|
||||
fn into_node_handler_builder(self) -> NodeHandlerWrapperBuilder<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
@ -455,10 +456,13 @@ where T: ProtocolsHandler
|
||||
{
|
||||
type Handler = Self;
|
||||
|
||||
#[inline]
|
||||
fn into_handler(self, _: &PeerId) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
|
||||
self.listen_protocol().into_upgrade()
|
||||
}
|
||||
}
|
||||
|
||||
/// How long the connection should be kept alive.
|
||||
|
@ -82,6 +82,10 @@ where
|
||||
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.
|
||||
|
@ -442,9 +442,7 @@ where TBehaviour: NetworkBehaviour,
|
||||
pub fn build(mut self) -> Swarm<TTransport, TBehaviour> {
|
||||
let supported_protocols = self.behaviour
|
||||
.new_handler()
|
||||
.into_handler(&self.local_peer_id)
|
||||
.listen_protocol()
|
||||
.into_upgrade()
|
||||
.inbound_protocol()
|
||||
.protocol_info()
|
||||
.into_iter()
|
||||
.map(|info| info.protocol_name().to_vec())
|
||||
|
@ -161,6 +161,14 @@ where
|
||||
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.
|
||||
|
Reference in New Issue
Block a user