diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 5712a7bc7a0..01e8dc2834d 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,14 +1,7 @@ ## 0.17.0 - unreleased - ## 0.16.2 - - ## 0.16.1 - Export `RateLimiter` type. diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index fc822e78ce5..6fb0a834d2f 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -355,8 +355,8 @@ pub struct Handler { >, >, - /// Until when to keep the connection alive. - keep_alive: KeepAlive, + /// The point in time when this connection started idleing. + idle_at: Option, /// Future handling inbound reservation request. reservation_request_future: Option, @@ -411,13 +411,13 @@ impl Handler { config, queued_events: Default::default(), pending_error: Default::default(), + idle_at: None, reservation_request_future: Default::default(), circuit_accept_futures: Default::default(), circuit_deny_futures: Default::default(), alive_lend_out_substreams: Default::default(), circuits: Default::default(), active_reservation: Default::default(), - keep_alive: KeepAlive::Yes, pending_connect_requests: Default::default(), } } @@ -616,7 +616,12 @@ impl ConnectionHandler for Handler { } fn connection_keep_alive(&self) -> KeepAlive { - self.keep_alive + match self.idle_at { + Some(idle_at) if Instant::now().duration_since(idle_at) > Duration::from_secs(10) => { + KeepAlive::No + } + _ => KeepAlive::Yes, + } } fn poll( @@ -883,16 +888,11 @@ impl ConnectionHandler for Handler { && self.circuits.is_empty() && self.active_reservation.is_none() { - #[allow(deprecated)] - match self.keep_alive { - KeepAlive::Yes => { - self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10)); - } - KeepAlive::Until(_) => {} - KeepAlive::No => panic!("Handler never sets KeepAlive::No."), + if self.idle_at.is_none() { + self.idle_at = Some(Instant::now()); } } else { - self.keep_alive = KeepAlive::Yes; + self.idle_at = None; } Poll::Pending