diff --git a/Cargo.lock b/Cargo.lock index 7cdb752531e..9663cae3cab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2932,7 +2932,7 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.47.0" +version = "0.47.1" dependencies = [ "asynchronous-codec", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 8ed318797f5..45bfbaad9d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,7 +85,7 @@ libp2p-floodsub = { version = "0.46.1", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.49.0", path = "protocols/gossipsub" } libp2p-identify = { version = "0.47.0", path = "protocols/identify" } libp2p-identity = { version = "0.2.11" } -libp2p-kad = { version = "0.47.0", path = "protocols/kad" } +libp2p-kad = { version = "0.47.1", path = "protocols/kad" } libp2p-mdns = { version = "0.47.0", path = "protocols/mdns" } libp2p-memory-connection-limits = { version = "0.4.0", path = "misc/memory-connection-limits" } libp2p-metrics = { version = "0.17.0", path = "misc/metrics" } diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 162f251e16b..5cb94686f39 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.47.1 + +- Configurable outbound_substreams_timeout. + See [PR 6015](https://github.com/libp2p/rust-libp2p/pull/6015). + ## 0.47.0 - Expose a kad query facility allowing specify num_results dynamically. @@ -15,7 +20,7 @@ - Remove deprecated default constructor for `ProtocolConfig`. See [PR 5774](https://github.com/libp2p/rust-libp2p/pull/5774). - Add lazy cleanup for expired provider records in `Behavior::get_providers` and `Behavior::provider_peers`. - See [PR 5980](https://github.com/libp2p/rust-libp2p/pull/5980) + See [PR 5980](https://github.com/libp2p/rust-libp2p/pull/5980). diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 0d235511242..d1bc65180e4 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-kad" edition.workspace = true rust-version = { workspace = true } description = "Kademlia protocol for libp2p" -version = "0.47.0" +version = "0.47.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 9acd829edc6..ec7272a3d85 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -382,6 +382,16 @@ impl Config { self } + /// Modifies the timeout duration of outbount_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); + self + } + /// Sets the k-bucket insertion strategy for the Kademlia routing table. pub fn set_kbucket_inserts(&mut self, inserts: BucketInserts) -> &mut Self { self.kbucket_inserts = inserts; diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 15253d6eae8..5edbd9b2df4 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -24,7 +24,6 @@ use std::{ marker::PhantomData, pin::Pin, task::{Context, Poll, Waker}, - time::Duration, }; use either::Either; @@ -454,6 +453,8 @@ impl Handler { } } + let outbound_substreams_timeout = protocol_config.outbound_substreams_timeout_s(); + Handler { protocol_config, mode, @@ -462,7 +463,7 @@ impl Handler { next_connec_unique_id: UniqueConnecId(0), inbound_substreams: Default::default(), outbound_substreams: futures_bounded::FuturesTupleSet::new( - Duration::from_secs(10), + outbound_substreams_timeout, MAX_NUM_STREAMS, ), pending_streams: Default::default(), diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 059b6ae6fd1..4be53dcd0e4 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -49,6 +49,8 @@ use crate::{ pub(crate) const DEFAULT_PROTO_NAME: StreamProtocol = StreamProtocol::new("/ipfs/kad/1.0.0"); /// 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); /// Status of our connection to a node reported by the Kademlia protocol. #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] pub enum ConnectionType { @@ -145,6 +147,8 @@ pub struct ProtocolConfig { protocol_names: Vec, /// Maximum allowed size of a packet. max_packet_size: usize, + /// Specifies the outbound_substreams timeout in seconds + outbound_substreams_timeout_s: Duration, } impl ProtocolConfig { @@ -153,6 +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, } } @@ -165,6 +170,16 @@ impl ProtocolConfig { pub fn set_max_packet_size(&mut self, size: usize) { 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; + } + + /// Getter of outbount_substreams_timeout_s. + pub fn outbound_substreams_timeout_s(&self) -> Duration { + self.outbound_substreams_timeout_s + } } impl UpgradeInfo for ProtocolConfig {