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:
@@ -50,6 +50,98 @@ network**, not exposed to the internet. So:
|
||||
between committing and answering) is stored twice if retried. A client
|
||||
that minds reads the latest message before retrying.
|
||||
|
||||
## Found by reading the code, not reproduced
|
||||
|
||||
From a read of the source on 2026-11-15: no test shows any of these yet.
|
||||
Reproduce one before fixing it, and move it up (or drop it) once known.
|
||||
|
||||
- **The server's writes have no timeout.** The 5 min of silence only
|
||||
covers reads (`connection.rs`, `serve`): a client that stops reading
|
||||
in the middle of an answer (an attachment's parts, `get_attachment`)
|
||||
holds its task and its read connection's turn for as long as TCP
|
||||
keeps the connection. Fix: a timeout around `send`, as `PART_TIMEOUT`
|
||||
does for reads.
|
||||
- **`sync_interval` over 5 min.** The server dialed closes the idle link
|
||||
(`IDLE_TIMEOUT`), so every check-in fails once ("closed the link",
|
||||
warned), then the link is dialed again after `retry_delay`. Nothing
|
||||
in the config caps `sync_interval`. Fix: cap it under the idle
|
||||
timeout, or have an idle link ask its `SyncState` more often.
|
||||
- **Resuming a big replicated attachment.** Before answering `Continue`,
|
||||
the receiver reads back and hashes every part it already has
|
||||
(`accept_from.rs`, `replicate_attachment`, `hash_parts`), while the
|
||||
sender waits 30 s for that answer (`push_to.rs`, `ANSWER_TIMEOUT`). On
|
||||
a slow disk, hundreds of parts may take longer: the link drops, and
|
||||
the same happens at every retry. Fix: a longer wait for that answer,
|
||||
or the hash's state kept with the attachment.
|
||||
- **Two peers sending the same attachment at once.** Both can be
|
||||
answered `Continue` for the same `from_part` (the check and the first
|
||||
part written aren't one step). Their parts then interleave in the
|
||||
writer's queue: each part is stored once, from whichever came first,
|
||||
and each sender has one refused (`InvalidRequest`). With few parts (4
|
||||
or fewer in flight, `PARTS_IN_FLIGHT`), all of them can be stored
|
||||
while both senders were refused: neither sends `FinishReplicated`,
|
||||
and the attachment stays `replicating` with `received = size`, asked
|
||||
for and refused at every check-in until a restart (`clean_up` starts
|
||||
it over). Needs two parts at least and a narrow timing: servers that
|
||||
take from two others having the same attachment. Fix: finish it
|
||||
whenever the last part is stored, or one receiver at a time per
|
||||
attachment.
|
||||
- **`SyncState` in one packet** (old item 9). Every head the peer may
|
||||
send goes in one frame of 16 MiB at most: with very many topic and
|
||||
node pairs (hundreds of thousands) it doesn't fit, the packet can't
|
||||
be sent and replication stops. Fix: heads in several packets, or only
|
||||
those that changed.
|
||||
- **Peers with several roles.** `SyncState` lists the union of its
|
||||
roles' `accept_topics` and the union of their `accept_nodes`
|
||||
(`Permissions::accepted`), while what's taken is each role on its
|
||||
own: the sender can offer a topic of one role with a node of another,
|
||||
refused (`NotAllowed`), and sent again, a whole batch, at every
|
||||
check-in. Fix: the pairs per role in `SyncState`, or the sender
|
||||
remembering what was refused.
|
||||
- **A peer can use up a topic and node's ids.** A replicated message
|
||||
may have any id up to the highest (2^43 - 1, `MAX_MESSAGE_ID`), and
|
||||
the stream's last id follows it (`batch.rs`, `replicate`). One such
|
||||
message from a server in `accept_from`, for any topic and node its
|
||||
roles accept, and every later push to that topic by that node is
|
||||
refused ("no message id left", `insert_pushed`); it replicates on to
|
||||
the other servers. Nothing lowers a last id again. Part of "Peers
|
||||
are trusted" above, but one message is enough and a bug can do it.
|
||||
Fix: refuse a batch that doesn't follow the last id here (also closes
|
||||
the gaps), or one that jumps further than some bound.
|
||||
- **A pair refused for good is sent again at every check-in**, a whole
|
||||
batch each time (`push_to.rs`, `send_messages`: a refusal only
|
||||
leaves it for the next check-in): the database's topic and node
|
||||
pairs all used, a message id past the last one. Fix: with "Peers
|
||||
with several roles" above.
|
||||
- **Patterns in `push_topics` let clients make topics.** The roles are
|
||||
the only lists of topics since 2026-11-16 (`config.md`): a client
|
||||
with `push_topics = ["*"]` makes as many topic and node pairs as it
|
||||
likes, up to the database's 2^20 - 1, after which no new pair is
|
||||
taken from anyone. Listing topics also only shows those with
|
||||
messages: a client can't ask what it may push to. Fine for the
|
||||
threat model; names in `push_topics` where the set is closed.
|
||||
- **Every client sees every node's name.** `ListNames` for nodes
|
||||
answers every node with messages (`list_names`, `reader.nodes()`),
|
||||
whatever the client's roles read, to push-only clients too. Topics
|
||||
are filtered by the roles. Fix: only the nodes of the topics it may read, or none
|
||||
without `read_topics` or `query`.
|
||||
- **A CRL file that isn't there.** The server takes it as nothing
|
||||
revoked (`load_revocations`, `bakashrot-server/src/lib.rs`), the
|
||||
`bakashrot` tool refuses to start when `client.toml`'s `crl` names a
|
||||
missing file. Either may be right (a server that starts before its
|
||||
first CRL; a client that must not skip the check): choose one and
|
||||
say it in the docs. A server whose CRL file was deleted by mistake
|
||||
revokes nothing, silently.
|
||||
- **No limits per client.** Any number of connections (each a task and
|
||||
its buffers), any amount pushed: an allowed client can fill the disk
|
||||
or the server's memory. Fine for the threat model; first thing to
|
||||
add if it changes (a cap on connections, a quota per node).
|
||||
- **Small ones:** the client's connect timeout is per socket
|
||||
operation, not for the whole connection; `bakashrot-cert ca` writes
|
||||
`ca.crt` before failing when only `ca.key` is there already; a
|
||||
server whose clock is before 1970 stamps `pushed_at` 0, which
|
||||
readers refuse when decoding.
|
||||
|
||||
## Ideas for later
|
||||
|
||||
From the old benchmarks and suggestions (`OldSource/Design/Suggestions.md`),
|
||||
|
||||
Reference in New Issue
Block a user