diff options
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 { |
