diff options
| author | tv <tv@krebsco.de> | 2026-11-01 20:59:18 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 20:59:18 +0100 |
| commit | 83b2f9efbbcedea3297fea6754ea4a0e7ac6b3e0 (patch) | |
| tree | b8dad406e79a23f8bf9ada3cdfb7da345c2ccba6 /src/transport/libp2p/mod.rs | |
| parent | 151d0a71ac8aef450c90c243966fb64aa63a63c7 (diff) | |
libp2p: idle timeout follows keepalive
Diffstat (limited to 'src/transport/libp2p/mod.rs')
| -rw-r--r-- | src/transport/libp2p/mod.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/transport/libp2p/mod.rs b/src/transport/libp2p/mod.rs index a159280..3ebe7f6 100644 --- a/src/transport/libp2p/mod.rs +++ b/src/transport/libp2p/mod.rs @@ -128,8 +128,16 @@ const SLOW_SEND: Duration = Duration::from_millis(5); const MAX_MESSAGE: usize = 128 << 20; /// How long a connection may take to come up. const CONNECT_TIMEOUT: Duration = Duration::from_secs(10); -/// A connection nobody uses is closed after this; neighbours keep theirs busy. +/// A connection nobody uses is closed after this at least; neighbours keep theirs busy, +/// with a keepalive within one and a half intervals (`PeerState::take_keepalive_due`), +/// so a long interval lengthens it (`idle_timeout`). const IDLE_TIMEOUT: Duration = Duration::from_secs(300); + +/// How long a connection may idle before it is closed: `IDLE_TIMEOUT`, or three +/// keepalive intervals if that is longer. +fn idle_timeout(keepalive: Duration) -> Duration { + IDLE_TIMEOUT.max(keepalive * 3) +} /// Addresses of one dial tried at once (libp2p's default: 8). Hole punching (`HolePunching`) /// dials every address both sides offer, where they listen (LAN, VPNs, public IPv6) and /// where others saw them, often more than 8, while the other side punches towards all of |
