Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(relay): remove KeepAlive::Until #4676

Merged
merged 8 commits into from
Oct 20, 2023
Merged
7 changes: 0 additions & 7 deletions protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
## 0.17.0 - unreleased


## 0.16.2

<!-- Internal changes

- Allow deprecated usage of `KeepAlive::Until`

-->

## 0.16.1

- Export `RateLimiter` type.
Expand Down
24 changes: 12 additions & 12 deletions protocols/relay/src/behaviour/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instant>,

/// Future handling inbound reservation request.
reservation_request_future: Option<ReservationRequestFuture>,
Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down