summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/state.rs b/src/state.rs
index ccc8253..33bc9b5 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -25,13 +25,32 @@ pub(crate) enum NodeLifecycle {
Ready { swarm_id: String },
}
+/// How far a peer got into the swarm, as far as we're concerned.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
-pub(crate) enum PeerMembership {
+pub(crate) enum Standing {
+ /// Nothing proven yet. With a swarm key, everything but a handshake from it is
+ /// ignored (`swarm::peer::admit`).
#[default]
- Unknown,
- Member {
- swarm_id: String,
- },
+ Stranger,
+ /// Proved the swarm key in a HELLO; no HELLO_REPLY yet. Only reached with a key.
+ Admitted,
+ /// Its HELLO_REPLY named our swarm (and, with a key, proved it): we sync with it.
+ Member { swarm_id: String },
+}
+
+impl Standing {
+ /// The swarm a member belongs to; None before its HELLO_REPLY.
+ pub(crate) fn swarm_id(&self) -> Option<&str> {
+ match self {
+ Self::Member { swarm_id } => Some(swarm_id),
+ Self::Stranger | Self::Admitted => None,
+ }
+ }
+
+ /// Proved the swarm key (meaningful only with one).
+ pub(crate) fn is_admitted(&self) -> bool {
+ !matches!(self, Self::Stranger)
+ }
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -67,7 +86,7 @@ pub(crate) struct PendingOutbound {
#[derive(Clone)]
pub(crate) struct PeerState {
- pub(crate) membership: PeerMembership,
+ pub(crate) standing: Standing,
pub(crate) sync_state: sync::State,
pub(crate) hello_state: HelloState,
@@ -102,10 +121,6 @@ pub(crate) struct PeerState {
/// Consecutive sync exchanges that changed nothing (livelock detection).
pub(crate) stalled_exchanges: u32,
- /// The peer proved the swarm key in its HELLO or HELLO_REPLY (always false and
- /// irrelevant without a swarm key).
- pub(crate) authenticated: bool,
-
/// The answer we expect to our last sync message(s), if any.
pub(crate) sync_reply: Option<SyncReplyWait>,
/// How long to wait for it; doubles while answers stay out.
@@ -144,7 +159,7 @@ const SYNC_OPENING_GRACE: Duration = Duration::from_secs(3);
impl Default for PeerState {
fn default() -> Self {
Self {
- membership: PeerMembership::default(),
+ standing: Standing::default(),
sync_state: sync::State::new(),
hello_state: HelloState::default(),
reply_owed: false,
@@ -158,7 +173,6 @@ impl Default for PeerState {
last_sync_rx: None,
last_resync_at: None,
stalled_exchanges: 0,
- authenticated: false,
sync_reply: None,
sync_reply_timeout: SYNC_REPLY_TIMEOUT,
sync_reset_at: Instant::now(),
@@ -668,7 +682,7 @@ impl AppState {
for (id, peer_state_mutex) in &peers {
let mut peer_state = peer_state_mutex.lock().await;
let syncs_with_us = peer_state.liveness == Liveness::Active
- && matches!(peer_state.membership, PeerMembership::Member { .. })
+ && matches!(peer_state.standing, Standing::Member { .. })
&& peer_state.epoch == Some(local);
peer_state.epoch_unannounced = syncs_with_us;
if !syncs_with_us {