use constant durations (#8278)
* use constant durations * fix CI * address comments
This commit is contained in:
committed by
Tomasz Drwięga
parent
68a08df9c3
commit
9c9ddaccec
@@ -47,7 +47,7 @@ const PACKET_PONG: u8 = 2;
|
||||
const PACKET_FIND_NODE: u8 = 3;
|
||||
const PACKET_NEIGHBOURS: u8 = 4;
|
||||
|
||||
const PING_TIMEOUT_MS: u64 = 300;
|
||||
const PING_TIMEOUT: Duration = Duration::from_millis(300);
|
||||
const MAX_NODES_PING: usize = 32; // Max nodes to add/ping at once
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -513,7 +513,7 @@ impl Discovery {
|
||||
for bucket in &mut self.node_buckets {
|
||||
bucket.nodes.retain(|node| {
|
||||
if let Some(timeout) = node.timeout {
|
||||
if !force && now.duration_since(timeout) < Duration::from_millis(PING_TIMEOUT_MS) {
|
||||
if !force && now.duration_since(timeout) < PING_TIMEOUT {
|
||||
true
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -34,8 +34,8 @@ use node_table::NodeId;
|
||||
use snappy;
|
||||
|
||||
// Timeout must be less than (interval - 1).
|
||||
const PING_TIMEOUT_SEC: u64 = 60;
|
||||
const PING_INTERVAL_SEC: u64 = 120;
|
||||
const PING_TIMEOUT_SEC: Duration = Duration::from_secs(60);
|
||||
const PING_INTERVAL_SEC: Duration = Duration::from_secs(120);
|
||||
const MIN_PROTOCOL_VERSION: u32 = 4;
|
||||
const MIN_COMPRESSION_PROTOCOL_VERSION: u32 = 5;
|
||||
|
||||
@@ -298,12 +298,12 @@ impl Session {
|
||||
return true;
|
||||
}
|
||||
let timed_out = if let Some(pong) = self.pong_time {
|
||||
pong.duration_since(self.ping_time) > Duration::from_secs(PING_TIMEOUT_SEC)
|
||||
pong.duration_since(self.ping_time) > PING_TIMEOUT_SEC
|
||||
} else {
|
||||
self.ping_time.elapsed() > Duration::from_secs(PING_TIMEOUT_SEC)
|
||||
self.ping_time.elapsed() > PING_TIMEOUT_SEC
|
||||
};
|
||||
|
||||
if !timed_out && self.ping_time.elapsed() > Duration::from_secs(PING_INTERVAL_SEC) {
|
||||
if !timed_out && self.ping_time.elapsed() > PING_INTERVAL_SEC {
|
||||
if let Err(e) = self.send_ping(io) {
|
||||
debug!("Error sending ping message: {:?}", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user