From 83b2f9efbbcedea3297fea6754ea4a0e7ac6b3e0 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 20:59:18 +0100 Subject: libp2p: idle timeout follows keepalive --- src/transport/libp2p/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/transport/libp2p/mod.rs') 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 -- cgit v1.3.1