Skip to content

Commit 91f3eff

Browse files
committed
feat(kad): configurable outbound_substreams timeout
1 parent 85e5d0f commit 91f3eff

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

protocols/kad/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
- Remove deprecated default constructor for `ProtocolConfig`.
1616
See [PR 5774](https://github.com/libp2p/rust-libp2p/pull/5774).
1717
- Add lazy cleanup for expired provider records in `Behavior::get_providers` and `Behavior::provider_peers`.
18-
See [PR 5980](https://github.com/libp2p/rust-libp2p/pull/5980)
18+
See [PR 5980](https://github.com/libp2p/rust-libp2p/pull/5980).
19+
- Configurable outbound_substreams_timeout.
20+
See [PR 6015](https://github.com/libp2p/rust-libp2p/pull/6015)
1921

2022
<!-- Update to libp2p-core v0.43.0 -->
2123

protocols/kad/src/handler.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ impl Handler {
454454
}
455455
}
456456

457+
let outbound_substreams_timeout = Duration::from_secs(protocol_config.outbound_substreams_timeout_s());
458+
457459
Handler {
458460
protocol_config,
459461
mode,
@@ -462,7 +464,7 @@ impl Handler {
462464
next_connec_unique_id: UniqueConnecId(0),
463465
inbound_substreams: Default::default(),
464466
outbound_substreams: futures_bounded::FuturesTupleSet::new(
465-
Duration::from_secs(10),
467+
outbound_substreams_timeout,
466468
MAX_NUM_STREAMS,
467469
),
468470
pending_streams: Default::default(),

protocols/kad/src/protocol.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ use crate::{
4949
pub(crate) const DEFAULT_PROTO_NAME: StreamProtocol = StreamProtocol::new("/ipfs/kad/1.0.0");
5050
/// The default maximum size for a varint length-delimited packet.
5151
pub(crate) const DEFAULT_MAX_PACKET_SIZE: usize = 16 * 1024;
52+
/// The default timeout of outbound_substreams to be 10 (seconds).
53+
const DEFAULT_OUTBOUND_SUBSTREAMS_TIMEOUT_S: u64 = 10;
5254
/// Status of our connection to a node reported by the Kademlia protocol.
5355
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
5456
pub enum ConnectionType {
@@ -145,6 +147,8 @@ pub struct ProtocolConfig {
145147
protocol_names: Vec<StreamProtocol>,
146148
/// Maximum allowed size of a packet.
147149
max_packet_size: usize,
150+
/// Specifies the outbound_substreams timeout in seconds
151+
outbound_substreams_timeout_s: u64,
148152
}
149153

150154
impl ProtocolConfig {
@@ -153,6 +157,7 @@ impl ProtocolConfig {
153157
ProtocolConfig {
154158
protocol_names: vec![protocol_name],
155159
max_packet_size: DEFAULT_MAX_PACKET_SIZE,
160+
outbound_substreams_timeout_s: DEFAULT_OUTBOUND_SUBSTREAMS_TIMEOUT_S,
156161
}
157162
}
158163

@@ -165,6 +170,16 @@ impl ProtocolConfig {
165170
pub fn set_max_packet_size(&mut self, size: usize) {
166171
self.max_packet_size = size;
167172
}
173+
174+
/// Modifies outbount_substreams timeout.
175+
pub fn set_outbound_substreams_timeout(&mut self, value: u64) {
176+
self.outbound_substreams_timeout_s = value;
177+
}
178+
179+
/// Getter of outbount_substreams_timeout_s.
180+
pub fn outbound_substreams_timeout_s(&self) -> u64 {
181+
self.outbound_substreams_timeout_s
182+
}
168183
}
169184

170185
impl UpgradeInfo for ProtocolConfig {

0 commit comments

Comments
 (0)