diff options
| author | tv <tv@krebsco.de> | 2026-11-17 00:58:13 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-17 02:03:19 +0100 |
| commit | 283c6a131d0bbb8ea7b6ffe87da1a14d457fd63d (patch) | |
| tree | 85bca3b029b7d7f62c34b2085bee59c5be4fecfe /src/swarm/peer/members.rs | |
| parent | 983db446089bd35d34a273fc60aabd24b7d888eb (diff) | |
peer: a member's message before its handshake was taken asks for one
In a swarm holding a store, a node reads a peer's messages only by the party its
handshake named. One whose handshake it hasn't taken (its reply lost, say) was cut off
at its next message, as a non-member is, while the peer, which took ours, synced on, and
neither said HELLO again. Now such a message goes unread, and the node says HELLO to the
peer, as to any whose reply it waits for (`hello_again_now`): its reply names its party.
What a peer refused as a non-member sends next is known to be a non-member's, its party
kept, so that it asks for no HELLO. A simulation loses a's replies to b for a while.
Diffstat (limited to 'src/swarm/peer/members.rs')
| -rw-r--r-- | src/swarm/peer/members.rs | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/swarm/peer/members.rs b/src/swarm/peer/members.rs index ddbd4a7..3df7674 100644 --- a/src/swarm/peer/members.rs +++ b/src/swarm/peer/members.rs @@ -3,13 +3,30 @@ //! any other goes unanswered, and what we had with it ends, as with a banned node; and so //! does what we had with a member at its next message, once the store names it no more. //! While the node holds no store yet, joining, it can't tell, and takes everyone of its -//! swarm: its seeds, which take it only where its party lists it. +//! swarm: its seeds, which take it only where its party lists it. From a peer whose +//! handshake it hasn't taken (its reply was lost, say), it reads nothing, and says HELLO +//! to it, as to any peer whose reply it waits for: the party its reply names tells. +use tokio::time::Instant; use tracing::{debug, warn}; use crate::state::{AppState, HelloState, Standing}; use crate::transport::ParsedMessage; +/// A message from `peer`, whose handshake this node hasn't taken: where it knows the peer, +/// its HELLO goes now, the first, or again where it waits for a reply. +async fn handshake_first(state: &AppState, peer: &str) { + let Some(peer_state) = state.get_peer_state(peer).await else { + debug!(peer = %peer, "A message of a node it doesn't know, before any handshake: unread"); + return; + }; + debug!(peer = %peer, "A message before its handshake was taken: unread; saying HELLO"); + if peer_state.lock().await.hello_again_now(Instant::now()) { + state.peers_due.now(); + } + super::handshake::ensure_handshake(state, peer).await; +} + /// Whether `message` from `peer` is a member's, by the party its handshakes name, which a /// handshake records; where it isn't, what we had with it ends. pub(super) async fn member(state: &AppState, peer: &str, message: &ParsedMessage) -> bool { @@ -22,10 +39,17 @@ pub(super) async fn member(state: &AppState, peer: &str, message: &ParsedMessage Some(party) => party.clone(), // Holding no store, it can't tell. None if !state.holding.tells_members() => return true, - None => match state.get_peer_state(peer).await { - Some(peer_state) => peer_state.lock().await.party.clone(), - None => None, - }, + None => { + let known = match state.get_peer_state(peer).await { + Some(peer_state) => peer_state.lock().await.party.clone(), + None => None, + }; + if known.is_none() { + handshake_first(state, peer).await; + return false; + } + known + } }; // A member, or it can't tell yet: the party a handshake names is kept. if state.holding.member(peer, party.as_deref()) != Some(false) { @@ -41,6 +65,10 @@ pub(super) async fn member(state: &AppState, peer: &str, message: &ParsedMessage } if let Some(peer_state) = state.get_peer_state(peer).await { let mut peer_state = peer_state.lock().await; + // Kept, so that what it sends next is known to be a non-member's. + if named.is_some() { + peer_state.party = party.clone(); + } if peer_state.standing.is_admitted() { warn!(peer = %peer, party = party.as_deref(), "Not a member of the store, as it reads now: no longer synced with"); } |
