1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Made the roles the only lists of topics, Refused PRAGMAs in queries

- Removed `[server] topics` and `[replication] replicated_topics`: a push
  is taken by its roles' `push_topics`, a replicated message by the
  peer's `accept_topics`; a topic exists from its first message.
- Topics that only came from a peer are read and listed like any other;
  `ListNames` lists the topics with messages, filtered by the roles.
- A push to a topic no role names is `NotAllowed`; `UnknownName` is only
  for nodes.
- Clients' queries: every PRAGMA refused as it's prepared (SQLite's
  authorizer), `PRAGMA query_only = 0` used to take effect.
- Noted the leads found by reading the code in `docs/known-issues.md`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 01:28:24 +01:00
parent cef99102f9
commit cf8264b21d
34 changed files with 304 additions and 227 deletions
+9 -20
View File
@@ -13,7 +13,7 @@ impl TryFrom<Vec<String>> for NameList {
type Error = String;
fn try_from(list: Vec<String>) -> Result<Self, String> {
check_names(&list, true)?;
check_names(&list)?;
Ok(NameList(list))
}
}
@@ -77,12 +77,11 @@ pub struct Role {
}
/// What a certificate may do: everything one of its roles allows, each role
/// on its own (a role's topics go with that role's nodes), replication
/// within the server's `replicated_topics`.
/// on its own (a role's topics go with that role's nodes). The roles are
/// all there is: no other list of topics.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Permissions {
pub(crate) roles: Vec<Role>,
pub(crate) replicated_topics: Option<NameList>,
}
impl Permissions {
@@ -112,20 +111,16 @@ impl Permissions {
/// Whether `node`'s messages in `topic` are sent to it.
pub fn sends(&self, topic: &str, node: &str) -> bool {
self.replicated(topic)
&& self
.roles
.iter()
.any(|role| role.send_topics.matches(topic) && role.send_nodes.matches(node))
self.roles
.iter()
.any(|role| role.send_topics.matches(topic) && role.send_nodes.matches(node))
}
/// Whether `node`'s messages in `topic` are taken from it.
pub fn accepts(&self, topic: &str, node: &str) -> bool {
self.replicated(topic)
&& self
.roles
.iter()
.any(|role| role.accept_topics.matches(topic) && role.accept_nodes.matches(node))
self.roles
.iter()
.any(|role| role.accept_topics.matches(topic) && role.accept_nodes.matches(node))
}
/// The topics and the nodes taken from it, as `SyncState` lists them:
@@ -158,10 +153,4 @@ impl Permissions {
.iter()
.any(|role| !role.send_topics.is_empty() || !role.accept_topics.is_empty())
}
fn replicated(&self, topic: &str) -> bool {
self.replicated_topics
.as_ref()
.is_none_or(|topics| topics.matches(topic))
}
}