diff options
Diffstat (limited to 'src/swarm/sync.rs')
| -rw-r--r-- | src/swarm/sync.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 6c67e57..ed4c4da 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -238,6 +238,13 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> { let Some(body) = body else { 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). + 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 envelope = transport::SyncEnvelope { swarm_id, epoch, @@ -251,6 +258,9 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> { let encoded = transport .encode(&peer_owned, &ParsedMessage::Sync(envelope)) .map(Some); + if let (Ok(Some(encoded)), Some(inner)) = (&encoded, inner) { + stats.sync_framing(encoded.payload_len.saturating_sub(inner), ids); + } (session, encoded) }, ) |
