aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/store.md8
-rw-r--r--src/federation/store/memory.rs10
-rw-r--r--src/federation/store/mod.rs3
-rw-r--r--src/federation/store/testfold.rs2
4 files changed, 20 insertions, 3 deletions
diff --git a/docs/store.md b/docs/store.md
index dad1485..e23a6a0 100644
--- a/docs/store.md
+++ b/docs/store.md
@@ -87,6 +87,7 @@ A fold says, of its events:
* **what an event builds on**, read from its bytes; bytes that aren't one of its events
are none, and are refused;
+* **how large an event may be**, which the document judges a change by (On Automerge);
* **whether an event is taken where its history reads as a given state**: judging. A
root is taken only as its own store's, never by judging;
* **the state a checkpoint and the events after it read as**, built by adding the events
@@ -106,6 +107,8 @@ In Rust, roughly:
```rust
pub trait Fold {
type State: Clone;
+ /// The most bytes an event may have: larger ones are none.
+ const LARGEST: usize;
/// What the event builds on; `None` where its bytes are none of this fold's events.
fn dependencies(event: &[u8]) -> Option<Vec<Id>>;
/// Whether the event is taken where its history reads as `at`.
@@ -226,8 +229,8 @@ nothing else of a strict policy: the document holds no values but events.
A change of a swarm holding a store writes nothing but:
-* **events**: at `_continuum/events/<ID>` the bytes whose ID it is, at a key held
- nowhere at the change's history;
+* **events**: at `_continuum/events/<ID>` the bytes whose ID it is, no more than its fold
+ allows, at a key held nowhere at the change's history;
* **its node's own protocol data**: its entry, its acks, a remake's record and proposal,
and, as a remake's coordinator, its decision or its abort; or, an epoch's first
change, epochs, the swarm's ID, the policy and the checkpoint.
@@ -407,6 +410,7 @@ crafted changes. *Sim*: a simulation. *Bench*: measured, not judged.
| 29 | Flooding: events, writers, history, remakes | Slow, or out of memory; not wrong | bench |
| 30 | A member decides compactions, grinding their IDs until the new epoch's ID is lower than the honest one's | Nodes on the honest epoch rejoin the lower, once a generation; no event is lost: slow, not wrong | sim |
| 31 | A made-up epoch whose snapshot holds a checkpoint before the node's document's, the root say | Not followed: a node follows an epoch only where the snapshot's checkpoint is its document's, one it builds from it, or one its operator pins | sim |
+| 32 | An event larger than the fold allows, put by a change | Refused: the change, by its own bytes; the store takes it nowhere | unit |
## Tests
diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs
index 8f97299..8b943f3 100644
--- a/src/federation/store/memory.rs
+++ b/src/federation/store/memory.rs
@@ -8,7 +8,7 @@ use super::{Fold, Id, Refused};
/// Why a store doesn't take an event.
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum Refusal {
- /// Its bytes are none of the fold's events.
+ /// Its bytes are none of the fold's events, or more than it allows.
None,
/// The fold refuses it at its history.
Judged(Refused),
@@ -233,6 +233,9 @@ impl<F: Fold> Store<F> {
if self.waiting.contains_key(&id) {
return Offered::Waiting;
}
+ if bytes.len() > F::LARGEST {
+ return self.refuse(id, Refusal::None);
+ }
let Some(dependencies) = F::dependencies(&bytes) else {
return self.refuse(id, Refusal::None);
};
@@ -613,6 +616,11 @@ mod tests {
store.offer(testfold::junk(&[root])),
Offered::Refused(Refusal::Judged(_))
));
+ let large = "x".repeat(TestFold::LARGEST);
+ assert_eq!(
+ store.offer(testfold::put(&[root], "a", &large)),
+ Offered::Refused(Refusal::None)
+ );
}
#[test]
diff --git a/src/federation/store/mod.rs b/src/federation/store/mod.rs
index b11c81a..ad1720d 100644
--- a/src/federation/store/mod.rs
+++ b/src/federation/store/mod.rs
@@ -72,6 +72,9 @@ pub(crate) trait Fold {
/// reading need of the events' history.
type State: Clone;
+ /// The most bytes an event may have: larger ones are none.
+ const LARGEST: usize;
+
/// What the event builds on; `None` where its bytes are none of this fold's events.
fn dependencies(event: &[u8]) -> Option<Vec<Id>>;
diff --git a/src/federation/store/testfold.rs b/src/federation/store/testfold.rs
index bbe0307..baaba55 100644
--- a/src/federation/store/testfold.rs
+++ b/src/federation/store/testfold.rs
@@ -289,6 +289,8 @@ pub(crate) struct TestFold;
impl Fold for TestFold {
type State = State;
+ const LARGEST: usize = 64 * 1024;
+
fn dependencies(event: &[u8]) -> Option<Vec<Id>> {
decode(event).map(|(deps, _)| deps)
}