diff options
| author | tv <tv@krebsco.de> | 2026-10-26 05:54:53 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-26 05:54:53 +0100 |
| commit | 13abdec6dd79529143acefeaf9f8f4ac394c2db5 (patch) | |
| tree | 895419552afd3323636d334a6684d8423361e7ad /src/swarm/peer/inbound.rs | |
| parent | 355f6db0b15e623a18626ac90c8baed10f23bef5 (diff) | |
number handshakes
This prevents late hellos from resetting the session.
Diffstat (limited to 'src/swarm/peer/inbound.rs')
| -rw-r--r-- | src/swarm/peer/inbound.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/swarm/peer/inbound.rs b/src/swarm/peer/inbound.rs index 040cafb..684a358 100644 --- a/src/swarm/peer/inbound.rs +++ b/src/swarm/peer/inbound.rs @@ -84,7 +84,20 @@ pub(crate) async fn handle_message( bail!("Incompatible swarm at {peer}: ours is {swarm_id}, it claims {theirs}"); } } - establish_peer(state, &peer, swarm_id, true, hello.ready).await?; + // A resent HELLO (our reply was lost) or a late copy of one repeats a + // handshake we answered already: it must not reset the session again. + let new_handshake = { + let peer_state = state.get_or_create_peer_state(&peer).await; + let mut peer_state = peer_state.lock().await; + let new = peer_state.last_hello.is_none_or(|(run, handshake)| { + run != hello.run_id || hello.handshake > handshake + }); + if new { + peer_state.last_hello = Some((hello.run_id, hello.handshake)); + } + new + }; + establish_peer(state, &peer, swarm_id, new_handshake, hello.ready).await?; let away = previously_seen.map(|seen| seen.elapsed()); if let Err(error) = send_hello_reply(state, &peer, hello.run_id, away).await { |
