diff --git a/core/src/protocols_handler/mod.rs b/core/src/protocols_handler/mod.rs index a3137df7..6d47bc04 100644 --- a/core/src/protocols_handler/mod.rs +++ b/core/src/protocols_handler/mod.rs @@ -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) -> ::InboundProtocol; + /// Builds an implementation of `IntoProtocolsHandler` that handles both this protocol and the /// other one together. - #[inline] fn select(self, other: TProto2) -> IntoProtocolsHandlerSelect 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 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) -> ::InboundProtocol { + self.listen_protocol().into_upgrade() + } } /// How long the connection should be kept alive. diff --git a/core/src/protocols_handler/select.rs b/core/src/protocols_handler/select.rs index a88f9081..b902034b 100644 --- a/core/src/protocols_handler/select.rs +++ b/core/src/protocols_handler/select.rs @@ -82,6 +82,10 @@ where proto2: self.proto2.into_handler(remote_peer_id), } } + + fn inbound_protocol(&self) -> ::InboundProtocol { + SelectUpgrade::new(self.proto1.inbound_protocol(), self.proto2.inbound_protocol()) + } } /// Implementation of `ProtocolsHandler` that combines two protocols into one. diff --git a/core/src/swarm/swarm.rs b/core/src/swarm/swarm.rs index b157ade0..b35eebaf 100644 --- a/core/src/swarm/swarm.rs +++ b/core/src/swarm/swarm.rs @@ -442,9 +442,7 @@ where TBehaviour: NetworkBehaviour, pub fn build(mut self) -> Swarm { 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()) diff --git a/core/src/swarm/toggle.rs b/core/src/swarm/toggle.rs index 901d6c74..be905597 100644 --- a/core/src/swarm/toggle.rs +++ b/core/src/swarm/toggle.rs @@ -161,6 +161,14 @@ where inner: self.inner.map(|h| h.into_handler(remote_peer_id)) } } + + fn inbound_protocol(&self) -> ::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.