diff options
| author | tv <tv@krebsco.de> | 2026-11-30 17:39:23 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 17:39:23 +0000 |
| commit | 93defc68f9b99da921f4746e91e5cee9e6e3f1b9 (patch) | |
| tree | b38f06c630c044f2c608ca321b1b73517bae5ea6 /src/swarm/peer/handshake.rs | |
| parent | 6ca6a97f5f9864c971c979c2c1758071a88635d0 (diff) | |
swarm: a node says to each peer the kind that peer holds, of those it holds
A node holds one kind of document, or, to come, its store in both
(Holding::kinds, of_both). The kind a peer's handshakes say is kept with
the peer, where the node holds it too, and is what the node says to it
in turn; to a peer that said none yet, a node of more than one kind
says each in turn, HELLO by HELLO, until one is answered. A node of one
kind says and takes that one, as before.
Diffstat (limited to 'src/swarm/peer/handshake.rs')
| -rw-r--r-- | src/swarm/peer/handshake.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/swarm/peer/handshake.rs b/src/swarm/peer/handshake.rs index fc1bc86..fc0a31b 100644 --- a/src/swarm/peer/handshake.rs +++ b/src/swarm/peer/handshake.rs @@ -144,7 +144,7 @@ async fn transmit_hello(state: &AppState, peer: &str) -> Result<()> { .await .map(|root| root.0.to_vec()), party: party(state), - kind: state.kind().to_owned(), + kind: kind_to(state, peer).await.to_owned(), }), ) .await; @@ -180,6 +180,20 @@ async fn say_what_we_speak(state: &AppState, peer: &str) { } } +/// The kind of document this node says to `peer` it holds: the one the peer's +/// handshakes said, of those this node holds; where the peer said none yet, and this +/// node holds more than one, each in turn, HELLO by HELLO, until one is answered. +async fn kind_to(state: &AppState, peer: &str) -> &'static str { + let kinds = state.kinds(); + let Some(peer_state) = state.get_peer_state(peer).await else { + return kinds[0]; + }; + let peer_state = peer_state.lock().await; + peer_state + .kind + .unwrap_or(kinds[peer_state.hello_attempts as usize % kinds.len()]) +} + pub(super) async fn ensure_handshake(state: &AppState, peer: &str) { if let Err(error) = send_hello_once(state, peer).await { warn!(peer = %peer, error = %format!("{error:#}"), "HELLO failed; will retry"); @@ -255,7 +269,7 @@ pub(super) async fn send_hello_reply( .await .map(|root| root.0.to_vec()), party: party(state), - kind: state.kind().to_owned(), + kind: kind_to(state, peer).await.to_owned(), }; debug!(to = %peer, ready, "Sending HELLO_REPLY"); |
