Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
21 changes: 2 additions & 19 deletions protocols/kad/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -534,13 +531,6 @@ where
<Self as ConnectionHandler>::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),
};

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
Expand Down Expand Up @@ -572,7 +562,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
Expand Down Expand Up @@ -611,19 +600,14 @@ where
type InEvent = KademliaHandlerIn<TUserData>;
type OutEvent = KademliaHandlerEvent<TUserData>;
type Error = io::Error; // TODO: better error type?
type InboundProtocol = Either<KademliaProtocolConfig, upgrade::DeniedUpgrade>;
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<TUserData>);
type InboundOpenInfo = ();

fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
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(), ())
}

fn on_behaviour_event(&mut self, message: KademliaHandlerIn<TUserData>) {
Expand Down Expand Up @@ -812,7 +796,6 @@ impl Default for KademliaHandlerConfig {
fn default() -> Self {
KademliaHandlerConfig {
protocol_config: Default::default(),
allow_listening: true,
idle_timeout: Duration::from_secs(10),
}
}
Expand Down