Skip to content

Commit

Permalink
feat(request-response): remove Config::set_connection_keep_alive
Browse files Browse the repository at this point in the history
This function has been deprecated and can now be removed.

Related: #3844.
Related: #4678.

Pull-Request: #4679.
  • Loading branch information
leonzchang committed Oct 20, 2023
1 parent 82d7713 commit 79f961f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 27 deletions.
4 changes: 2 additions & 2 deletions protocols/rendezvous/tests/rendezvous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ async fn registration_on_clients_expire() {
let roberts_peer_id = *robert.local_peer_id();
tokio::spawn(robert.loop_on_next());

let registration_ttl = 3;
let registration_ttl = 1;

alice
.behaviour_mut()
Expand All @@ -389,7 +389,7 @@ async fn registration_on_clients_expire() {
event => panic!("Unexpected event: {event:?}"),
}

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

let event = bob.select_next_some().await;
let error = bob.dial(*alice.local_peer_id()).unwrap_err();
Expand Down
2 changes: 2 additions & 0 deletions protocols/request-response/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 0.26.0 - unreleased

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

## 0.25.2

Expand Down
16 changes: 4 additions & 12 deletions protocols/request-response/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use crate::handler::protocol::{RequestProtocol, ResponseProtocol};
use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD};

use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered};
use instant::Instant;
use libp2p_swarm::handler::{
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
ListenUpgradeError,
Expand Down Expand Up @@ -57,9 +56,6 @@ where
inbound_protocols: SmallVec<[TCodec::Protocol; 2]>,
/// The request/response message codec.
codec: TCodec,
/// The keep-alive timeout of idle connections. A connection is considered
/// idle if there are no outbound substreams.
keep_alive_timeout: Duration,
/// The timeout for inbound and outbound substreams (i.e. request
/// and response processing).
substream_timeout: Duration,
Expand Down Expand Up @@ -92,15 +88,13 @@ where
pub(super) fn new(
inbound_protocols: SmallVec<[TCodec::Protocol; 2]>,
codec: TCodec,
keep_alive_timeout: Duration,
substream_timeout: Duration,
inbound_request_id: Arc<AtomicU64>,
) -> Self {
Self {
inbound_protocols,
codec,
keep_alive: KeepAlive::Yes,
keep_alive_timeout,
substream_timeout,
outbound: VecDeque::new(),
inbound: FuturesUnordered::new(),
Expand Down Expand Up @@ -336,13 +330,11 @@ where
self.outbound.shrink_to_fit();
}

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

Poll::Pending
Expand Down
13 changes: 0 additions & 13 deletions protocols/request-response/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,17 @@ impl fmt::Display for RequestId {
#[derive(Debug, Clone)]
pub struct Config {
request_timeout: Duration,
connection_keep_alive: Duration,
}

impl Default for Config {
fn default() -> Self {
Self {
connection_keep_alive: Duration::from_secs(10),
request_timeout: Duration::from_secs(10),
}
}
}

impl Config {
/// Sets the keep-alive timeout of idle connections.
#[deprecated(
note = "Set a global idle connection timeout via `SwarmBuilder::idle_connection_timeout` instead."
)]
pub fn set_connection_keep_alive(&mut self, v: Duration) -> &mut Self {
self.connection_keep_alive = v;
self
}

/// Sets the timeout for inbound and outbound requests.
pub fn set_request_timeout(&mut self, v: Duration) -> &mut Self {
self.request_timeout = v;
Expand Down Expand Up @@ -717,7 +706,6 @@ where
self.inbound_protocols.clone(),
self.codec.clone(),
self.config.request_timeout,
self.config.connection_keep_alive,
self.next_inbound_id.clone(),
);

Expand Down Expand Up @@ -760,7 +748,6 @@ where
self.inbound_protocols.clone(),
self.codec.clone(),
self.config.request_timeout,
self.config.connection_keep_alive,
self.next_inbound_id.clone(),
);

Expand Down

0 comments on commit 79f961f

Please sign in to comment.