Description
Original discussion thread: #3844
We want an idle_connection_timeout config on the SwarmBuilder that triggers once a connection reports KeepAlive::No. The current logic is here:
|
let keep_alive = handler.connection_keep_alive(); |
|
match (&mut *shutdown, keep_alive) { |
|
(Shutdown::Later(timer, deadline), KeepAlive::Until(t)) => { |
|
if *deadline != t { |
|
*deadline = t; |
|
if let Some(dur) = deadline.checked_duration_since(Instant::now()) { |
|
timer.reset(dur) |
|
} |
|
} |
|
} |
|
(_, KeepAlive::Until(t)) => { |
|
if let Some(dur) = t.checked_duration_since(Instant::now()) { |
|
*shutdown = Shutdown::Later(Delay::new(dur), t) |
|
} |
|
} |
|
(_, KeepAlive::No) => *shutdown = Shutdown::Asap, |
|
(_, KeepAlive::Yes) => *shutdown = Shutdown::None, |
|
}; |
I think what we can do here is utilize the already existing Shutdown::Later variant and simply set it to the configured timeout in the KeepAlive::No branch.
By default, the timeout should be 0 seconds.
Motivation
Several usecases like tests, examples, benchmarks and more client-server style applications often want to keep connections alive even if there currently isn't any work happening on the connection.
This will unblock #4029. At the same time with introducing this feature, we should deprecate keep_alive::Behaviour and recommend users to simply set the new configuration option to:
u64::MAX if they want to keep the connection alive "forever"
- a value that makes sense in their context
For tests for example, we would probably be fine to set the value to something like 10 seconds. We can do that here: https://github.com/libp2p/rust-libp2p/blob/master/swarm-test/src/lib.rs#L221
As a result, we can likely remove the usage of keep_alive::Behaviour from several tests.
Are you planning to do it yourself in a pull request?
Maybe but would appreciate help.
Description
Original discussion thread: #3844
We want an
idle_connection_timeoutconfig on theSwarmBuilderthat triggers once a connection reportsKeepAlive::No. The current logic is here:rust-libp2p/swarm/src/connection.rs
Lines 339 to 356 in 524bfc2
I think what we can do here is utilize the already existing
Shutdown::Latervariant and simply set it to the configured timeout in theKeepAlive::Nobranch.By default, the timeout should be 0 seconds.
Motivation
Several usecases like tests, examples, benchmarks and more client-server style applications often want to keep connections alive even if there currently isn't any work happening on the connection.
This will unblock #4029. At the same time with introducing this feature, we should deprecate
keep_alive::Behaviourand recommend users to simply set the new configuration option to:u64::MAXif they want to keep the connection alive "forever"For tests for example, we would probably be fine to set the value to something like 10 seconds. We can do that here: https://github.com/libp2p/rust-libp2p/blob/master/swarm-test/src/lib.rs#L221
As a result, we can likely remove the usage of
keep_alive::Behaviourfrom several tests.Are you planning to do it yourself in a pull request?
Maybe but would appreciate help.