aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/libp2p/behaviour.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/libp2p/behaviour.rs')
-rw-r--r--src/transport/libp2p/behaviour.rs16
1 files changed, 15 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 {