feat(swarm): deprecate KeepAlive::Until

In preparation for removing this variant, we are issuing a deprecation notice. The linked issue describes why and guides users in migrating away from it. This deprecation is backwards-compatible and allows us to remove the variant in the next breaking release. We haven't migrated all internal protocols yet but that isn't strictly necessary to issue the deprecation.

Related: #3844.

Pull-Request: #4656.
This commit is contained in:
Thomas Eizinger
2023-10-17 03:32:09 +11:00
committed by GitHub
parent e54580525d
commit 7c6f75eaf2
17 changed files with 76 additions and 24 deletions

View File

@@ -5,6 +5,12 @@
[PR 4648]: (https://github.com/libp2p/rust-libp2p/pull/4648)
<!-- Internal changes
- Allow deprecated usage of `KeepAlive::Until`
-->
## 0.45.1
- Add getter function to obtain `TopicScoreParams`.

View File

@@ -444,6 +444,7 @@ impl ConnectionHandler for Handler {
return KeepAlive::Yes;
}
#[allow(deprecated)]
KeepAlive::Until(handler.last_io_activity + handler.idle_timeout)
}
Handler::Disabled(_) => KeepAlive::No,

View File

@@ -8,6 +8,12 @@
[PR 4547]: https://github.com/libp2p/rust-libp2p/pull/4547
<!-- Internal changes
- Allow deprecated usage of `KeepAlive::Until`
-->
## 0.44.5
- Migrate to `quick-protobuf-codec` crate for codec logic.
See [PR 4501].

View File

@@ -484,6 +484,7 @@ impl Handler {
}
}
#[allow(deprecated)]
let keep_alive = KeepAlive::Until(Instant::now() + idle_timeout);
Handler {
@@ -769,13 +770,17 @@ impl ConnectionHandler for Handler {
}
let no_streams = self.outbound_substreams.is_empty() && self.inbound_substreams.is_empty();
self.keep_alive = match (no_streams, self.keep_alive) {
// No open streams. Preserve the existing idle timeout.
(true, k @ KeepAlive::Until(_)) => k,
// No open streams. Set idle timeout.
(true, _) => KeepAlive::Until(Instant::now() + self.idle_timeout),
// Keep alive for open streams.
(false, _) => KeepAlive::Yes,
self.keep_alive = {
#[allow(deprecated)]
match (no_streams, self.keep_alive) {
// No open streams. Preserve the existing idle timeout.
(true, k @ KeepAlive::Until(_)) => k,
// No open streams. Set idle timeout.
(true, _) => KeepAlive::Until(Instant::now() + self.idle_timeout),
// Keep alive for open streams.
(false, _) => KeepAlive::Yes,
}
};
Poll::Pending

View File

@@ -1,3 +1,11 @@
## 0.16.2 - unreleased
<!-- Internal changes
- Allow deprecated usage of `KeepAlive::Until`
-->
## 0.16.1
- Export `RateLimiter` type.

View File

@@ -3,7 +3,7 @@ name = "libp2p-relay"
edition = "2021"
rust-version = { workspace = true }
description = "Communications relaying for libp2p"
version = "0.16.1"
version = "0.16.2"
authors = ["Parity Technologies <admin@parity.io>", "Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@@ -883,6 +883,7 @@ 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));

View File

@@ -489,21 +489,24 @@ impl ConnectionHandler for Handler {
}
// Update keep-alive handling.
if matches!(self.reservation, Reservation::None)
&& self.alive_lend_out_substreams.is_empty()
&& self.circuit_deny_futs.is_empty()
#[allow(deprecated)]
{
match self.keep_alive {
KeepAlive::Yes => {
self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10));
if matches!(self.reservation, Reservation::None)
&& self.alive_lend_out_substreams.is_empty()
&& self.circuit_deny_futs.is_empty()
{
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."),
}
KeepAlive::Until(_) => {}
KeepAlive::No => panic!("Handler never sets KeepAlive::No."),
} else {
self.keep_alive = KeepAlive::Yes;
}
} else {
self.keep_alive = KeepAlive::Yes;
}
Poll::Pending
}

View File

@@ -1,3 +1,11 @@
## 0.25.2 - unreleased
<!-- Internal changes
- Allow deprecated usage of `KeepAlive::Until`
-->
## 0.25.1
- Replace unmaintained `serde_cbor` dependency with `cbor4ii`.

View File

@@ -3,7 +3,7 @@ name = "libp2p-request-response"
edition = "2021"
rust-version = { workspace = true }
description = "Generic Request/Response Protocols"
version = "0.25.1"
version = "0.25.2"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@@ -336,6 +336,7 @@ 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