aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/peer/handshake.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/peer/handshake.rs')
-rw-r--r--src/swarm/peer/handshake.rs18
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");