diff --git a/CLAUDE.md b/CLAUDE.md index 80502f5..813c92f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -5,16 +5,11 @@ from authenticated clients, store them in SQLite, and replicate them between peers by name. Clients: a C DLL, CLI tools, a Python module. An **internal tool on trusted machines**. -**Rewritten in Rust** (since 2026-11-13): - -- `revamp.md`: why, what's decided, what's proposed and open, the plan and - its status. Read it first. +- `revamp.md`: what's decided, what's proposed and open, the plan and its + status. Read it first. - The implementation is the Cargo workspace at the root (`readme.md`: layout, scripts, conventions; `docs/`: designs, `protocol.md` first, `known-issues.md` for what's left). -- The old PureBasic implementation was removed on 2026-11-15: it's in git - history, `OldSource/` up to commit `68966a8`. Paths starting with - `OldSource/` in the code and docs point there. ## Toolchain @@ -24,13 +19,13 @@ between peers by name. Clients: a C DLL, CLI tools, a Python module. An (`rust-toolchain.toml`, 1.100.0, MSVC; Visual Studio 18 has the linker). - `test.ps1` runs what CI runs; it must pass before a step is done - (`build.ps1`, `release.ps1`, `clean.ps1` beside it, see `readme.md`). + (`build.ps1`, `release.ps1`, `clean.ps1`, `bench.ps1` beside it, see `readme.md`). Run them by absolute path (`-File \test.ps1`): a relative one fails when the shell's folder differs. ## Working rules -- **Commit only when the owner asks**, on a branch (`revamp`), not `master`. +- **Commit only when the owner asks**, on a branch, not `master`. - **Follow the plan's order** (`revamp.md`, "Plan"); a step is done when its tests pass and its docs are updated, then its status goes in the table. - **Decisions go in `revamp.md`**: moved to "Decided" only when the owner diff --git a/bench.ps1 b/bench.ps1 new file mode 100644 index 0000000..79a966a --- /dev/null +++ b/bench.ps1 @@ -0,0 +1,47 @@ +# Runs the benchmarks, release mode: the tests ignored by default. +# push pushes through one server, 10 clients (end_to_end.rs, push_rate) +# replication 4 servers in a Y, pushed to flat out (end_to_end.rs, replication_rate) +# storage the storage alone, pushes then reads (storage.rs, storage_rate) +# docs/server.md and docs/storage.md have the numbers measured so far. +# Usage: powershell -ExecutionPolicy Bypass -File bench.ps1 [-Only push,replication,storage] [-Sync full|normal] +# -Sync sets SQLite's synchronous for all of them (otherwise each one's +# default: full for push and replication, normal for storage). The tests' +# other variables are taken from the environment as they are: PUSHES and +# CLIENTS (push), NODES, SECONDS and BATCH (replication), PUSHES (storage). +param( + [ValidateSet("push", "replication", "storage")] + [string[]]$Only = @("push", "replication", "storage"), + [ValidateSet("full", "normal")] + [string]$Sync +) +$ErrorActionPreference = "Stop" + +# rustup's folder isn't always on the PATH (it isn't in every shell here). +if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) { + $env:PATH = (Join-Path $env:USERPROFILE ".cargo\bin") + [IO.Path]::PathSeparator + $env:PATH +} + +# What -Only names, in this order: the package, the test file, the test. +$benches = [ordered]@{ + push = @("bakashrot-server", "end_to_end", "push_rate") + replication = @("bakashrot-server", "end_to_end", "replication_rate") + storage = @("bakashrot-storage", "storage", "storage_rate") +} + +$oldSync = $env:SYNC +if ($Sync) { $env:SYNC = $Sync } +Push-Location $PSScriptRoot +try { + foreach ($name in $benches.Keys) { + if ($Only -notcontains $name) { continue } + $package, $file, $test = $benches[$name] + "== $name ($test)" + cargo test --locked --release -p $package --test $file $test -- --ignored --exact --nocapture + if ($LASTEXITCODE -ne 0) { "FAILED: $name"; exit 1 } + } +} finally { + Pop-Location + $env:SYNC = $oldSync +} +"Benchmarks done" +exit 0 diff --git a/bindings/c/bakashrot.h b/bindings/c/bakashrot.h index e2524c1..5553e2a 100644 --- a/bindings/c/bakashrot.h +++ b/bindings/c/bakashrot.h @@ -70,8 +70,8 @@ ptrdiff_t BakaShrot_SetPrivateKeyW(const uint16_t *key); /** * Sets the CA's CRL, optional: servers it revokes are refused. PEM text, - * or the path of a file holding it; null or empty for none. Before - * connecting. + * or the path of a file holding it (one that isn't there is a + * `FileError`); null or empty for none. Before connecting. */ ptrdiff_t BakaShrot_SetCrlA(const char *crl); diff --git a/bindings/purebasic/BakaShrot_Client_Prototypes.pbi b/bindings/purebasic/BakaShrot_Client_Prototypes.pbi index c77e94a..1308748 100644 --- a/bindings/purebasic/BakaShrot_Client_Prototypes.pbi +++ b/bindings/purebasic/BakaShrot_Client_Prototypes.pbi @@ -34,16 +34,8 @@ ; call, BakaShrot_GetLastError() tells why: the codes and what to do about ; each are in BakaShrot_ErrorCodes.pbi, next to this file (included below), ; BakaShrot_ErrorName() names them; BakaShrot_GetRefusalReasonString() says -; why in words. -; -; Changed from the PureBasic DLL (protocol 6): certificates instead of keys -; and a node (BakaShrot_SetCaCertificate(), _SetCertificate(), -; _SetPrivateKey() now a PEM key, _SetCrl()); a push always names its topic -; (BakaShrot_PushMessage() is gone); no ids (_GetLatestMessage(TopicId, -; NodeId), _SetNodeId(), _GetMessageTopicId/NodeId(), _ResolveTopic/Node(), -; _GetResolvedName() are gone); _GetNamesList() is -; {"kind":"topic","names":[...],"truncated":false}. New: _GetNode(). -; Attachments: the same six as before, by names. +; why in words. _GetNamesList() is +; {"kind":"topic","names":[...],"truncated":false}. ; ============================================================================ XIncludeFile "BakaShrot_ErrorCodes.pbi" diff --git a/bindings/purebasic/BakaShrot_ErrorCodes.pbi b/bindings/purebasic/BakaShrot_ErrorCodes.pbi index 5700f6e..2c164fb 100644 --- a/bindings/purebasic/BakaShrot_ErrorCodes.pbi +++ b/bindings/purebasic/BakaShrot_ErrorCodes.pbi @@ -17,7 +17,7 @@ ; ; What BakaShrot_GetLastError() returns after a failed call of the client DLL ; (bakashrot.dll), and the code a server sends with each refusal (protocol 7, -; crates/bakashrot-proto/src/error.rs, the same numbers as protocol 6). +; crates/bakashrot-proto/src/error.rs). ; The Python client has them in bakashrot.ErrorCode. Shipped next to ; BakaShrot_Client_Prototypes.pbi, which includes it. ; @@ -58,8 +58,6 @@ ; A message, attachment or query result over a limit, or an attachment ; bigger than this server keeps. #BakaShrot_Refused_TooBig = 5 -; Protocol 6's (a push without a topic): never sent any more. -#BakaShrot_Refused_NoDefaultTopic = 6 ; A request that doesn't fit: an attachment's parts not matching its size, ; a part that doesn't exist... #BakaShrot_Refused_InvalidRequest = 7 @@ -117,7 +115,6 @@ Procedure.s BakaShrot_ErrorName(Code.l) Case #BakaShrot_Refused_NotFound : ProcedureReturn "NotFound" Case #BakaShrot_Refused_NotReady : ProcedureReturn "NotReady" Case #BakaShrot_Refused_TooBig : ProcedureReturn "TooBig" - Case #BakaShrot_Refused_NoDefaultTopic : ProcedureReturn "NoDefaultTopic" Case #BakaShrot_Refused_InvalidRequest : ProcedureReturn "InvalidRequest" Case #BakaShrot_Refused_DataMismatch : ProcedureReturn "DataMismatch" Case #BakaShrot_Refused_QueryFailed : ProcedureReturn "QueryFailed" diff --git a/bindings/python/bakashrot.py b/bindings/python/bakashrot.py index 36ad824..c85b635 100644 --- a/bindings/python/bakashrot.py +++ b/bindings/python/bakashrot.py @@ -83,7 +83,6 @@ class ErrorCode(enum.IntEnum): NOT_FOUND = 3 # no such message or attachment NOT_READY = 4 # the attachment isn't on this server yet: retry later TOO_BIG = 5 # over a limit, or more than this server keeps - NO_DEFAULT_TOPIC = 6 # protocol 6's, never sent any more INVALID_REQUEST = 7 # a request that doesn't fit (parts out of order...) DATA_MISMATCH = 8 # an upload that doesn't match its SHA-256 QUERY_FAILED = 9 # the SQL failed @@ -326,8 +325,8 @@ class Client: @classmethod def from_file(cls, path: Union[str, os.PathLike], dll_path: Optional[str] = None) -> "Client": """From a client.toml (server, ca, certificate, key, crl), the tools' - too; paths in it are relative to its folder. Needs Python 3.11+ - (tomllib).""" + too; paths in it are relative to its folder, a crl whose file isn't + there yet is none. Needs Python 3.11+ (tomllib).""" import tomllib try: @@ -351,7 +350,10 @@ class Client: value = get(key, required) return os.path.join(folder, value) if value else None - return cls(get("server"), file("ca"), file("certificate"), file("key"), file("crl", False), dll_path) + # No CRL file yet: nothing revoked, as with the tools and the server. + crl = file("crl", False) + crl = crl if crl and os.path.exists(crl) else None + return cls(get("server"), file("ca"), file("certificate"), file("key"), crl, dll_path) # --- Connection -------------------------------------------------------- diff --git a/bindings/python/check_bakashrot.py b/bindings/python/check_bakashrot.py index 6e1ca79..baf7e28 100644 --- a/bindings/python/check_bakashrot.py +++ b/bindings/python/check_bakashrot.py @@ -227,6 +227,15 @@ check("None of its roles allowed: AuthError, NOT_ALLOWED", ok, detail) missing = Client(f"{kitchen.host}:{kitchen.port}", os.path.join(folder, "missing.crt"), *pem[1:], dll_path=dll_path) ok, detail = raises(missing.connect, BakaShrotError, "missing.crt", ErrorCode.FILE_ERROR) check("A certificate file that isn't there: FILE_ERROR", ok, detail) +missing = Client(f"{kitchen.host}:{kitchen.port}", *pem, crl=os.path.join(folder, "missing.crl"), dll_path=dll_path) +ok, detail = raises(missing.connect, BakaShrotError, "missing.crl", ErrorCode.FILE_ERROR) +check("A CRL file given that isn't there: FILE_ERROR", ok, detail) +with open(os.path.join(folder, "kitchen.toml")) as settings: + no_crl_yet = settings.read() + '\ncrl = "missing.crl"\n' +with open(os.path.join(folder, "no-crl-yet.toml"), "w") as settings: + settings.write(no_crl_yet) +with Client.from_file(os.path.join(folder, "no-crl-yet.toml"), dll_path) as again: + check("A client.toml's CRL file not there yet: none, connected", again.connected, again.crl) with Client(f"{kitchen.host}:{kitchen.port}", *pem, dll_path=dll_path) as again: check("The same identity from PEM text: connected", again.connected and again.node == "kitchen", again.node) diff --git a/building.md b/building.md new file mode 100644 index 0000000..bd963fc --- /dev/null +++ b/building.md @@ -0,0 +1,90 @@ +# BakaShrot - Building + +## Compilation +Requires [rustup](https://rustup.rs) (it installs the pinned toolchain, [rust-toolchain.toml](rust-toolchain.toml), +by itself; on Windows, Visual Studio's C++ tools for the linker) and Python 3.11+ for releases. + +From the repository's root, on Windows (`powershell -ExecutionPolicy Bypass -File