diff options
| author | tv <tv@krebsco.de> | 2026-12-01 13:19:32 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-01 13:19:32 +0000 |
| commit | 6d3dbcb129b67152c89bbbe2a7dad98b071bf838 (patch) | |
| tree | 8f92769b83f802950e0cc0b42be89653c74b2037 /src/transport | |
| parent | 82bb426dcd22268a960d35d7b8c947b864a6ddf5 (diff) | |
Two options for a node on a machine that should idle
--libp2p-ping-interval: how often libp2p pings each open connection,
15 s unless given, 0 for once as it opens. The pings keep no connection
open and close none; continuum takes each connection's round trip from
them, to keep the fastest of several to one peer.
--worker-threads: how many threads take the node's work in turns, as
many as the machine has cores unless given. The runtime is built from
the configuration, so the count is set as the node starts.
Each wakes the node's threads less often; docs/operations.md, An idle
node, says what to choose, and what was measured.
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/libp2p/behaviour.rs | 16 | ||||
| -rw-r--r-- | src/transport/libp2p/config.rs | 4 | ||||
| -rw-r--r-- | src/transport/libp2p/tests.rs | 3 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/transport/libp2p/behaviour.rs b/src/transport/libp2p/behaviour.rs index 0b9be6b..33155d0 100644 --- a/src/transport/libp2p/behaviour.rs +++ b/src/transport/libp2p/behaviour.rs @@ -187,6 +187,8 @@ pub(super) struct Features { pub(super) relay: bool, pub(super) mdns: bool, pub(super) upnp: bool, + /// How often an open connection is pinged, after the ping as it opens. + pub(super) ping_interval: Duration, pub(super) public: bool, /// How long a connection may idle (`idle_timeout`). pub(super) idle_timeout: Duration, @@ -198,12 +200,21 @@ impl Features { relay: config.relay, mdns: config.mdns, upnp: config.upnp, + // None: so long that none comes. A connection's first ping goes as it opens. + ping_interval: if config.ping_interval.is_zero() { + NO_PINGS + } else { + config.ping_interval + }, public: config.public, idle_timeout: idle_timeout(config.keepalive), } } } +/// The interval of pings that never come (`--libp2p-ping-interval 0`): ten years. +const NO_PINGS: Duration = Duration::from_secs(10 * 365 * 24 * 3600); + /// The IPFS DHT's protocol, and its bootstrap nodes (all at `IPFS_BOOTSTRAP_ADDRESS`). pub(super) const IPFS_DHT: StreamProtocol = StreamProtocol::new("/ipfs/kad/1.0.0"); @@ -230,6 +241,7 @@ impl Behaviour { relay, mdns, upnp, + ping_interval, public, idle_timeout: _, } = features; @@ -286,7 +298,9 @@ impl Behaviour { relay_client, relay: relay.into(), dcutr: HolePunching::new(peer_id, ignored), - ping: ::libp2p::ping::Behaviour::new(::libp2p::ping::Config::new()), + ping: ::libp2p::ping::Behaviour::new( + ::libp2p::ping::Config::new().with_interval(ping_interval), + ), autonat: ::libp2p::autonat::Behaviour::new( peer_id, ::libp2p::autonat::Config { diff --git a/src/transport/libp2p/config.rs b/src/transport/libp2p/config.rs index 712f2e2..70a8561 100644 --- a/src/transport/libp2p/config.rs +++ b/src/transport/libp2p/config.rs @@ -21,6 +21,9 @@ pub(crate) struct Libp2pConfig { pub(crate) mdns: bool, /// Ask the router to forward our listen ports (UPnP), and publish where. pub(crate) upnp: bool, + /// How often each open connection is pinged after the ping as it opens; zero for + /// never (`--libp2p-ping-interval`). + pub(crate) ping_interval: std::time::Duration, /// Address ranges neither published nor dialled, nor connected over (`Ignoring`). pub(crate) ignore: Vec<IpRange>, /// Address ranges that matter most, best first (`Book::preference`). @@ -136,6 +139,7 @@ impl Libp2pConfig { continuum: !relay_only, mdns: settings.libp2p_mdns, upnp: settings.libp2p_upnp, + ping_interval: settings.libp2p_ping_interval, ignore: parse_ranges("libp2p-ignore", &settings.libp2p_ignore)?, prefer: parse_ranges("libp2p-prefer", &settings.libp2p_prefer)?, internet_hosts: settings.libp2p_internet_hosts.clone(), diff --git a/src/transport/libp2p/tests.rs b/src/transport/libp2p/tests.rs index 93f251f..7c9f0f0 100644 --- a/src/transport/libp2p/tests.rs +++ b/src/transport/libp2p/tests.rs @@ -41,6 +41,7 @@ fn memory_node_with( continuum: true, mdns: false, upnp: false, + ping_interval: std::time::Duration::from_secs(15), ignore: Vec::new(), prefer: Vec::new(), internet_hosts: Vec::new(), @@ -231,6 +232,7 @@ async fn announced_addresses_are_published_instead() { continuum: true, mdns: false, upnp: false, + ping_interval: std::time::Duration::from_secs(15), ignore: Vec::new(), prefer: Vec::new(), internet_hosts: Vec::new(), @@ -473,6 +475,7 @@ async fn a_relay_that_is_no_node() { continuum: false, mdns: false, upnp: false, + ping_interval: std::time::Duration::from_secs(15), ignore: Vec::new(), prefer: Vec::new(), internet_hosts: Vec::new(), |
