aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/simtest/hyparview.rs6
-rw-r--r--src/state/timing.rs23
-rw-r--r--src/swarm/hyparview.rs46
3 files changed, 39 insertions, 36 deletions
diff --git a/src/simtest/hyparview.rs b/src/simtest/hyparview.rs
index 8b95378..65d581c 100644
--- a/src/simtest/hyparview.rs
+++ b/src/simtest/hyparview.rs
@@ -144,7 +144,7 @@ async fn active_views_settle_and_heal() {
sim.wait_ready(&all, SOON).await;
// By node ID, as the views hold them (`ids` are the names on the simulated net).
let up: BTreeSet<String> = nodes.iter().map(|n| n.local_id().to_owned()).collect();
- // Up to a reaffirm round (`REAFFIRM_EVERY`, 60 s) past the last change of a view: a
+ // Up to a reaffirm round (`Timing::reaffirm_every`) past the last change of a view: a
// DISCONNECT lost on these lossy links leaves the link at one end until then.
wait_settled(
&nodes,
@@ -233,8 +233,8 @@ async fn a_swarm_switches_to_hyparview_at_runtime() {
.expect("recorded");
let up: BTreeSet<String> = nodes.iter().map(|n| n.local_id().to_owned()).collect();
// Longer than a start: a node that switched first asks others still on the member
- // list's graph, which ignore NEIGHBOUR; it gives up on them after 20 s, and asks
- // them again only a minute later (or they ask it, once switched).
+ // list's graph, which ignore NEIGHBOUR; it gives up on them after `Timing::ask_for`, and
+ // asks them again only after `Timing::refused_for` (or they ask it, once switched).
wait_settled(
&nodes,
&ids,
diff --git a/src/state/timing.rs b/src/state/timing.rs
index fed48e9..adb8cfe 100644
--- a/src/state/timing.rs
+++ b/src/state/timing.rs
@@ -44,6 +44,25 @@ pub(crate) struct Timing {
/// (`Transport::delivery_limit`): a peer silent for longer has nothing on the way to
/// us any more.
pub(crate) delivery_limit: Duration,
+ /// HyParView (`swarm::hyparview`): how long a member asked to be a neighbour has to
+ /// agree, the handshake before included. Twice the first sync reply timeout: over
+ /// Tor, a few round trips of up to 3 s.
+ pub(crate) ask_for: Duration,
+ /// HyParView: a member that refused, didn't answer, or left isn't asked again for this
+ /// long. A keepalive interval.
+ pub(crate) refused_for: Duration,
+ /// HyParView: a member one neighbour short asks this seldom (five keepalive
+ /// intervals): in a swarm whose members mostly have `k`, asking each in turn kept
+ /// NEIGHBOURs going in a quiet swarm (up to 300 in 20 s at 50 members). Two or more
+ /// short, it asks at once. A member with `k` takes it (it says it is one short), so one
+ /// ask is enough but where those asked have `k + 1`.
+ pub(crate) one_short_every: Duration,
+ /// HyParView: each neighbour is asked again this often whether it still is (NEIGHBOUR,
+ /// as a new ask would be), a keepalive interval: a NEIGHBOUR_REPLY or DISCONNECT lost
+ /// on a lossy link leaves a link in one end's view only, and nothing else would tell
+ /// that end: the other still answers it. A neighbour that has us agrees at once; one
+ /// that doesn't takes us if it has room, else refuses, and we drop it.
+ pub(crate) reaffirm_every: Duration,
}
impl Timing {
@@ -100,6 +119,10 @@ impl Timing {
sync_reply_timeout,
unreached_after: sync_reply_timeout * 2,
delivery_limit,
+ ask_for: sync_reply_timeout * 2,
+ refused_for: keepalive,
+ one_short_every: keepalive * 5,
+ reaffirm_every: keepalive,
}
}
diff --git a/src/swarm/hyparview.rs b/src/swarm/hyparview.rs
index 1f2bdc6..3bee7e8 100644
--- a/src/swarm/hyparview.rs
+++ b/src/swarm/hyparview.rs
@@ -10,12 +10,12 @@
//! even where that means dropping another (told so: DISCONNECT). One a neighbour short
//! says so, and a member with `k` takes it as its `k + 1`th, the most it keeps: else
//! a few members one short each, neighbours of each other, would ask only members with
-//! `k`, be refused, and stay an island (`ONE_SHORT_EVERY`). One left with none
+//! `k`, be refused, and stay an island (`Timing::one_short_every`). One left with none
//! (dropped so itself) while its asks are low ones has one of them, or another, made
//! high at once, even of a member that refused before. A neighbour that fails
//! (judged unreachable: unanswered HELLOs, dormant, not alive lately) leaves the active
//! view, and another is asked. Every neighbour is asked again now and then whether it
-//! still is (`REAFFIRM_EVERY`): the paper's links are TCP connections, whose ends know
+//! still is (`Timing::reaffirm_every`): the paper's links are TCP connections, whose ends know
//! when the other closed them; ours, without, could be left in one end's view.
//!
//! The paper's passive view comes from its own messages (JOIN, FORWARD_JOIN, SHUFFLE),
@@ -30,13 +30,12 @@
//!
//! A member being asked counts as a neighbour already: it gets HELLOs, and NEIGHBOUR
//! goes once the handshake is done (a swarm's members only take messages from peers
-//! that did one). Refused, or unanswered for `ASK_FOR`, it is not asked again for
-//! `REFUSED_FOR`, and stops counting.
+//! that did one). Refused, or unanswered for `Timing::ask_for`, it is not asked again for
+//! `Timing::refused_for`, and stops counting.
use std::collections::{BTreeMap, BTreeSet};
use std::sync::Mutex;
use std::sync::atomic::{AtomicU64, Ordering};
-use std::time::Duration;
use async_trait::async_trait;
use tokio::time::Instant;
@@ -47,26 +46,6 @@ use crate::state::{AppState, HelloState};
use crate::swarm::topology::{self, Inputs, Topology};
use crate::transport::{NeighbourAnswer, NeighbourRequest, ParsedMessage};
-/// How long a member asked to be a neighbour has to agree, the handshake before
-/// included: over Tor, a few round trips of up to 3 s.
-const ASK_FOR: Duration = Duration::from_secs(20);
-
-/// A member that refused, didn't answer, or left isn't asked again for this long.
-const REFUSED_FOR: Duration = Duration::from_secs(60);
-
-/// A member one neighbour short asks this seldom: in a swarm whose members mostly have
-/// `k`, asking each in turn kept NEIGHBOURs going in a quiet swarm (up to 300 in 20 s
-/// at 50 members). Two or more short, it asks at once. A member with `k` takes it (it
-/// says it is one short), so one ask is enough but where those asked have `k + 1`.
-const ONE_SHORT_EVERY: Duration = Duration::from_secs(300);
-
-/// Each neighbour is asked again this often whether it still is (NEIGHBOUR, as a new
-/// ask would be): a NEIGHBOUR_REPLY or DISCONNECT lost on a lossy link leaves a link in
-/// one end's view only, and nothing else would tell that end: the other still answers
-/// it. A neighbour that has us agrees at once; one that doesn't takes us if it has room,
-/// else refuses, and we drop it.
-const REAFFIRM_EVERY: Duration = Duration::from_secs(60);
-
/// A member asked to be a neighbour.
#[derive(Debug)]
struct Asking {
@@ -86,9 +65,9 @@ struct Views {
asking: BTreeMap<String, Asking>,
/// Refused, unanswered or left lately: since when.
refused: BTreeMap<String, Instant>,
- /// When we last asked while one neighbour short (`ONE_SHORT_EVERY`).
+ /// When we last asked while one neighbour short (`Timing::one_short_every`).
asked_one_short: Option<Instant>,
- /// When the neighbours were last asked whether they still are (`REAFFIRM_EVERY`).
+ /// When the neighbours were last asked whether they still are (`Timing::reaffirm_every`).
reaffirmed: Option<Instant>,
}
@@ -227,7 +206,8 @@ impl Topology for HyParView {
.asking
.iter()
.filter(|(member, asking)| {
- !reachable.contains(*member) || now.duration_since(asking.since) > ASK_FOR
+ !reachable.contains(*member)
+ || now.duration_since(asking.since) > state.timing.ask_for
})
.map(|(member, _)| member.clone())
.collect();
@@ -246,7 +226,7 @@ impl Topology for HyParView {
}
views
.refused
- .retain(|_, since| now.duration_since(*since) < REFUSED_FOR);
+ .retain(|_, since| now.duration_since(*since) < state.timing.refused_for);
// More than one beyond `k` (asks sent before others asked us came back
// agreed): the excess dropped, at random, and told.
if views.active.len() > inputs.k + 1 {
@@ -262,12 +242,12 @@ impl Topology for HyParView {
let missing = inputs
.k
.saturating_sub(views.active.len() + views.asking.len());
- // One short, with neighbours: not again before `ONE_SHORT_EVERY`.
+ // One short, with neighbours: not again before `Timing::one_short_every`.
let one_short = missing == 1 && !views.active.is_empty();
let waiting = one_short
&& views
.asked_one_short
- .is_some_and(|at| now.duration_since(at) < ONE_SHORT_EVERY);
+ .is_some_and(|at| now.duration_since(at) < state.timing.one_short_every);
if missing > 0 && !waiting {
if one_short {
views.asked_one_short = Some(now);
@@ -330,7 +310,7 @@ impl Topology for HyParView {
.collect();
if views
.reaffirmed
- .is_none_or(|at| now.duration_since(at) >= REAFFIRM_EVERY)
+ .is_none_or(|at| now.duration_since(at) >= state.timing.reaffirm_every)
{
views.reaffirmed = Some(now);
to_ask.extend(views.active.iter().map(|member| (member.clone(), false)));
@@ -444,7 +424,7 @@ impl Topology for HyParView {
{
let mut views = self.views.lock_or_recover();
// Not asked: a neighbour asked again whether it still is
- // (`REAFFIRM_EVERY`), dropped if it refused; or one we gave up on,
+ // (`Timing::reaffirm_every`), dropped if it refused; or one we gave up on,
// and told so (`maintain`), which undoes its agreeing.
if views.asking.remove(peer).is_none() {
if answer.agreed || !views.active.remove(peer) {