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

Added filtered name lists and the DLL's enumerations, Opened the query connection read-only, Bumped to 0.4.0

- Protocol 8: ListTopics / ListNodes became one ListNames [kind, topics,
  nodes], each filter a name or a pattern: the topics a node pushed to,
  the nodes that pushed to a topic, wildcards included. No storage
  change; the permissions are the lists' (may_list_topic,
  may_list_nodes_of)
- The DLL: the JSON getters are suffixed AsJson (GetNamesListAsJson,
  GetQueryResultAsJson); ListNamesA/W replaces ListTopics / ListNodes.
  Beside them, Win32-like enumerations: EnumerateNames / EnumerateQuery,
  NextName / NextQueryRow (before the first item at first), getters,
  CloseEnum (enumerations.rs). They don't outlive their client:
  FreeClient closes them
- C#: EnumerateTopics / EnumerateNodes / EnumerateQuery as IEnumerable
  (QueryRow for a query), fetched at each foreach, closed in finally
- Queries: the connection opens the file read-only
  (SQLITE_OPEN_READ_ONLY), a fifth guard beside query_only, the
  read-only statement check, one statement only and the PRAGMA-denying
  authorizer; a unit test checks the handle is read-only
- Python, PureBasic, the tool, docs, guides and revamp.md (step 16)
  updated; versions 0.4.0 everywhere

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 20:19:04 +01:00
parent 1a1603f3f3
commit c513d8bf05
41 changed files with 1625 additions and 297 deletions
+43 -7
View File
@@ -67,11 +67,12 @@ Its conventions:
on the other; the C runtime linked statically on Windows (the release
DLL imports system DLLs only).
Every export but `CreateClient` takes the handle first (left out below).
Every export but `CreateClient` takes the handle first (left out below):
a client's, or an enumeration's for the enumeration getters.
| Exports | What |
|---|---|
| `CreateClient()`, `FreeClient` | a new client's handle (0 if it failed); freed, 1 |
| `CreateClient()`, `FreeClient` | a new client's handle (0 if it failed); freed (its enumerations closed), 1 |
| `SetCaCertificate`, `SetCertificate`, `SetPrivateKey`, `SetCrl` (`A`/`W`) | PEM text (starting with `-----BEGIN`), or the path of a file holding it; `SetCrl` null or empty for none. Before connecting (`AlreadyConnected`); a file that can't be read is `FileError` |
| `Connect(Host, Port)` (`A`/`W`) | TLS with those; refused: `AuthRejected` (the server refused the certificate), `ServerNotVerified` (this client refused the server's), `NotAllowed` (none of its roles is the server's), `VersionMismatch` |
| `IsConnected`, `Disconnect` | `IsConnected` notices a connection the server closed |
@@ -80,8 +81,11 @@ Every export but `CreateClient` takes the handle first (left out below).
| `GetLatestMessageOf(Topic, Node)` (`A`/`W`) | 1, or 0 with `NotFound` when there's none yet |
| `GetMessages(Topic, Node, After, Limit)` (`A`/`W`) | how many (0 isn't a failure), -1 on failure; then `GetMessageCount`, `SelectMessage(Index)`, `HasMoreMessages` |
| `GetMessageId`, `GetMessagePushedAt`, `GetMessageAttachmentSize`, `IsMessageAttachmentReady`, `GetMessageData`/`Topic`/`Node` (`A`/`W`) | the selected message; topic and node as asked |
| `ListTopics`, `ListNodes`, then `GetNamesList` (`A`/`W`) | how many; `{"kind":"topic","names":[...],"truncated":false}` |
| `Query(Sql)`, then `GetQueryResult` (`A`/`W`) | `{"columns":[...],"rows":[[...],...]}` |
| `ListNames(Kind, Topics, Nodes)` (`A`/`W`), then `GetNamesListAsJson` (`A`/`W`) | how many; `{"kind":"topic","names":[...],"truncated":false}`. 1 topics, 2 nodes, of the topic/node pairs `Topics` and `Nodes` match (a name or a pattern each, null for any): `(1, null, null)` every topic it may see, `(1, null, "kitchen")` the topics kitchen pushed to, `(2, "sensors.*", null)` the nodes that pushed to those |
| `Query(Sql)` (`A`/`W`), then `GetQueryResultAsJson` (`A`/`W`) | `{"columns":[...],"rows":[[...],...]}` |
| `EnumerateNames(Kind, Topics, Nodes)` (`A`/`W`), then `NextName`, `GetEnumName` (`A`/`W`), `GetNameCount`, `IsNamesListTruncated` | the same list without JSON: an enumeration's handle (0 on failure, the client's error); see below |
| `EnumerateQuery(Sql)` (`A`/`W`), then `GetQueryColumnCount`, `GetQueryColumnName(Index)` (`A`/`W`), `NextQueryRow`, `GetQueryValue(Index)` (`A`/`W`), `IsQueryValueNull(Index)` | the same result without JSON, a row at a time; see below |
| `CloseEnum` | an enumeration closed: 1, 0 if it wasn't one |
| `PushMessageWithFile(Topic, Data, FilePath)`, `PushMessageWithData(Topic, Data, *Data, Size)` (`A`/`W`) | the id, -1 on failure; the attachment 1 byte and up, as much as the server takes (`TooBig`); a file read twice (its SHA-256 first), one changed in between refused (`DataMismatch`) |
| `SaveAttachment(Topic, Node, MessageId, FilePath)` (`A`/`W`) | its size, -1 on failure (`NotFound`, `NotReady`, `AttachmentMismatch`); a failed one leaves no file |
| `LoadAttachment(Topic, Node, MessageId)` (`A`/`W`), then `GetAttachmentData(*Buffer, Size)`, `FreeAttachmentData()` | into memory, for small ones; the getter returns the size, copies nothing if it doesn't fit |
@@ -89,6 +93,27 @@ Every export but `CreateClient` takes the handle first (left out below).
The header has each one's comment. Every name starts with `BakaShrot_`.
**Enumerations**, like Win32's `FindFirstFile` / `FindNextFile` /
`FindClose`: `EnumerateNames()` or `EnumerateQuery()` asks the server
once and keeps the whole answer; `NextName()` / `NextQueryRow()` move to
the next item (1, 0 once there are no more, -1 for a handle that isn't
one of that kind), the getters read it. An enumeration starts before its
first item, so `while (BakaShrot_NextName(e) == 1)` reads them all, none
for an empty list. Several can be open at once, even on one client; the
client's later calls don't change them. They don't outlive their client:
`FreeClient()` closes them, their handles refused after. Otherwise
`CloseEnum()` once done. Their handles are numbered with the clients',
never reused: one is never the other's. A value's getter returns 0 for a
null, `IsQueryValueNull()` tells it from an empty string.
```c
int64_t e = BakaShrot_EnumerateNamesW(client, 1, NULL, L"kitchen");
while (BakaShrot_NextName(e) == 1) {
BakaShrot_GetEnumNameW(e, name, sizeof name); /* a topic kitchen pushed to */
}
BakaShrot_CloseEnum(e);
```
## Python
`bindings/python/bakashrot.py`: `Client(server, ca,
@@ -98,7 +123,9 @@ on 3.8), `client.node` once connected, `push(data, topic,
attachment=None)` (the topic required; the attachment bytes or a path),
`latest()`, `get_messages()`, `iter_messages()`, `follow()`,
`get_attachment()` (bytes), `save_attachment()` (a file),
`list_topics()` / `list_nodes()` (names), `query()` / `query_raw()`.
`list_topics()` / `list_nodes()` (names; `topic=` and `node=`, a name or
a pattern each, filter them: `list_topics(node="kitchen")` the topics
kitchen pushed to), `query()` / `query_raw()`.
Each `Client` has its own client in the DLL: several can be connected at
once, from any threads.
Errors: `RefusedError`, `ConnectionLostError`, `AuthError` (a certificate
@@ -140,8 +167,15 @@ using (Client client = new Client("10.0.0.2", 7000, "ca.crt", "kitchen.crt", "ki
data[, byte[]])`, `PushFile(topic, data, path)`, `Latest()` (null if
none), `GetMessages()` (a `MessagesPage`), `IterMessages()`, `Follow()`,
`GetAttachment()` (bytes), `SaveAttachment()` (a file), `ListTopics()` /
`ListNodes()` / `Query()` (the library's JSON, as a string: parsing it is
the app's), `Close()` / `Dispose()`. The same exceptions as Python's:
`ListNodes()` / `Query()` (the library's JSON, as a string: parsing it
is the app's; `ListTopics(topic, node)` / `ListNodes(topic, node)`
filter the lists as Python's do, null for any), `EnumerateTopics()` /
`EnumerateNodes()` (the same, filtered the same, as an
`IEnumerable<string>`) and `EnumerateQuery()` (`QueryRow`s: `Values`,
null for NULL, by index or column name, `Columns`), over the library's
enumerations, no JSON: each `foreach` asks again, the enumeration closed
when it ends (`Close()` ends it too, `ConnectionLostException`),
`Close()` / `Dispose()`. The same exceptions as Python's:
`RefusedException`, `ConnectionLostException`, `AuthException`,
`BakaShrotException`, each with its `ErrorCode`. Strings go as UTF-16 (the
`W` exports); one with a NUL is refused (`InvalidArgument`) rather than
@@ -184,6 +218,8 @@ bakashrot messages logs kitchen -f --after latest --time
bakashrot query "SELECT topic, count(*) FROM messages GROUP BY topic"
bakashrot list Topics (2): ... Nodes (1): ...
bakashrot list nodes --json {"kind":"node","names":["kitchen"],"truncated":false}
bakashrot list topics --nodes kitchen Topics (1): the topics kitchen pushed to
bakashrot list nodes --topics 'sensors.*' Nodes (2): those that pushed to sensors.*
```
- **`messages`:** the first 100 by default (`--limit 0` for all), `--after
+1 -1
View File
@@ -49,7 +49,7 @@ that browses a server: reading a topic is still `read_topics`. `query`
gives both, it reads everything anyway.
No `AllowRead` / `AllowWrite`: a list that's empty allows nothing. No
default topic: a push always names its topic (protocol 7 has none).
default topic: a push always names its topic (protocol 8 has none).
**The roles are the only lists of topics** (decided 2026-11-16): no
`[server] topics`, no `[replication] replicated_topics`, both refused as
+1 -1
View File
@@ -163,7 +163,7 @@ certificate is refused, at its next connection or request:
Failed to connect to server-2.lab:7000 (AuthRejected): the server refused this client's certificate (CertificateRevoked)
```
**Python.** `pip install bakashrot-0.3.0-py3-none-<platform>.whl` (from the
**Python.** `pip install bakashrot-0.4.0-py3-none-<platform>.whl` (from the
release's `python/`), then, next to lab-py's `client.toml` (it may push and
read: `sensor` and `dashboard`):
+5 -4
View File
@@ -1,4 +1,4 @@
# Protocol 7
# Protocol 8
What goes over a connection between a client and a server, or two servers.
The code is `crates/bakashrot-proto`; this describes it.
@@ -83,8 +83,9 @@ format, its values are checked all the same.)
### Types
Direction: **C** client, **S** server, **P** peer (a server linked to
another, as its client). Ids are protocol 7's own (6 can't connect); a new
packet takes the next one, none is ever reused.
another, as its client). Ids are protocol 7's own (6 can't connect; 8
added `ListNames`' filters); a new packet takes the next one, none is
ever reused.
| Id | Packet | Dir | Fields | Answered by |
|---|---|---|---|---|
@@ -98,7 +99,7 @@ packet takes the next one, none is ever reused.
| 8 | GetAttachment | C→S | `topic`, `node`, `message_id`, `from_part` | Attachment then its parts / RequestRefused |
| 9 | Attachment | S→C | `size`, `sha256` | |
| 10 | AttachmentPart | C→S, S→C, P→S | `data` bin, 1 B to 1 MiB | |
| 11 | ListNames | C→S | `kind` (1 topics, 2 nodes) | NamesList |
| 11 | ListNames | C→S | `kind` (1 topics, 2 nodes), `topics`, `nodes`: each a name or a pattern, or nil for any (those of the topic/node pairs they match) | NamesList |
| 12 | NamesList | S→C | `kind`, `truncated` bool, `[name...]` (65536 at most) | |
| 13 | Query | C→S | `sql` str | QueryResult / RequestRefused |
| 14 | QueryResult | S→C | `json` str: `{"columns":[...],"rows":[[...],...]}` | |
+14 -5
View File
@@ -7,7 +7,7 @@ the wire: `protocol.md`.
**Status:** steps 5, 6, 9, 10, 11 and 12: connecting, pushes and their
attachments, messages, attachments, names, queries, retention,
replication, stopping cleanly. Every request of protocol 7 is answered.
replication, stopping cleanly. Every request of protocol 8 is answered.
## Running
@@ -77,7 +77,7 @@ uid 10001.
|---|---|---|
| Connections | tokio, a task each | TLS (`tokio-rustls`, `bakashrot-pki`'s settings), the versions, the identity, then requests one at a time |
| Writes | one writer thread | a queue of every write (pushes, uploads and their parts, replicated messages and parts, retention's deletes); the thread writes whatever is queued in one transaction (group commit, 1000 at most): the busier, the bigger the groups |
| Reads, queries | tokio's blocking threads | a pool of read connections and one of query connections (`query_only`), reused |
| Reads, queries | tokio's blocking threads | a pool of read connections and one of query connections (the file opened read-only, `query_only`), reused |
| WAL checkpoints | one thread, every second | its own connection, off the writer's way (`storage.md`) |
| The CRL file | a task, every 5 s | reloaded when its time or size changes; one that isn't the CA's is refused, the previous one stays; no file: nothing revoked, warned |
| Retention | a task, at start then every `retention_interval` (1 min) | below |
@@ -213,6 +213,15 @@ the same ids with different messages, undetected.
replicated), those the roles may push to or read (every one with
`list_topics` or `query`); nodes are those with messages in the
topics the roles may read (every one with `list_nodes` or `query`). `truncated` past 65,536.
The filters (`topics`, `nodes`: a name or a pattern each) keep the
topics or nodes of the topic and node pairs they match, out of
`reader.heads()`: the topics a node pushed to, the nodes that pushed to
a topic (a pair counts once it had messages, retention's deletions
included). A pair's topic must be one the roles may see when the
answer is topics or `topics` filters it; its node, when the answer is
nodes or `nodes` filters it (`connection.rs`, `list_names`). So a
node filter doesn't tell a client which nodes pushed to a topic it may
only push to.
- **`Query`:** the roles must allow it (`NotAllowed`); read-only SQL,
refused with SQLite's message (`QueryFailed`, with a hint to add
`is_json = 1` on "malformed JSON"), over 10,000 rows or 16 MB
@@ -226,8 +235,8 @@ the same ids with different messages, undetected.
`Client::connect(address, settings)` (`host:port`, the CA's certificate,
the client's certificate and key, the CRL if any), then `push(topic,
data)`, `get_messages(topic, node, after, limit)`, `list_names(kind)`,
`query(sql)`. Blocking, no runtime. The DLL and the bindings over it:
data)`, `get_messages(topic, node, after, limit)`, `list_names(kind,
topics, nodes)`, `query(sql)`. Blocking, no runtime. The DLL and the bindings over it:
`client.md`.
Attachments: `push_with_attachment(topic, data, source)`, the source any
@@ -332,7 +341,7 @@ each:
isn't one line of JSON;
- big messages: five of 600 KB and one of the largest size, one per answer, read back whole; one byte
over refused; a query result over 16 MB refused;
- names: topics by role, nodes;
- names: topics by role, nodes, filtered by names and patterns;
- attachments: 100 KB, 5 MB + 123 bytes, exactly 2 MB, 1 byte, 1 MB, read back and saved; the
messages saying theirs; none, or no such message, refused leaving no
file; another reader, one not allowed; over the server's limit, 0 for
+5 -3
View File
@@ -133,9 +133,11 @@ afterwards, `purge_attachments(max_parts)` a batch at a time.
## The query surface
Clients' `Query` runs on `Database::query_runner()`, read-only three ways:
the connection is `query_only`, the statement must be one SQLite says only
reads, and one statement only (more is refused, not ignored). PRAGMAs are
Clients' `Query` runs on `Database::query_runner()`, read-only four ways:
the file is opened read-only (`SQLITE_OPEN_READONLY`, 2026-11-19: the
handle itself can't write), the connection is `query_only`, the statement
must be one SQLite says only reads, and one statement only (more is
refused, not ignored). PRAGMAs are
refused as they're prepared ("not authorized", SQLite's authorizer), the
`pragma_*` table functions too: some take effect at that point, and
`PRAGMA query_only = 0`, though refused, turned `query_only` off for the