diff options
| author | tv <tv@krebsco.de> | 2026-11-05 03:50:38 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-05 03:50:38 +0100 |
| commit | a02ed87abf6a0dc9d3f36bafcf333272586093aa (patch) | |
| tree | e22e2f58703d3eac74df8e0eccc51c47b2f45133 /src/swarm/peer/inbound.rs | |
| parent | a9fb4e6890bfaef1e25cdceb4eea9c997e3c7cdf (diff) | |
epoch tag in sync
Diffstat (limited to 'src/swarm/peer/inbound.rs')
| -rw-r--r-- | src/swarm/peer/inbound.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/swarm/peer/inbound.rs b/src/swarm/peer/inbound.rs index f43a45a..c75f66b 100644 --- a/src/swarm/peer/inbound.rs +++ b/src/swarm/peer/inbound.rs @@ -38,8 +38,26 @@ pub(crate) async fn handle_message( note_alive(state, &peer, &message).await; return Ok(()); } - // WHO and ME end at the identity layer (`transport::identity`). - let Some((epoch, epoch_seq)) = message.epoch_stamp() else { + // WHO and ME end at the identity layer (`transport::identity`). A sync message names + // its epoch by a tag (`EpochTag`): ours, or the sender's as we know it; one naming + // neither is of an epoch we don't sync on, and says nothing we could record. + let stamp = match &message { + transport::ParsedMessage::Sync(envelope) => { + let known = match state.get_peer_state(&peer).await { + Some(peer_state) => peer_state.lock().await.epoch, + None => None, + }; + let epoch = envelope + .epoch + .resolve(std::iter::once(state.local_epoch()).chain(known)); + if epoch.is_none() { + debug!(peer = %peer, epoch = %envelope.epoch, "Dropping a sync message of an epoch we don't know"); + } + epoch.map(|epoch| (epoch, envelope.epoch_seq)) + } + _ => message.epoch_stamp(), + }; + let Some((epoch, epoch_seq)) = stamp else { return Ok(()); }; @@ -145,7 +163,7 @@ pub(crate) async fn handle_message( ensure_handshake(state, &peer).await; } if !same_epoch { - debug!(peer = %peer, epoch = %envelope.epoch, "Dropping sync message from another epoch"); + debug!(peer = %peer, epoch = %epoch, "Dropping sync message from another epoch"); return Ok(()); } crate::swarm::source::synced_from(state, &peer); |
