mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-25 15:51:34 +00:00
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:
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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::*;
|
||||
|
@ -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 {}, ()),
|
||||
|
Reference in New Issue
Block a user