aboutsummaryrefslogtreecommitdiffstats
path: root/src/access
diff options
context:
space:
mode:
Diffstat (limited to 'src/access')
-rw-r--r--src/access/bans.rs18
-rw-r--r--src/access/mod.rs1
-rw-r--r--src/access/rules.rs34
3 files changed, 52 insertions, 1 deletions
diff --git a/src/access/bans.rs b/src/access/bans.rs
new file mode 100644
index 0000000..339f6cf
--- /dev/null
+++ b/src/access/bans.rs
@@ -0,0 +1,18 @@
+//! Banned nodes (`_continuum/banned/<node ID>`, `{"by", "at", "reason"}`), written by a
+//! user who may write there, as any protocol data: a node refuses a banned node's
+//! handshake, so it neither syncs with it nor counts it a member (`swarm::peer`), and
+//! with the swarm's policy every node refuses the changes a banned node commits
+//! (`access::rules`, judged as the ban stood when they were made). Deleting the entry
+//! lifts the ban.
+
+use crate::document::{ReadDoc, meta, store};
+
+/// Where `node`'s ban is.
+pub(crate) fn path(node: &str) -> Vec<String> {
+ meta::path(&[meta::BANNED, node])
+}
+
+/// Whether `doc` bans `node`.
+pub(crate) fn banned(doc: &impl ReadDoc, node: &str) -> bool {
+ store::read_path(doc, &path(node)).ok().flatten().is_some()
+}
diff --git a/src/access/mod.rs b/src/access/mod.rs
index ea2e65c..4d96f9b 100644
--- a/src/access/mod.rs
+++ b/src/access/mod.rs
@@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
use crate::document::meta;
+pub(crate) mod bans;
pub(crate) mod policy;
pub(crate) mod registry;
pub(crate) mod rules;
diff --git a/src/access/rules.rs b/src/access/rules.rs
index e151cbb..c061893 100644
--- a/src/access/rules.rs
+++ b/src/access/rules.rs
@@ -9,7 +9,8 @@
//! * A change without dependencies is an epoch's root: the genesis change, the first a
//! document holds, or a remake's snapshot, whose hash is the epoch's ID. Nothing else
//! is judged of it: it writes the protocol data it starts with.
-//! * Any other is its committer's, a member at its dependencies, or registering itself.
+//! * Any other is its committer's, a member at its dependencies, or registering itself,
+//! and not banned there (`access::bans`).
//! * Protocol data (`_continuum`, `document::meta`): a member's entry and its votes by
//! that member only (removing an entry also by a user who may write there); epochs
//! and the swarm ID in a root only; a remake's decision by the coordinator its
@@ -86,6 +87,9 @@ pub(crate) fn judge(doc: &Document, epoch: Epoch, change: &Change<'_>) -> Result
let Some(node) = change.committer else {
return refuse("it names no node".to_owned());
};
+ if super::bans::banned(&at, node) {
+ return refuse(format!("{node} is banned"));
+ }
let own_entry = meta::path(&[meta::MEMBERS, node]);
let member = store::read_path(&at, &own_entry).ok().flatten().is_some();
let registering = change
@@ -313,6 +317,34 @@ mod tests {
assert!(refused(judged(&doc, "a", Some("alice"), &[tokens])));
}
+ /// A banned node's changes: refused, as the ban stood when they were made.
+ #[test]
+ fn banned_nodes() {
+ let mut doc = swarm(true);
+ let before = doc.get_heads();
+ write(&mut doc, "_continuum/banned/b", json!({"by": "alice"}));
+ assert!(refused(judged(
+ &doc,
+ "b",
+ None,
+ &["_continuum/members/b/alive"]
+ )));
+ let touched = paths(&["_continuum/members/b/alive"]);
+ let earlier = judge(
+ &doc,
+ Epoch::GENESIS,
+ &Change {
+ hash: ChangeHash([9; 32]),
+ deps: &before,
+ seen: &before,
+ committer: Some("b"),
+ user: None,
+ paths: &touched,
+ },
+ );
+ assert!(earlier.is_ok());
+ }
+
/// A node that isn't a member may only register itself.
#[test]
fn strangers_register_themselves_only() {