Skip to content

Commit 171b7af

Browse files
committed
feat(kad): configurable OUTBOUND_SUBSTREAMS_TIMEOUT
1 parent 85e5d0f commit 171b7af

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

protocols/kad/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
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`.
1818
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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::{
2323
error, fmt, io,
2424
marker::PhantomData,
2525
pin::Pin,
26+
sync::LazyLock,
2627
task::{Context, Poll, Waker},
2728
time::Duration,
2829
};
@@ -48,6 +49,16 @@ use crate::{
4849

4950
const MAX_NUM_STREAMS: usize = 32;
5051

52+
/// Specifies the outbound_substreams timeout.
53+
///
54+
/// Can be overridden by the `OUTBOUND_STREAMS_TIMEOUT` environment variable.
55+
static OUTBOUND_STREAMS_TIMEOUT: LazyLock<u64> = LazyLock::new(|| {
56+
std::env::var("OUTBOUND_STREAMS_TIMEOUT")
57+
.ok()
58+
.and_then(|s| s.parse().ok())
59+
.unwrap_or(10)
60+
});
61+
5162
/// Protocol handler that manages substreams for the Kademlia protocol
5263
/// on a single connection with a peer.
5364
///
@@ -462,7 +473,7 @@ impl Handler {
462473
next_connec_unique_id: UniqueConnecId(0),
463474
inbound_substreams: Default::default(),
464475
outbound_substreams: futures_bounded::FuturesTupleSet::new(
465-
Duration::from_secs(10),
476+
Duration::from_secs(*OUTBOUND_STREAMS_TIMEOUT),
466477
MAX_NUM_STREAMS,
467478
),
468479
pending_streams: Default::default(),

0 commit comments

Comments
 (0)