aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/events.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 19:58:26 +0000
committertv <tv@krebsco.de>2026-11-16 21:26:24 +0100
commitff97d657d76508af290a29ed11e478575317c7df (patch)
treebe944a6b70422d4d53ed0fb54e20e3939a9c23e9 /src/document/events.rs
parentc9707297bd393f69461c781a38a5ddb017dced60 (diff)
federation: events put again
A node puts again, in changes of its own, every event its store holds that its document lacks (`docs/store.md`, What the store takes from the document): one it took from the document it left, at a drop or a rejoin, or from a change it refused, whose events the store is offered as from anywhere (`Holding::look`, every few seconds, of the changes screening keeps). It puts each after its dependencies, what the checkpoint keeps first, then what the store took after it in the order taken, up to 1 MiB of events a change, once a wait of its own has passed: random, between one and ten seconds after the document first lacked them, so that not every node puts the same, and none another node put meanwhile, as it looks again when it writes.
Diffstat (limited to 'src/document/events.rs')
-rw-r--r--src/document/events.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/document/events.rs b/src/document/events.rs
index ee16de7..687079e 100644
--- a/src/document/events.rs
+++ b/src/document/events.rs
@@ -8,7 +8,7 @@
//! (`store::write_path`). Its writer is the first 16 bytes of the root's ID, its time 0,
//! and it has no message.
-use automerge::legacy::OpType;
+use automerge::legacy::{Key, OpType};
use automerge::transaction::CommitOptions;
use automerge::{ObjId, ObjType, ScalarValue, Value};
use serde_json::Value as JsonValue;
@@ -51,6 +51,22 @@ pub(crate) fn bytes(doc: &impl ReadDoc, id: &Id) -> Option<Vec<u8>> {
}
}
+/// The events `change` puts: bytes, each at a key that is its ID.
+pub(crate) fn carried(change: &Change) -> Vec<Vec<u8>> {
+ super::changes::decode(change)
+ .operations
+ .into_iter()
+ .filter_map(|op| match (op.key, op.action) {
+ (Key::Map(key), OpType::Put(ScalarValue::Bytes(bytes)))
+ if Id::of(&bytes).to_string() == key.as_str() =>
+ {
+ Some(bytes)
+ }
+ _ => None,
+ })
+ .collect()
+}
+
/// The policy of a swarm holding a store of the fold `fold`.
pub(crate) fn policy(fold: &str) -> JsonValue {
serde_json::json!({"version": 2, "store": fold})
@@ -159,6 +175,7 @@ mod tests {
);
assert_eq!(ids(&doc), vec![id]);
assert_eq!(bytes(&doc, &id).as_deref(), Some(ROOT));
+ assert_eq!(carried(&genesis("federation", ROOT)), vec![ROOT.to_vec()]);
}
#[test]