diff options
| author | tv <tv@krebsco.de> | 2026-11-16 03:50:14 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-16 03:50:14 +0000 |
| commit | 71ac2362820ca0b1ff6911b9b269261496d4b478 (patch) | |
| tree | d2a777130adced3bc51071a47303cabf17574aba /src | |
| parent | 417e6ce3efbb1e32ee5443d1d77ec3f0d4874dc2 (diff) | |
screen: what reads as no policy has what is received judged
A node judges what it receives only once the document holds a policy,
or a batch writes at a key named `policy` (`Screening::policed`); and
an envelope holding `null` at the policy's place reads as none. So a
change putting `"signed"` at `values` in a map beside such an envelope,
writing at no key named `policy`, went unjudged where it came alone,
and a later change deleting the envelope left a strict policy that no
change was refused for. Nodes that took the second in one batch with
others refused it, and the rest dropped it once told: apart until then,
by how changes were batched.
A node judges what it receives once anything is at the policy's place,
whatever it reads as. A swarm with nothing there is screened as before;
one whose policy's place holds what reads as none is judged by none but
the rule that refuses turning strict, as a swarm without a policy is.
Diffstat (limited to 'src')
| -rw-r--r-- | src/access/screen.rs | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/src/access/screen.rs b/src/access/screen.rs index 9ca8809..909133b 100644 --- a/src/access/screen.rs +++ b/src/access/screen.rs @@ -144,14 +144,19 @@ impl Screening { } /// Itself for the document `epoch_seq`: emptied if it was another's. - /// Whether `doc` holds a policy, known or not, or did since this node took it up: + /// Whether `doc` holds anything at the policy's place, a policy known or not or what + /// reads as none (an envelope holding `null`), or did since this node took it up: /// then what it receives is judged (`apply`), each change by the policy at its /// dependencies, though the policy is gone or unknown now; changes written under it - /// may still come. Kept across a swap of the document (a drop, a switch, a rejoin, - /// `of`); not across a restart: a node that starts with no policy in its document - /// judges as one that never had one. + /// may still come, and one writing into what reads as none may turn it into a policy. + /// Kept across a swap of the document (a drop, a switch, a rejoin, `of`); not across + /// a restart: a node that starts with nothing at the policy's place judges as one + /// that never had a policy. pub(crate) fn policed(&mut self, doc: &Document) -> bool { - self.policed |= !matches!(super::policy::of(doc), super::policy::Policy::Open); + self.policed |= !matches!( + crate::document::store::read_held(doc, &super::policy::path()), + Ok(None) + ); self.policed } @@ -1508,4 +1513,41 @@ mod tests { assert!(!crate::access::policy::of(&doc).enforced()); assert!(screening.policed(&doc)); } + + /// What reads as no policy at the policy's place (an envelope holding `null`) has + /// what is received judged: a change writing into it may make it a policy, strict + /// even, which every node refuses where the policy isn't strict. + #[test] + fn policed_where_the_policy_reads_as_none() { + use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD as B64URL}; + let meta = json!({ + "swarm": "s", + "path": ["_continuum", "access", "policy"], + "user": "alice", + "at": 0, + "seq": 0, + "prev": "", + }); + let envelope = format!( + "cv2.{}.{}.", + B64URL.encode("null"), + B64URL.encode(meta.to_string()) + ); + let mut doc = Document::new(); + transact( + &mut doc, + UnixMillis(1), + &Writer { + node: "a", + user: None, + }, + |doc| store::write_path(doc, &path("_continuum/access/policy"), &json!(envelope)), + ) + .unwrap(); + assert_eq!( + crate::access::policy::of(&doc), + crate::access::policy::Policy::Open + ); + assert!(Screening::default().policed(&doc)); + } } |
