Skip to content

Commit 79f961f

Browse files
authored
feat(request-response): remove Config::set_connection_keep_alive
This function has been deprecated and can now be removed. Related: #3844. Related: #4678. Pull-Request: #4679.
1 parent 82d7713 commit 79f961f

File tree

4 files changed

+8
-27
lines changed

4 files changed

+8
-27
lines changed

protocols/rendezvous/tests/rendezvous.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ async fn registration_on_clients_expire() {
370370
let roberts_peer_id = *robert.local_peer_id();
371371
tokio::spawn(robert.loop_on_next());
372372

373-
let registration_ttl = 3;
373+
let registration_ttl = 1;
374374

375375
alice
376376
.behaviour_mut()
@@ -389,7 +389,7 @@ async fn registration_on_clients_expire() {
389389
event => panic!("Unexpected event: {event:?}"),
390390
}
391391

392-
tokio::time::sleep(Duration::from_secs(registration_ttl + 5)).await;
392+
tokio::time::sleep(Duration::from_secs(registration_ttl + 1)).await;
393393

394394
let event = bob.select_next_some().await;
395395
let error = bob.dial(*alice.local_peer_id()).unwrap_err();

protocols/request-response/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 0.26.0 - unreleased
22

3+
- Remove `request_response::Config::set_connection_keep_alive` in favor of `SwarmBuilder::idle_connection_timeout`.
4+
See [PR 4679](https://github.com/libp2p/rust-libp2p/pull/4679).
35

46
## 0.25.2
57

protocols/request-response/src/handler.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::handler::protocol::{RequestProtocol, ResponseProtocol};
2727
use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD};
2828

2929
use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered};
30-
use instant::Instant;
3130
use libp2p_swarm::handler::{
3231
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
3332
ListenUpgradeError,
@@ -57,9 +56,6 @@ where
5756
inbound_protocols: SmallVec<[TCodec::Protocol; 2]>,
5857
/// The request/response message codec.
5958
codec: TCodec,
60-
/// The keep-alive timeout of idle connections. A connection is considered
61-
/// idle if there are no outbound substreams.
62-
keep_alive_timeout: Duration,
6359
/// The timeout for inbound and outbound substreams (i.e. request
6460
/// and response processing).
6561
substream_timeout: Duration,
@@ -92,15 +88,13 @@ where
9288
pub(super) fn new(
9389
inbound_protocols: SmallVec<[TCodec::Protocol; 2]>,
9490
codec: TCodec,
95-
keep_alive_timeout: Duration,
9691
substream_timeout: Duration,
9792
inbound_request_id: Arc<AtomicU64>,
9893
) -> Self {
9994
Self {
10095
inbound_protocols,
10196
codec,
10297
keep_alive: KeepAlive::Yes,
103-
keep_alive_timeout,
10498
substream_timeout,
10599
outbound: VecDeque::new(),
106100
inbound: FuturesUnordered::new(),
@@ -336,13 +330,11 @@ where
336330
self.outbound.shrink_to_fit();
337331
}
338332

339-
#[allow(deprecated)]
340333
if self.inbound.is_empty() && self.keep_alive.is_yes() {
341-
// No new inbound or outbound requests. However, we may just have
342-
// started the latest inbound or outbound upgrade(s), so make sure
343-
// the keep-alive timeout is preceded by the substream timeout.
344-
let until = Instant::now() + self.substream_timeout + self.keep_alive_timeout;
345-
self.keep_alive = KeepAlive::Until(until);
334+
// No new inbound or outbound requests. We already check
335+
// there is no active streams exist in swarm connection,
336+
// so we can set keep-alive to no directly.
337+
self.keep_alive = KeepAlive::No;
346338
}
347339

348340
Poll::Pending

protocols/request-response/src/lib.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,28 +284,17 @@ impl fmt::Display for RequestId {
284284
#[derive(Debug, Clone)]
285285
pub struct Config {
286286
request_timeout: Duration,
287-
connection_keep_alive: Duration,
288287
}
289288

290289
impl Default for Config {
291290
fn default() -> Self {
292291
Self {
293-
connection_keep_alive: Duration::from_secs(10),
294292
request_timeout: Duration::from_secs(10),
295293
}
296294
}
297295
}
298296

299297
impl Config {
300-
/// Sets the keep-alive timeout of idle connections.
301-
#[deprecated(
302-
note = "Set a global idle connection timeout via `SwarmBuilder::idle_connection_timeout` instead."
303-
)]
304-
pub fn set_connection_keep_alive(&mut self, v: Duration) -> &mut Self {
305-
self.connection_keep_alive = v;
306-
self
307-
}
308-
309298
/// Sets the timeout for inbound and outbound requests.
310299
pub fn set_request_timeout(&mut self, v: Duration) -> &mut Self {
311300
self.request_timeout = v;
@@ -717,7 +706,6 @@ where
717706
self.inbound_protocols.clone(),
718707
self.codec.clone(),
719708
self.config.request_timeout,
720-
self.config.connection_keep_alive,
721709
self.next_inbound_id.clone(),
722710
);
723711

@@ -760,7 +748,6 @@ where
760748
self.inbound_protocols.clone(),
761749
self.codec.clone(),
762750
self.config.request_timeout,
763-
self.config.connection_keep_alive,
764751
self.next_inbound_id.clone(),
765752
);
766753

0 commit comments

Comments
 (0)