aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/stats.rs14
-rw-r--r--src/swarm/sync.rs10
2 files changed, 24 insertions, 0 deletions
diff --git a/src/swarm/stats.rs b/src/swarm/stats.rs
index 191f4e9..371fe42 100644
--- a/src/swarm/stats.rs
+++ b/src/swarm/stats.rs
@@ -128,6 +128,11 @@ pub(crate) struct Relay {
/// payload's bytes.
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.
+ pub(crate) framed: u64,
+ pub(crate) framing_bytes: u64,
+ pub(crate) framing_id_bytes: u64,
/// Sync messages received that carried changes, all of which we had already, and
/// their payload's bytes: changes that came twice. Of those, how many came along a
/// writer's tree (`SyncEnvelope::writer`), and how many were taken as delivered by
@@ -249,6 +254,15 @@ impl NodeStats {
self.lock().relay.tree_forwards += 1;
}
+ /// A sync message went out whose envelope added `bytes` to its Automerge message,
+ /// `ids` of them the swarm ID and the epoch.
+ pub(crate) fn sync_framing(&self, bytes: usize, ids: usize) {
+ let mut inner = self.lock();
+ inner.relay.framed += 1;
+ inner.relay.framing_bytes += bytes as u64;
+ inner.relay.framing_id_bytes += ids as u64;
+ }
+
/// A sync message taken as delivered went out, of `bytes` payload.
pub(crate) fn delivered_sent(&self, bytes: usize) {
let mut inner = self.lock();
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)
},
)