From 2efb598bc31f2f6e11c5c0ebcc8e081eb10bc180 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Wed, 25 Jun 2025 22:59:26 +0200 Subject: [PATCH 1/3] chore(kad): rename substreams_timeout --- protocols/kad/CHANGELOG.md | 2 +- protocols/kad/src/behaviour.rs | 7 +++---- protocols/kad/src/handler.rs | 4 ++-- protocols/kad/src/protocol.rs | 18 +++++++++--------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 5cb94686f39..2702522c8dd 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.47.1 -- Configurable outbound_substreams_timeout. +- Configurable substreams_timeout. See [PR 6015](https://github.com/libp2p/rust-libp2p/pull/6015). ## 0.47.0 diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index f1c970024ac..5a48d30bca9 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -382,13 +382,12 @@ impl Config { self } - /// Modifies the timeout duration of outbount_substreams. + /// Modifies the timeout duration of outbound substreams. /// /// * Default to `10` seconds. /// * May need to increase this value when sending large records with poor connection. - pub fn set_outbound_substreams_timeout(&mut self, timeout: Duration) -> &mut Self { - self.protocol_config - .set_outbound_substreams_timeout(timeout); + pub fn set_substreams_timeout(&mut self, timeout: Duration) -> &mut Self { + self.protocol_config.set_substreams_timeout(timeout); self } diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 7e3a67098ce..2c7b6c52257 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -453,7 +453,7 @@ impl Handler { } } - let outbound_substreams_timeout = protocol_config.outbound_substreams_timeout_s(); + let substreams_timeout = protocol_config.substreams_timeout_s(); Handler { protocol_config, @@ -463,7 +463,7 @@ impl Handler { next_connec_unique_id: UniqueConnecId(0), inbound_substreams: Default::default(), outbound_substreams: futures_bounded::FuturesTupleSet::new( - outbound_substreams_timeout, + substreams_timeout, MAX_NUM_STREAMS, ), pending_streams: Default::default(), diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 4be53dcd0e4..df181af1a86 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -50,7 +50,7 @@ pub(crate) const DEFAULT_PROTO_NAME: StreamProtocol = StreamProtocol::new("/ipfs /// The default maximum size for a varint length-delimited packet. pub(crate) const DEFAULT_MAX_PACKET_SIZE: usize = 16 * 1024; /// The default timeout of outbound_substreams to be 10 (seconds). -const DEFAULT_OUTBOUND_SUBSTREAMS_TIMEOUT_S: Duration = Duration::from_secs(10); +const DEFAULT_SUBSTREAMS_TIMEOUT_S: Duration = Duration::from_secs(10); /// Status of our connection to a node reported by the Kademlia protocol. #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] pub enum ConnectionType { @@ -148,7 +148,7 @@ pub struct ProtocolConfig { /// Maximum allowed size of a packet. max_packet_size: usize, /// Specifies the outbound_substreams timeout in seconds - outbound_substreams_timeout_s: Duration, + substreams_timeout_s: Duration, } impl ProtocolConfig { @@ -157,7 +157,7 @@ impl ProtocolConfig { ProtocolConfig { protocol_names: vec![protocol_name], max_packet_size: DEFAULT_MAX_PACKET_SIZE, - outbound_substreams_timeout_s: DEFAULT_OUTBOUND_SUBSTREAMS_TIMEOUT_S, + substreams_timeout_s: DEFAULT_SUBSTREAMS_TIMEOUT_S, } } @@ -171,14 +171,14 @@ impl ProtocolConfig { self.max_packet_size = size; } - /// Modifies outbount_substreams timeout. - pub fn set_outbound_substreams_timeout(&mut self, timeout: Duration) { - self.outbound_substreams_timeout_s = timeout; + /// Modifies the outbound substreams timeout. + pub fn set_substreams_timeout(&mut self, timeout: Duration) { + self.substreams_timeout_s = timeout; } - /// Getter of outbount_substreams_timeout_s. - pub fn outbound_substreams_timeout_s(&self) -> Duration { - self.outbound_substreams_timeout_s + /// Getter of substreams_timeout_s. + pub fn substreams_timeout_s(&self) -> Duration { + self.substreams_timeout_s } } From 0746e37aa9311542e856a807e725e5828b7c2f51 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Thu, 26 Jun 2025 13:06:40 +0200 Subject: [PATCH 2/3] update changelog per review --- protocols/kad/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 2702522c8dd..ecaeaa64b84 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.47.1 -- Configurable substreams_timeout. +- Configurable substreams_timeout for outbound substreams. See [PR 6015](https://github.com/libp2p/rust-libp2p/pull/6015). ## 0.47.0 From 2dcb544ba376bc55bc517dd95d661550ca5746fb Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Thu, 26 Jun 2025 14:14:23 +0200 Subject: [PATCH 3/3] update changelog --- protocols/kad/CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index ecaeaa64b84..b9ba8b31d19 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,8 +1,9 @@ ## 0.47.1 -- Configurable substreams_timeout for outbound substreams. +- Configurable outbound_substreams_timeout. See [PR 6015](https://github.com/libp2p/rust-libp2p/pull/6015). - +- Rename `outbound_substreams_timeout` to `substreams_timeout` for future-proofness. + See [PR 6076](https://github.com/libp2p/rust-libp2p/pull/6076). ## 0.47.0 - Expose a kad query facility allowing specify num_results dynamically.