From 194015e4e8e83f507af07a3d7dc849f8041912fb Mon Sep 17 00:00:00 2001 From: chirag-bgh Date: Fri, 24 Feb 2023 18:42:28 +0530 Subject: [PATCH 1/4] kad: remove allow_listening handler config --- protocols/kad/src/behaviour.rs | 2 -- protocols/kad/src/handler.rs | 14 +------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 9d3d9014538..b5ac5a48fdd 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -1993,7 +1993,6 @@ where Ok(KademliaHandler::new( KademliaHandlerConfig { protocol_config: self.protocol_config.clone(), - allow_listening: true, idle_timeout: self.connection_idle_timeout, }, ConnectedPoint::Listener { @@ -2014,7 +2013,6 @@ where Ok(KademliaHandler::new( KademliaHandlerConfig { protocol_config: self.protocol_config.clone(), - allow_listening: true, idle_timeout: self.connection_idle_timeout, }, ConnectedPoint::Dialer { diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 27938c1f477..69710155127 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -106,9 +106,6 @@ pub struct KademliaHandlerConfig { /// Configuration of the wire protocol. pub protocol_config: KademliaProtocolConfig, - /// If false, we deny incoming requests. - pub allow_listening: bool, - /// Time after which we close an idle connection. pub idle_timeout: Duration, } @@ -534,8 +531,6 @@ where ::InboundOpenInfo, >, ) { - // If `self.allow_listening` is false, then we produced a `DeniedUpgrade` and `protocol` - // is a `Void`. let protocol = match protocol { future::Either::Left(p) => p, future::Either::Right(p) => void::unreachable(p), @@ -572,7 +567,6 @@ where } } - debug_assert!(self.config.allow_listening); let connec_unique_id = self.next_connec_unique_id; self.next_connec_unique_id.0 += 1; self.inbound_substreams @@ -618,12 +612,7 @@ where type InboundOpenInfo = (); fn listen_protocol(&self) -> SubstreamProtocol { - if self.config.allow_listening { - SubstreamProtocol::new(self.config.protocol_config.clone(), ()) - .map_upgrade(Either::Left) - } else { - SubstreamProtocol::new(Either::Right(upgrade::DeniedUpgrade), ()) - } + SubstreamProtocol::new(self.config.protocol_config.clone(), ()).map_upgrade(Either::Left) } fn on_behaviour_event(&mut self, message: KademliaHandlerIn) { @@ -812,7 +801,6 @@ impl Default for KademliaHandlerConfig { fn default() -> Self { KademliaHandlerConfig { protocol_config: Default::default(), - allow_listening: true, idle_timeout: Duration::from_secs(10), } } From 2177d46122ce81dcfa008917371c74d06a7c0ba6 Mon Sep 17 00:00:00 2001 From: chirag-bgh Date: Sun, 26 Feb 2023 11:54:58 +0530 Subject: [PATCH 2/4] remove Either --- protocols/kad/src/handler.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 69710155127..4c903b55f49 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -605,14 +605,13 @@ where type InEvent = KademliaHandlerIn; type OutEvent = KademliaHandlerEvent; type Error = io::Error; // TODO: better error type? - type InboundProtocol = Either; type OutboundProtocol = KademliaProtocolConfig; // Message of the request to send to the remote, and user data if we expect an answer. type OutboundOpenInfo = (KadRequestMsg, Option); type InboundOpenInfo = (); fn listen_protocol(&self) -> SubstreamProtocol { - SubstreamProtocol::new(self.config.protocol_config.clone(), ()).map_upgrade(Either::Left) + SubstreamProtocol::new(self.config.protocol_config.clone(), ()) } fn on_behaviour_event(&mut self, message: KademliaHandlerIn) { From ab09e23a81fcbc7d3e90eface4a613504227ef9b Mon Sep 17 00:00:00 2001 From: chirag-bgh Date: Sun, 26 Feb 2023 15:01:00 +0530 Subject: [PATCH 3/4] fix --- protocols/kad/src/handler.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 4c903b55f49..dc627e82245 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -605,6 +605,7 @@ where type InEvent = KademliaHandlerIn; type OutEvent = KademliaHandlerEvent; type Error = io::Error; // TODO: better error type? + type InboundProtocol = KademliaProtocolConfig; type OutboundProtocol = KademliaProtocolConfig; // Message of the request to send to the remote, and user data if we expect an answer. type OutboundOpenInfo = (KadRequestMsg, Option); From eb0ec9983d43536e5d5337041cba56769f3d52fd Mon Sep 17 00:00:00 2001 From: chirag-bgh Date: Tue, 28 Feb 2023 14:49:11 +0530 Subject: [PATCH 4/4] fix --- protocols/kad/src/handler.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index dc627e82245..2067b381103 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -531,11 +531,6 @@ where ::InboundOpenInfo, >, ) { - let protocol = match protocol { - future::Either::Left(p) => p, - future::Either::Right(p) => void::unreachable(p), - }; - if let ProtocolStatus::Unconfirmed = self.protocol_status { // Upon the first successfully negotiated substream, we know that the // remote is configured with the same protocol name and we want