summaryrefslogtreecommitdiffstats
path: root/src/transport/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 19:45:21 +0100
committertv <tv@krebsco.de>2026-10-26 19:45:21 +0100
commit8edc7242b0b72853bccb3f1c1c841e81ebb3c6b3 (patch)
treed6067794054af9d4562634eb5055cb114c774d2d /src/transport/mod.rs
parent4bbadf6fdc4733b4c3c5eeb575508b2f9334ebdb (diff)
decode sync messages lazily
Sync messages are now being decoded only where they are applied: after membership has been checked, in the sync lane's blocking task. Debug now shows only the size instead of the whole message.
Diffstat (limited to 'src/transport/mod.rs')
-rw-r--r--src/transport/mod.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/transport/mod.rs b/src/transport/mod.rs
index a040993..0d761e0 100644
--- a/src/transport/mod.rs
+++ b/src/transport/mod.rs
@@ -326,13 +326,37 @@ pub struct SyncEnvelope {
/// ignores an epoch older than the newest it has seen in the same session.
pub epoch_seq: u32,
#[serde(with = "crate::transport::wire::codec::sync_message")]
- pub message: Message,
+ pub message: SyncPayload,
/// The sender was ready when it generated the message: its document is the swarm's,
/// not one it is still filling (joining, rejoining). Only such a peer can tell a
/// catching-up node that it has everything; an empty document says nothing else.
pub ready: bool,
}
+/// An Automerge sync message in Automerge's own encoding. Decoded only where it is
+/// applied (`decode`), after the sender proved to be a member and off the consumer: a
+/// large message from anyone else costs nothing but its bytes.
+#[derive(Clone)]
+pub struct SyncPayload(pub bytes::Bytes);
+
+impl SyncPayload {
+ pub fn encode(message: Message) -> Self {
+ Self(message.encode().into())
+ }
+
+ pub fn decode(&self) -> Result<Message> {
+ Message::decode(&self.0)
+ .map_err(|error| anyhow::anyhow!("Automerge decode failed: {error:?}"))
+ }
+}
+
+/// Sizes instead of contents: logged messages stay short.
+impl std::fmt::Debug for SyncPayload {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "SyncPayload({} bytes)", self.0.len())
+ }
+}
+
/// A message serialized for the wire. Cloning is cheap (shared buffer).
#[derive(Clone, Debug)]
pub struct EncodedMessage {