aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/peer/members.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 20:48:03 +0000
committertv <tv@krebsco.de>2026-11-16 22:03:41 +0100
commit0e1238015e55854515a4cbc6b6ef757792e7d804 (patch)
treebc7c008dfdf36d78d1e80f10d03e13926690749e /src/swarm/peer/members.rs
parentc534b25dbd94dc41731f98e4c4b2a170fe02c347 (diff)
peer: in a swarm holding a store, its members only
A node of a swarm holding a store syncs with its members only (`docs/store.md`, Members): the nodes its store names, each with the party its handshakes name, as the store reads now. A handshake from any other goes unanswered, and what the node had with it ends, as with a banned node; so does what it had with a member at its next message, once the store names it no more (`swarm::peer::members`). The party a handshake names is kept with the peer. While a 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. A node says whether it is a member itself, as its store reads, when that changes.
Diffstat (limited to 'src/swarm/peer/members.rs')
-rw-r--r--src/swarm/peer/members.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/swarm/peer/members.rs b/src/swarm/peer/members.rs
new file mode 100644
index 0000000..ddbd4a7
--- /dev/null
+++ b/src/swarm/peer/members.rs
@@ -0,0 +1,56 @@
+//! In a swarm holding a store, a node syncs with members only (`docs/store.md`, Members):
+//! the nodes its store names, each with the party its handshakes name. A handshake from
+//! 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.
+
+use tracing::{debug, warn};
+
+use crate::state::{AppState, HelloState, Standing};
+use crate::transport::ParsedMessage;
+
+/// 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 {
+ let named = match message {
+ ParsedMessage::Hello(hello) => Some(hello.party.clone()),
+ ParsedMessage::HelloReply(reply) => Some(reply.party.clone()),
+ _ => None,
+ };
+ let party = match &named {
+ 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,
+ },
+ };
+ // 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) {
+ if named.is_some() {
+ state
+ .get_or_create_peer_state(peer)
+ .await
+ .lock()
+ .await
+ .party = party;
+ }
+ return true;
+ }
+ if let Some(peer_state) = state.get_peer_state(peer).await {
+ let mut peer_state = peer_state.lock().await;
+ 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");
+ }
+ crate::swarm::topology::change_peer(state, &mut peer_state, |p| {
+ p.standing = Standing::Stranger
+ });
+ peer_state.hello_state = HelloState::NotSent;
+ peer_state.reset_sync();
+ } else {
+ debug!(peer = %peer, party = party.as_deref(), "A handshake of a node the store doesn't name: unanswered");
+ }
+ false
+}