The rewrite's plan and decisions are in revamp.md. Steps 0 to 10 are done: the workspace and checks, bakashrot-proto, bakashrot-pki and bakashrot-cert, bakashrot-config, bakashrot-storage (schema v9), the server and the client library (every request but replication's, attachments and retention included), the C DLL with its C, PureBasic and Python bindings, and the bakashrot tool. Step 11 (replication) is next. OldSource/ is the old implementation, kept building and passing as the reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVTGs2SsufaH6zquzcb
6.1 KiB
One server, one client
The smallest BakaShrot setup: one server on 127.0.0.1:12360, one client
that pushes and reads messages with the tools.
The keys in
server.iniandclient.iniare public, they're in the repository. They're only for trying this example on your own machine (the server only listens on 127.0.0.1). Never reuse them: make your own withBakaShrotGenerateKeyPairs.exe.
Running it
Build first, Build.ps1 at the root, or use a release folder (-BinDir Release\<version> on both scripts). Then, from this folder:
powershell -ExecutionPolicy Bypass -File Start-Server.ps1
powershell -ExecutionPolicy Bypass -File Run-Client.ps1
Start-Server.ps1opens the server in its own window and waits until it listens. Typequitin that window to stop it (helplists the other commands).-Hereruns it in the current console instead,-Resetdeletes its database first, so the ids start from 1 again.Run-Client.ps1goes through what a client does, printing each command before its output. The commands can be pasted as they are from this folder:
== Push a message to the client's default topic (logs, the server's DefaultTopic for it), as node demo
> ..\..\Build\BakaShrotPushMessage.exe @messages\hello.json client.ini
Pushed as message #1
...
== Read the latest message of logs:demo (topic:node, by name)
> ..\..\Build\BakaShrotGetLatestMessage.exe logs demo client.ini
Message logs:demo#2 (ids 1:2), pushed 2026-11-08T21:23:53.590Z
Attachment: 159 bytes
{"level":"info","text":"Daily report, attached"}
The server's database (example.sqlite) and what the client saves
(out\) stay in this folder, git ignores them.
What's in here
| File | What it is |
|---|---|
server.ini |
The server: its key, its names, where it listens, the one client it accepts and what that client may do. Every option is documented in Server/Config/schema.ini. |
client.ini |
The client: its key pair, the node it writes as (demo), and the server's address and public key. Every tool takes it as its last argument. |
Start-Server.ps1 |
Starts the server with server.ini. |
Run-Client.ps1 |
The client's steps, below. |
messages\ |
What the client pushes (hello.json, reading.json, report.json with report.txt attached) and the SQL it runs (query.sql). |
How the two configs fit together
- Keys: each side has a key pair. The server lists the client's public
key in
[BakaShrot.Client.demo] PublicKeys; the client has the server's inServerPublicKey. Every connection is encrypted, and only reaches the server holding the matching private key. - Names: messages are filed under a topic and a node. The topics are
listed in
[BakaShrot.Topics], the nodes come from the sections that define them (server,demo). The server gives each name an id of its own; clients use the names. - Who the client is: its node,
demo, in both configs (Node). Every message it pushes is stored under it. That's why the server checks it: the key proves who's connecting, the server'sNodefor that key says which node it may write as, so no client can push as another's node. - Where its pushes go: the server's
DefaultTopic = logs, unless a push names another topic inPushTopics(-t sensors). Only the server has it:client.inihas no topic. - What it may do: read every topic (
ReadTopics = *,AllowRead), push (AllowWrite), run read-only SQL (AllowQuery). - Retention:
sensorsmessages are kept a day,logsones forever. - Durability:
Synchronous = FULL(the default): every message the server acknowledges is flushed to disk first, so it survives a power cut.NORMALpushes faster but can lose the last second or so of messages then; seeServer/Config/schema.ini.
What the client does
Run-Client.ps1, step by step:
- Pushes
hello.jsontologs, its default topic:BakaShrotPushMessage @messages\hello.json. JSON goes in a file (@file): PowerShell drops the double quotes of an argument. - Pushes
reading.jsontosensors:-t sensors. - Pushes
report.jsonwithreport.txtattached:-a messages\report.txt. - Reads the latest message of
logs:demo:BakaShrotGetLatestMessage logs demo. - Saves the attachment back to
out\report-copy.txtand checks it's the same:BakaShrotGetAttachment logs demo <id> out\report-copy.txt. - Reads every message of
logs:demo, one per line (id, time, data):BakaShrotGetMessages logs demo --time. - Reads
sensors:demo's latest. - Shows the ids the server has for the names:
BakaShrotResolveIds topic sensors,BakaShrotList. - Queries with SQL:
BakaShrotQuery @messages\query.sql, on themessagesview, which has the names.
To watch messages arrive, leave this running and push from another terminal:
..\..\Build\BakaShrotGetMessages.exe logs demo --after latest --follow client.ini
Looking at the database
example.sqlite is a plain SQLite file, the messages view has the
names. To browse one topic in a tool like SQLiteStudio:
- Open the
browsetable: one row. Pick a topic in itstopiccell (a dropdown of the topics, from its foreign key), and a node innodeto narrow it, or leave it NULL for every node. Commit. - Open the
browse_messagesview: that topic's messages, newest first, with their node, id, time (UTC), data and attachment size.
The server never writes browse, so it's safe to change while it runs.
Close the tool when done: an open grid keeps the server from finishing
its checkpoints, and its WAL file grows meanwhile.
From Python
The same client.ini works with the Python client
(Interactors/Python/bakashrot.py, over the DLL). From the repository's
root:
import sys
sys.path.insert(0, r"Interactors\Python")
from bakashrot import Client
with Client.from_ini(r"Examples\SingleServer\client.ini", r"Build\BakaShrot_Client.dll") as client:
print("pushed", client.push({"from": "python"}))
for message in client.get_messages("logs", "demo").messages:
print(message.id, message.json())