diff options
| author | tv <tv@krebsco.de> | 2026-11-17 00:19:51 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-17 01:47:31 +0100 |
| commit | 27e5436b5cc5b94831aec272cd7b350be808e3f1 (patch) | |
| tree | 8e736dc0dd3edac49fc944a733cc4678bf9f4ef2 /src/access/holding.rs | |
| parent | ac95ca1d8d774e494f5719457a0bba64a3e690b7 (diff) | |
access: the changes founding a fork's swarm taken, unsigned, as built byte for byte
A change of a swarm holding a store naming no node is taken where it is one of those
founding the swarm (`events::is_founding`): built from the root its document holds and
the events the root keeps, those at its history and those it puts, by the fold
(`access::holding`). A change of the genesis change's writer waits for no signature,
as every node builds it and nobody signs it (`screen::built_by_every_node`); judged, it
is refused unless it is one of them.
Diffstat (limited to 'src/access/holding.rs')
| -rw-r--r-- | src/access/holding.rs | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/src/access/holding.rs b/src/access/holding.rs index 3c6fd13..4fc41f5 100644 --- a/src/access/holding.rs +++ b/src/access/holding.rs @@ -9,10 +9,11 @@ //! //! Everything else is closed: whatever isn't under `_continuum`, the policy, the swarm's //! ID, users, bans, the swarm's topology, remakes and their acks. Nothing deletes or -//! replaces an event. A change names its node, as signed (signatures are required): the -//! genesis change's writer (`document::events`) names none, so no change under it is -//! taken but the genesis change, which the epoch's root is. Which events the store takes -//! is the store's (`federation::held`); this judges none. +//! replaces an event. A change names its node, as signed (signatures are required), but +//! for the changes founding the swarm, which every node builds and nobody signs: the +//! genesis change, which the epoch's root is, and those of its writer putting the events +//! a fork's root keeps (`document::events`), taken only as built byte for byte. Which +//! events the store takes is the store's (`federation::held`); this judges none. //! //! In a swarm not holding a store, no change writes a policy naming one (`turns_store`): //! a swarm holds a store from its genesis change, or not at all. @@ -22,7 +23,8 @@ use sha2::{Digest, Sha256}; use super::rules::{Change, Refusal}; use crate::document::at::At; use crate::document::inspect::{Action, Op, Path}; -use crate::document::{meta, store}; +use crate::document::{events, meta, store}; +use crate::federation::store::Id; /// The most bytes an event of the fold `fold` may have. fn largest(fold: &str) -> usize { @@ -33,10 +35,44 @@ fn largest(fold: &str) -> usize { } } +/// The events the store's root `root` keeps, by the fold `fold`: those of a fork's. +fn keeps(fold: &str, root: &[u8]) -> Option<Vec<Id>> { + use crate::federation::store::Fold; + match fold { + crate::federation::fold::Federation::NAME => { + crate::federation::fold::Federation::parts(root).map(|(_, keeps)| keeps) + } + _ => None, + } +} + +/// Whether `change`, naming no node, is one of those founding the swarm, which every node +/// builds from the store's root and the events it keeps (`events::is_founding`). +fn founding(at: &At<'_>, change: &Change<'_>, fold: &str) -> bool { + let Some(root) = events::swarm(at).and_then(|swarm| events::bytes(at, &swarm)) else { + return false; + }; + let Some(keeps) = keeps(fold, &root) else { + return false; + }; + let written: Vec<Vec<u8>> = change + .ops + .iter() + .filter_map(|op| match &op.action { + Action::PutBytes(bytes) => Some(bytes.clone()), + _ => None, + }) + .collect(); + events::is_founding(at, fold, (&root, &keeps), &change.hash, &written) +} + /// Judges `change`, of a swarm holding a store of the fold `fold`, at its history `at`. pub(crate) fn judge(at: &At<'_>, change: &Change<'_>, fold: &str) -> Result<(), Refusal> { let refuse = |why: String| Err(Refusal::Rule(why)); let Some(node) = change.committer else { + if founding(at, change, fold) { + return Ok(()); + } return refuse("it names no node".to_owned()); }; let events = meta::path(&[meta::EVENTS]); |
