use constant durations (#8278)

* use constant durations

* fix CI

* address comments
This commit is contained in:
Ryan Leung
2018-04-02 16:47:56 +08:00
committed by Tomasz Drwięga
parent 68a08df9c3
commit 9c9ddaccec
12 changed files with 88 additions and 84 deletions

View File

@@ -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 {

View File

@@ -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);
}