Be more lenient on pings

This commit is contained in:
Alex 2022-08-31 16:25:36 +02:00
parent 984ba65e65
commit 7703659742
Signed by untrusted user: lx
GPG key ID: 0E496D15096376BE

View file

@ -22,10 +22,10 @@ use crate::NodeID;
const CONN_RETRY_INTERVAL: Duration = Duration::from_secs(30); const CONN_RETRY_INTERVAL: Duration = Duration::from_secs(30);
const CONN_MAX_RETRIES: usize = 10; const CONN_MAX_RETRIES: usize = 10;
const PING_INTERVAL: Duration = Duration::from_secs(10); const PING_INTERVAL: Duration = Duration::from_secs(15);
const LOOP_DELAY: Duration = Duration::from_secs(1); const LOOP_DELAY: Duration = Duration::from_secs(1);
const PING_TIMEOUT: Duration = Duration::from_secs(5); const PING_TIMEOUT: Duration = Duration::from_secs(10);
const FAILED_PING_THRESHOLD: usize = 3; const FAILED_PING_THRESHOLD: usize = 4;
// -- Protocol messages -- // -- Protocol messages --
@ -255,15 +255,11 @@ impl FullMeshPeeringStrategy {
trace!("{}, {:?}", hex::encode(&id[..8]), info); trace!("{}, {:?}", hex::encode(&id[..8]), info);
match info.state { match info.state {
PeerConnState::Connected => { PeerConnState::Connected => {
let must_ping = match info.last_seen { let must_ping = match info.last_send_ping {
None => true, None => true,
Some(t) => Instant::now() - t > PING_INTERVAL, Some(t) => Instant::now() - t > PING_INTERVAL,
}; };
let pinged_recently = match info.last_send_ping { if must_ping {
None => false,
Some(t) => Instant::now() - t < PING_TIMEOUT,
};
if must_ping && !pinged_recently {
to_ping.push(*id); to_ping.push(*id);
} }
} }