aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/peering/fullmesh.rs16
3 files changed, 16 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ca7e3ba..bd7248c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -428,7 +428,7 @@ dependencies = [
[[package]]
name = "netapp"
-version = "0.5.0"
+version = "0.5.2"
dependencies = [
"arc-swap",
"async-trait",
diff --git a/Cargo.toml b/Cargo.toml
index 65f6c6b..1a6e5ea 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "netapp"
-version = "0.5.1"
+version = "0.5.2"
authors = ["Alex Auvolat <alex@adnab.me>"]
edition = "2018"
license-file = "LICENSE"
diff --git a/src/peering/fullmesh.rs b/src/peering/fullmesh.rs
index fb2e3d1..859a94a 100644
--- a/src/peering/fullmesh.rs
+++ b/src/peering/fullmesh.rs
@@ -25,9 +25,10 @@ const CONN_RETRY_INTERVAL: Duration = Duration::from_secs(30);
const CONN_MAX_RETRIES: usize = 10;
const PING_INTERVAL: Duration = Duration::from_secs(15);
const LOOP_DELAY: Duration = Duration::from_secs(1);
-const PING_TIMEOUT: Duration = Duration::from_secs(10);
const FAILED_PING_THRESHOLD: usize = 4;
+const DEFAULT_PING_TIMEOUT_MILLIS: u64 = 10_000;
+
// -- Protocol messages --
#[derive(Serialize, Deserialize)]
@@ -184,6 +185,8 @@ pub struct FullMeshPeeringStrategy {
next_ping_id: AtomicU64,
ping_endpoint: Arc<Endpoint<PingMessage, Self>>,
peer_list_endpoint: Arc<Endpoint<PeerListMessage, Self>>,
+
+ ping_timeout_millis: AtomicU64,
}
impl FullMeshPeeringStrategy {
@@ -220,6 +223,7 @@ impl FullMeshPeeringStrategy {
next_ping_id: AtomicU64::new(42),
ping_endpoint: netapp.endpoint("__netapp/peering/fullmesh.rs/Ping".into()),
peer_list_endpoint: netapp.endpoint("__netapp/peering/fullmesh.rs/PeerList".into()),
+ ping_timeout_millis: DEFAULT_PING_TIMEOUT_MILLIS.into(),
});
strat.update_public_peer_list(&strat.known_hosts.read().unwrap());
@@ -331,6 +335,12 @@ impl FullMeshPeeringStrategy {
self.public_peer_list.load_full()
}
+ /// Set the timeout for ping messages, in milliseconds
+ pub fn set_ping_timeout_millis(&self, timeout: u64) {
+ self.ping_timeout_millis
+ .store(timeout, atomic::Ordering::Relaxed);
+ }
+
// -- internal stuff --
fn update_public_peer_list(&self, known_hosts: &KnownHosts) {
@@ -372,6 +382,8 @@ impl FullMeshPeeringStrategy {
let peer_list_hash = self.known_hosts.read().unwrap().hash;
let ping_id = self.next_ping_id.fetch_add(1u64, atomic::Ordering::Relaxed);
let ping_time = Instant::now();
+ let ping_timeout =
+ Duration::from_millis(self.ping_timeout_millis.load(atomic::Ordering::Relaxed));
let ping_msg = PingMessage {
id: ping_id,
peer_list_hash,
@@ -385,7 +397,7 @@ impl FullMeshPeeringStrategy {
);
let ping_response = select! {
r = self.ping_endpoint.call(&id, ping_msg, PRIO_HIGH) => r,
- _ = tokio::time::sleep(PING_TIMEOUT) => Err(Error::Message("Ping timeout".into())),
+ _ = tokio::time::sleep(ping_timeout) => Err(Error::Message("Ping timeout".into())),
};
match ping_response {