aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/libp2p/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-01 20:59:18 +0100
committertv <tv@krebsco.de>2026-11-01 20:59:18 +0100
commit9626255663820b708800fffa91c5f38c33d3cf09 (patch)
tree092336879981ea3d170028ae80af34ac5a318550 /src/transport/libp2p/mod.rs
parentbf88eb98173758691b3e8cea65a6ab8a90d5ca65 (diff)
libp2p: idle timeout follows keepalive
Diffstat (limited to 'src/transport/libp2p/mod.rs')
-rw-r--r--src/transport/libp2p/mod.rs10
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