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

Stopped long queries, Read is_open() through TLS, Simplified answers and paging

- [server] query_time_limit (20 s by default) stops a client's query
  through SQLite's progress handler: refused with QueryTimedOut (11). A
  client closing while its query runs stops it too.
- The answer timeout in the DLL (BakaShrot_SetAnswerTimeout /
  GetAnswerTimeout, kept across connections), Python (answer_timeout)
  and C# (AnswerTimeoutMs); QueryTimedOut in every binding.
- is_open() reads what's waiting through TLS: a close_notify says
  closed, TLS's own records keep it open, unasked data or a broken
  stream close it.
- The Rust client checks an answer's type in one place (TryFrom per
  packet); Client::wait() pings while waiting (the tool's --follow).
- Pair::from(&Head), heads_after taking a Pair; simpler SyncState
  paging on both ends; the writer's redundant rollback check dropped.
- codes.rs: the bindings' error codes and copied values match Rust's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 12:17:28 +01:00
parent a6ade535d0
commit 1bae8ee182
37 changed files with 1064 additions and 264 deletions
+33 -8
View File
@@ -37,11 +37,20 @@ works; Python and C# go through it.
- `set_answer_timeout()`: how long an answer, or sending a packet, may
take: 30 s (`ANSWER_TIMEOUT`) until changed, more than 0. Longer for a
slow query, say.
- `is_open()`: false once closed; it looks at the socket without
blocking, then always makes it blocking again (it was left
non-blocking when it found the connection gone).
slow query, say (the server's own limit, `query_time_limit`, is 20 s
by default: `config.md`). Giving up closes the connection, and the
server stops the query it was running then.
- `is_open()` (`&mut self`): false once closed. It reads what's waiting
without blocking, through TLS, then always makes the socket blocking
again (it was left non-blocking when it found the connection gone).
What TLS sends for itself (session tickets, key updates) leaves it
open; the socket's end or TLS's close_notify says the server closed it
(the next request fails with `ConnectionLost`); data sent unasked or a
broken TLS stream leave it out of step, so it's closed (`NotConnected`
after).
- `ping()`: keeps an idle connection open (`protocol.md`, "Rules").
`wait()` sleeps, pinging every `KEEPALIVE_SECS` meanwhile (the
tool's `--follow` uses it).
## Who connects: certificates
@@ -102,6 +111,7 @@ a client's, or an enumeration's for the enumeration getters.
| `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 |
| `Ping` | 1, or 0 if the connection is gone: keeps it open. The server closes one silent for 5 min; the DLL has no thread of its own, so an app idle longer calls it every minute or so |
| `SetAnswerTimeout(Milliseconds)`, `GetAnswerTimeout` | how long an answer may take: 30000 until changed, more than 0 (`InvalidArgument`). Kept across connections, and applied to the current one too (unlike the other settings). Past it, `ConnectionLost`, the connection closed and the server's query stopped |
| `GetNode` (`A`/`W`) | the node the server says this client is |
| `PushMessageTo(Topic, Data)` (`A`/`W`) | the id, -1 on failure |
| `GetLatestMessageOf(Topic, Node)` (`A`/`W`) | 1, or 0 with `NotFound` when there's none yet |
@@ -149,6 +159,8 @@ 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()` (pinging
every minute while it waits longer), `ping()` (`KEEPALIVE_SECONDS`),
`answer_timeout` (seconds, `ANSWER_TIMEOUT_SECONDS` until set; before
connecting or while connected),
`get_attachment()` (bytes), `save_attachment()` (a file),
`list_topics()` / `list_nodes()` (names; `topic=` and `node=`, a name or
a pattern each, filter them: `list_topics(node="kitchen")` the topics
@@ -194,6 +206,7 @@ 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()`
(pinging every minute while it waits longer), `Ping()` (`KeepAliveMs`),
`AnswerTimeoutMs` (`DefaultAnswerTimeoutMs` until set),
`GetAttachment()` (bytes), `SaveAttachment()` (a file), `ListTopics()` /
`ListNodes()` / `Query()` (the library's JSON, as a string: parsing it
is the app's; `ListTopics(topic, node)` / `ListNodes(topic, node)`
@@ -275,8 +288,11 @@ wrong size, a refusal among the parts, a source failing mid-upload, a
connection the server closed (each: closed, `NotConnected` after,
nothing more sent); a refusal and an argument refused before sending
keeping it; a longer timeout waiting for a slow answer; `is_open()`
leaving it blocking. Each closing path broken on purpose once: the
tests caught it.
leaving it blocking, noticing a close_notify with the socket still open,
closing on data sent unasked or a broken TLS stream, and staying open
past a key update (the next request under the new keys). Each closing
path broken on purpose once: the tests caught it (`is_open()` five ways,
2026-11-20, the old socket peek among them).
`crates/bakashrot-capi/tests/`, each against a server on a free port:
@@ -288,12 +304,20 @@ tests caught it.
- `exports.rs`, `clients`: two clients at once, each with its own answers
and errors; bad and freed handles; 4 threads on 4 clients; a client
freed while another thread uses it.
- `exports.rs`, `answer_timeouts`: the answer timeout refused at 0 or
less, kept across connections; a query past it `ConnectionLost`.
- `codes.rs`: Python's, C#'s and PureBasic's error codes are the
protocol's (`error.rs`), every one by the same number and name; the
values Python and C# copy (the answer timeout, the keepalive,
`MAX_GET_MESSAGES`) are the Rust side's.
- `python.rs`: runs `bindings/python/check_bakashrot.py` on the DLL (two
`Client`s at once, too); skipped, saying so, without Python 3.11+.
- PureBasic, by hand (no PureBasic in CI): run
`BakaShrot_Client_Prototypes.pbi` directly, `ClientExample <DllPath>
<CaFile> <CertificateFile> <KeyFile> <Host> <Port>`. Passed 2026-11-17
with PureBasic 5.73 LTS and 6.41 (C backend), x64.
with PureBasic 5.73 LTS and 6.41 (C backend), x64. 2026-11-20, both
again: the answer timeout exports and `QueryTimedOut` (11) through
the DLL against a server with `query_time_limit = "1s"`.
- C#, by hand (not in `test.ps1`): `cargo build`, then `dotnet test
bindings/csharp/NibblePoker.BakaShrot.Client.Tests` (NUnit). Its `[SetUpFixture]`
makes the certificates with `target/debug`'s `bakashrot cert`
@@ -301,7 +325,8 @@ tests caught it.
port in `target/csharp-tests/`, copies the library next to the tests.
On `net48` (the `net35` build) and `net8.0` (`netstandard2.0`), on Linux
`net8.0` only. Passed 2026-11-18 on both, and on `net11.0`
(`-p:TargetFrameworks=net11.0`).
(`-p:TargetFrameworks=net11.0`); 2026-11-20 on both again
(`AnswerTimeouts`).
- `header.rs`: `bindings/c/bakashrot.h` matches the exports (rewritten
when it doesn't: check it in).
+10
View File
@@ -105,6 +105,16 @@ idle ones each pool keeps; more are closed as they're put back, and an
idle one is closed after a minute unused (looked at every 10 s). 0 opens
one per request.
## Query time limit
`[server] query_time_limit` (20 s by default) is how long a client's
query may run. Past it, SQLite stops it (it looks every 10,000 steps, a
fraction of a millisecond) and the client is refused with `QueryTimedOut` (11):
"stopped after 20s, the server's time limit". Keep it under the clients'
answer timeout (30 s by default; `BakaShrot_SetAnswerTimeout()`), or they
give up first. A client that gives up closes its connection, and the
server stops its query then too (`protocol.md`, "Rules").
## Retention
A topic takes its name's line, else the first pattern matching it in the
+4 -1
View File
@@ -157,7 +157,10 @@ Keeping alive C: Ping (every minute while idle) S: Pong
## Rules
- **One request at a time:** a client sends one, waits for its answer (the
parts of an attachment being part of its request or answer).
parts of an attachment being part of its request or answer). While a
`Query` runs, anything from the client (its closing, having given up
waiting) stops the query and closes the connection (2026-11-20); the
server's own limit stops it past `query_time_limit` (`QueryTimedOut`).
- **Silence:** the server closes a connection with no request for
`IDLE_TIMEOUT_SECS` (5 min). An end waiting longer between requests
sends a `Ping` every `KEEPALIVE_SECS` (1 min) meanwhile (added
+8 -1
View File
@@ -184,7 +184,8 @@ the same ids with different messages, undetected.
| TLS, versions, welcome | 10 s (the server); the client's connect too |
| Silence between requests | 5 min, then the server closes (a `Ping` is a request: links and follows send one every minute while they wait) |
| A packet sent (an answer, an attachment's part, to a peer too) | 30 s (the server), then it closes: a client that stopped reading doesn't hold a connection |
| An answer | 30 s (the client) |
| An answer | 30 s (the client; `set_answer_timeout()`, `BakaShrot_SetAnswerTimeout()`), then it closes: the server stops the query it was running |
| A query | 20 s (`[server] query_time_limit`), then SQLite stops it: `QueryTimedOut` |
| An attachment's next part | 30 s (the server), then it closes |
## Requests so far
@@ -232,6 +233,10 @@ the same ids with different messages, undetected.
refused with SQLite's message (`QueryFailed`, with a hint to add
`is_json = 1` on "malformed JSON"), over 10,000 rows or 16 MB
(`TooBig`), never a partial result (`storage.md`, "The query surface").
Stopped past `query_time_limit` (`QueryTimedOut`, "stopped after 20s,
the server's time limit"), or when the client closes meanwhile (it
gave up): its thread isn't left running. `Server::queries_running()`
says how many run.
- **Sizes:** frames up to 16 MB (`MAX_PACKET_SIZE`), a bigger one drops the
connection; messages up to `MAX_MESSAGE_SIZE` (16 MB less 4 KB), the
server refusing bigger ones (`TooBig`); the client refuses messages and
@@ -358,6 +363,8 @@ each:
part on, something else than a part (closed, dropped);
- queries: not allowed, results, a non-JSON row
refused with the hint, errors, writes and two statements refused;
one past `query_time_limit` refused, the connection kept; one whose
client gave up first stopped (`queries_are_stopped`);
- refusals keeping the connection (not allowed, unknown topic, a bad name
the client catches);
- certificates refused (no known role, with why; another CA's client; a
+1 -3
View File
@@ -74,7 +74,7 @@ batch goes on after one fails: the server queues pushes and stores them
together, one disk flush for all.
Except when SQLite rolls the whole transaction back by itself, which it
may on a full disk, an I/O error or out of memory (`Batch::is_rolled_back()`).
may on a full disk, an I/O error or out of memory.
What came after then ran outside any transaction, each operation
committed alone, while the batch failed and every write in it was
answered as failed: a retried push stored twice. Since 2026-11-19 every
@@ -271,7 +271,5 @@ big), the view's plans, and readers with two writers at once. In
- **A time index**, if time queries over big streams get slow: a v10
migration adding an index on `(stream_id, pushed_at)` and joining the
view on it too (measured above: twice the write cost).
- **Interrupting long queries** (a time limit): the server's, with
SQLite's interrupt.
- **Attachments as files** next to the database instead of in it, if their
size calls for it.