diff options
| author | tv <tv@krebsco.de> | 2026-11-15 18:53:46 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-15 18:53:46 +0000 |
| commit | c761bcfd03aafe1398109d657066a2498f62af33 (patch) | |
| tree | 8bedd34d17ce53fd7462aa0429094ae0062f5ea1 /src/access | |
| parent | fbe98b00c9e98ebad02fe18103ca02bdfe1ed9e5 (diff) | |
rules: the document's own policy read once for its heads
Every change judged under a policy that isn't strict, in every swarm,
read the document's own policy to ask whether the time before a strict
policy applies: in a swarm without a policy, where a change was judged
for nearly nothing, a read of the policy for each. It is now read once
for the document's heads and kept while the batch is judged at others
(`Reads::strict_now`), read again once the document takes more.
Diffstat (limited to 'src/access')
| -rw-r--r-- | src/access/rules.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/access/rules.rs b/src/access/rules.rs index 43404cf..745dd7e 100644 --- a/src/access/rules.rs +++ b/src/access/rules.rs @@ -95,6 +95,9 @@ pub(crate) struct Reads { member: HashMap<String, bool>, /// By user: what the registry lets it do. caps: HashMap<String, Caps>, + /// Whether the document's own policy, at its heads then, is strict + /// (`before_strict`): kept across `seen`, read again once the document takes more. + strict_now: Option<(Vec<ChangeHash>, bool)>, } impl Reads { @@ -103,11 +106,25 @@ impl Reads { if self.seen != seen { *self = Self { seen: seen.to_vec(), + strict_now: self.strict_now.take(), ..Self::default() }; } self } + + /// Whether `doc`'s policy, as it stands, is strict: read once for its heads. + fn strict_now(&mut self, doc: &Document) -> bool { + let heads = doc.get_heads(); + match &self.strict_now { + Some((at, strict)) if *at == heads => *strict, + _ => { + let strict = super::policy::of(doc).strict(); + self.strict_now = Some((heads, strict)); + strict + } + } + } } impl Reads { @@ -161,6 +178,7 @@ pub(crate) fn judge_reading( .get_or_insert_with(|| super::policy::of(&at)) .clone(); if !policy.strict() + && reads.strict_now(doc) && let Some(why) = before_strict(doc, change) { return Err(Refusal::Rule(why)); @@ -359,11 +377,8 @@ pub(crate) fn judge_reading( /// later, strict over strict, names the same change; one written beside it, strict or /// not, is refused like any other, so a change made later to look as old can't take its /// place. A swarm strict from its genesis change (`--bootstrap-policy`) has no such -/// time. None where `doc`'s policy isn't strict: there, nothing changes. +/// time. Asked only where `doc`'s policy is strict: elsewhere, nothing changes. fn before_strict(doc: &Document, change: &Change<'_>) -> Option<String> { - if !super::policy::of(doc).strict() { - return None; - } let held = crate::document::changes::holds(doc, &change.hash); let beside = turned_strict(doc).into_iter().find(|turned| { *turned != change.hash |
