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

@ -347,6 +347,7 @@ where
// Ask the handler whether it wants the connection (and the handler itself)
// to be kept alive, which determines the planned shutdown, if any.
let keep_alive = handler.connection_keep_alive();
#[allow(deprecated)]
match (&mut *shutdown, keep_alive) {
(Shutdown::Later(timer, deadline), KeepAlive::Until(t)) => {
if *deadline != t {
@ -1005,6 +1006,7 @@ mod tests {
}
fn connection_keep_alive(&self) -> KeepAlive {
#[allow(deprecated)]
KeepAlive::Until(self.until)
}

View File

@ -728,6 +728,9 @@ where
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum KeepAlive {
/// If nothing new happens, the connection should be closed at the given `Instant`.
#[deprecated(
note = "Use `swarm::Config::with_idle_connection_timeout` instead. See <https://github.com/libp2p/rust-libp2p/issues/3844> for details."
)]
Until(Instant),
/// Keep the connection alive.
Yes,
@ -748,6 +751,7 @@ impl PartialOrd for KeepAlive {
}
}
#[allow(deprecated)]
impl Ord for KeepAlive {
fn cmp(&self, other: &KeepAlive) -> Ordering {
use self::KeepAlive::*;

View File

@ -176,6 +176,7 @@ where
} else {
self.dial_queue.shrink_to_fit();
#[allow(deprecated)]
if self.dial_negotiated == 0 && self.keep_alive.is_yes() {
self.keep_alive = KeepAlive::Until(Instant::now() + self.config.keep_alive_timeout);
}
@ -199,6 +200,7 @@ where
..
}) => {
// If we're shutting down the connection for inactivity, reset the timeout.
#[allow(deprecated)]
if !self.keep_alive.is_yes() {
self.keep_alive =
KeepAlive::Until(Instant::now() + self.config.keep_alive_timeout);
@ -258,6 +260,7 @@ mod tests {
use void::Void;
#[test]
#[allow(deprecated)]
fn do_not_keep_idle_connection_alive() {
let mut handler: OneShotHandler<_, DeniedUpgrade, Void> = OneShotHandler::new(
SubstreamProtocol::new(DeniedUpgrade {}, ()),