diff options
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/stats.rs | 4 | ||||
| -rw-r--r-- | src/swarm/sync.rs | 29 |
2 files changed, 9 insertions, 24 deletions
diff --git a/src/swarm/stats.rs b/src/swarm/stats.rs index 371fe42..ed91db0 100644 --- a/src/swarm/stats.rs +++ b/src/swarm/stats.rs @@ -129,7 +129,7 @@ pub(crate) struct Relay { pub(crate) delivered: u64, pub(crate) delivered_bytes: u64, /// Sync messages sent (not offers), the bytes the envelope added to their - /// Automerge messages, and of those the swarm ID's and the epoch's. + /// Automerge messages, and of those the epoch's. pub(crate) framed: u64, pub(crate) framing_bytes: u64, pub(crate) framing_id_bytes: u64, @@ -255,7 +255,7 @@ impl NodeStats { } /// A sync message went out whose envelope added `bytes` to its Automerge message, - /// `ids` of them the swarm ID and the epoch. + /// `ids` of them the epoch. pub(crate) fn sync_framing(&self, bytes: usize, ids: usize) { let mut inner = self.lock(); inner.relay.framed += 1; diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 8660742..28f3ca0 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -239,14 +239,13 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> { return (session, Ok(None)); }; // What the envelope adds to an Automerge message (`swarm::stats`), and of - // that, the swarm ID and the epoch (msgpack: 36 bytes the epoch). + // that, the epoch (msgpack: 36 bytes). let inner = match &body { transport::SyncBody::Message(payload) => Some(payload.0.len()), transport::SyncBody::Delta(_) => None, }; - let ids = rmp_serde::encode::to_vec(&swarm_id).map_or(0, |id| id.len()) + 36; + let ids = 36; let envelope = transport::SyncEnvelope { - swarm_id, epoch, epoch_seq, body, @@ -390,13 +389,11 @@ pub(crate) async fn handle_sync( debug!(peer = %peer, "Dropping sync message from a peer that isn't a member yet"); true } - Standing::Member { swarm_id } if swarm_id != &envelope.swarm_id => { - bail!( - "Sync swarm mismatch for peer {peer}: validated_swarm={swarm_id}, envelope_swarm={}", - envelope.swarm_id - ); - } - Standing::Member { .. } => false, + // Its swarm was proven by the handshake (the envelope doesn't say it again). + Standing::Member { swarm_id } => match state.swarm_id().await { + Some(ours) if &ours == swarm_id => false, + _ => bail!("Sync from {peer}, a member of swarm {swarm_id}, which isn't ours"), + }, } }; @@ -409,18 +406,6 @@ pub(crate) async fn handle_sync( return Ok(()); } - let expected_swarm = state - .swarm_id() - .await - .ok_or_else(|| anyhow!("Missing expected swarm ID after peer membership"))?; - if envelope.swarm_id != expected_swarm { - bail!( - "Incompatible swarm from {peer}: expected {}, received {}", - expected_swarm, - envelope.swarm_id - ); - } - let epoch_label = envelope.epoch; let from_ready = envelope.ready; let writer = envelope.writer; |
