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

Added bench.ps1, Made a CRL file not there yet revoke nothing for clients too

- bench.ps1 runs the benchmarks (push_rate, replication_rate,
  compare_with_old) in release mode: -Only, -Sync full|normal. Plan
  step 13 done, every step of the plan is.
- A CRL file named in client.toml that isn't there yet: nothing revoked
  (the tool, Python's from_file), as on the server, which now warns in
  its log. A path given to the DLL's SetCrl or Client(crl=...) stays a
  FileError. Decided in revamp.md, dropped from known-issues.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 10:36:59 +01:00
parent 34eb6f4600
commit 39ba7fce6c
18 changed files with 115 additions and 31 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ 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 <repo>\test.ps1`): a relative one
fails when the shell's folder differs.
+47
View File
@@ -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, the old storage's workload (storage.rs, compare_with_old)
# 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", "compare_with_old")
}
$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
+2 -2
View File
@@ -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);
+6 -3
View File
@@ -326,8 +326,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 +351,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 --------------------------------------------------------
+9
View File
@@ -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)
+2 -2
View File
@@ -288,8 +288,8 @@ pub unsafe extern "C" fn BakaShrot_SetPrivateKeyW(key: *const u16) -> isize {
}
/// 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.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn BakaShrot_SetCrlA(crl: *const c_char) -> isize {
unsafe { set::<Utf8>(crl.cast(), "CRL", true, |state| &mut state.crl) }
+3
View File
@@ -85,6 +85,9 @@ fn exports() {
BakaShrot_SetPrivateKeyA(a(&file("kitchen.key")).as_ptr()),
1
);
// A CRL file asked for is needed (client.toml's may be missing).
assert_eq!(BakaShrot_SetCrlW(w(&file("missing.crl")).as_ptr()), 0);
assert_eq!(error().0, code(ErrorCode::FileError));
assert_eq!(BakaShrot_SetCrlW(std::ptr::null()), 1);
assert_eq!(BakaShrot_ConnectW(localhost.as_ptr(), 0), 0);
assert_eq!(error().0, code(ErrorCode::InvalidArgument));
+1 -1
View File
@@ -74,7 +74,7 @@ pub struct Server {
pub certificate: PathBuf,
/// The server's key.
pub key: PathBuf,
/// The CA's CRL, watched; none: nothing revoked.
/// The CA's CRL, watched; none, or no such file: nothing revoked.
#[serde(default)]
pub crl: Option<PathBuf>,
/// The SQLite database; `bakashrot.sqlite` by default.
+7 -2
View File
@@ -294,11 +294,16 @@ fn read(path: &Path) -> Result<String, String> {
std::fs::read_to_string(path).map_err(|error| format!("{}: {error}", path.display()))
}
/// The CRL file's revocations; none without one (no file, or not set).
/// The CRL file's revocations; none without one (not set, or no file:
/// warned, a CRL deleted by mistake would revoke nothing silently).
fn load_revocations(path: Option<&Path>, ca: &str) -> Result<Revocations, String> {
let Some(path) = path.filter(|path| path.exists()) else {
let Some(path) = path else {
return Ok(Revocations::none());
};
if !path.exists() {
warn!("{}: no such file, nothing revoked", path.display());
return Ok(Revocations::none());
}
Revocations::load(&read(path)?, ca).map_err(|error| format!("{}: {error}", path.display()))
}
@@ -316,9 +316,11 @@ fn connect(config: &Path) -> Result<Client, String> {
let ca = pem("CA's certificate", &settings.ca)?;
let certificate = pem("certificate", &settings.certificate)?;
let key = pem("key", &settings.key)?;
// No CRL file yet: nothing revoked, as on the server.
let crl = settings
.crl
.as_deref()
.filter(|path| folder.join(path).exists())
.map(|path| pem("CRL", path))
.transpose()?;
let pems = Settings {
+5 -1
View File
@@ -550,7 +550,11 @@ fn settings() {
format!("{kitchen}crl = \"none.crl\"\n"),
)
.unwrap();
run(folder, "crl", &["list"], None).fails(1, "Can't read the CRL");
// No CRL file yet: nothing revoked. One that isn't a CRL is refused.
let none = run(folder, "crl", &["list", "topics"], None);
assert_eq!(none.ok().out, "Topics (0):\n");
fs::write(folder.join("none.crl"), "not a CRL").unwrap();
run(folder, "crl", &["list"], None).fails(1, "the CRL");
let closed = kitchen.replace(&server.port.to_string(), "1");
fs::write(folder.join("closed.toml"), closed).unwrap();
run(folder, "closed", &["list"], None)
+6 -3
View File
@@ -77,9 +77,12 @@ connected, `peer_identity()` gives the other end's `Identity`.
handshake, no new configuration needed. `Revocations::revokes()` tells
the server which open connections to drop.
- **Both ends check it:** `server_config()` and `client_config()` both take
the revocations (`Revocations::none()` without a CRL). A server dialing
its peer is the peer's client, with the same CRL: servers block each
other, whichever end dials.
the revocations (`Revocations::none()` without a CRL, or when the
server's config or `client.toml` names a CRL file that isn't there
yet: never blocking, the server warns in its log; a path given to
the DLL is a `FileError`). A server dialing its peer is the peer's
client, with the same CRL: servers block each other, whichever end
dials.
- **Revoking is by certificate, not by name:** each certificate has its own
key and its own serial number (made from that key), so two of the same
name (two servers named alike, a new one before the old one goes) are
+1 -1
View File
@@ -35,7 +35,7 @@ server = "10.0.0.2:7000" # host:port, [an IPv6 address]:port
ca = "ca.crt"
certificate = "kitchen.crt"
key = "kitchen.key"
crl = "ca.crl" # optional
crl = "ca.crl" # optional; a file not there yet: none
```
## The DLL
-7
View File
@@ -123,13 +123,6 @@ Reproduce one before fixing it, and move it up (or drop it) once known.
`GetMessages` answers `UnknownName` for a node without messages
anywhere and none for one with messages in another topic
(`reader.rs`, `messages`). Fix: none in both cases.
- **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
+4 -1
View File
@@ -77,7 +77,7 @@ beside it, on `debian:trixie-slim`, as uid 10001.
| 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 |
| 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 |
| 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 |
| Replication | a task per server of `push_to` | below: links kept up, a check-in every `sync_interval` (5 s) |
@@ -238,6 +238,9 @@ server's, `ConnectionLost`, `ProtocolError`, `InvalidArgument`,
## Measured
`bench.ps1` at the root runs these benchmarks (`-Only push,replication`,
`-Sync full|normal`; the variables below from the environment).
`push_rate` (`tests/end_to_end.rs`, ignored by default): a whole server on
localhost, 10 clients each its own node (`CLIENTS`), one push at a time
each, 200-byte JSON, 20,000 pushes per client.
+3 -2
View File
@@ -220,8 +220,9 @@ over 500 streams picked at random, 100 per transaction, 200-byte JSON;
middle id; retention of 10% of one topic. The new side is
`compare_with_old` (`tests/storage.rs`, ignored by default:
`PUSHES=1000000 SYNC=normal cargo test --release -p bakashrot-storage --
--ignored --nocapture`). The old side calls `OldSource`'s writer
(`BakaShrot_Writer_WriteJobs()`, its group commit, PureBasic 5.73, SQLite
--ignored --nocapture`, or `bench.ps1 -Only storage`). The old side
calls `OldSource`'s writer (`BakaShrot_Writer_WriteJobs()`, its group
commit, PureBasic 5.73, SQLite
3.54.1 from `sqlite3.dll`), from a program built outside `OldSource`.
Same machine, NVMe, one run each.
+4 -2
View File
@@ -35,8 +35,10 @@ From the repository's root, on Windows (`powershell -ExecutionPolicy Bypass -Fil
| `test.ps1` | What CI runs: formatting, clippy (warnings are errors), the tests, the docs |
| `release.ps1` | A release for this platform, smoke-tested (`release.py`, below); `-SkipTest` |
| `clean.ps1` | Deletes `target\` (builds and releases) |
| `bench.ps1` | The benchmarks, release mode: pushes, replication, storage (`docs/server.md`, "Measured"); `-Only`, `-Sync full` or `normal` |
Elsewhere, the same with cargo: `cargo build --release`, `cargo test`, `python release.py`, `cargo clean`.
Elsewhere, the same with cargo: `cargo build --release`, `cargo test`, `python release.py`, `cargo clean`;
the benchmarks are ignored tests (`cargo test --release -- --ignored`).
Generated keys and certificates never go in git.
@@ -46,7 +48,7 @@ A Cargo workspace:
```
Cargo.toml the workspace: shared lints, release profile
rust-toolchain.toml the pinned toolchain (1.100.0)
build.ps1, test.ps1, release.ps1, clean.ps1
build.ps1, test.ps1, release.ps1, clean.ps1, bench.ps1
release.py a release for this platform: build, package, smoke test
docs/ designs across crates: protocol.md, certificates.md, oid.md, config.md,
storage.md, server.md, client.md, known-issues.md, lab.md (a test lab, step by step)
+12 -3
View File
@@ -1,12 +1,13 @@
# BakaShrot revamp
Started 2026-11-13: what it should change, what's decided, what's still
open, and the plan. Steps 0 to 12 of the plan are done (the workspace,
open, and the plan. Every step of the plan is done (the workspace,
`bakashrot-proto`, `bakashrot-pki` and `bakashrot-cert`,
`bakashrot-config`, `bakashrot-storage`, `bakashrot-server` and
`bakashrot-client` answering every request, attachments included, the C
DLL with its C, PureBasic and Python bindings, the `bakashrot` tool,
retention, replication, operations and releases), see "Plan".
retention, replication, operations and releases, then the finish: one
test runner, CI, Docker, `bench.ps1`), see "Plan".
- **Old implementation:** PureBasic, protocol 6, schema v8. Removed on
2026-11-15 ("The PureBasic version removed"): it's in git history,
@@ -135,6 +136,14 @@ Also decided (2026-11-13):
drops the connections whose certificate it now revokes;
- a new file that doesn't verify is refused, the previous one kept and
the refusal logged; no file means nothing revoked;
- **a CRL file that isn't there** (2026-11-16): nothing revoked, on
both ends, never blocking, where it's a setting: the server's
config (warned in its log: a CRL deleted by mistake) and
`client.toml` (the tool, Python's `from_file()`). A path given
to the DLL's `SetCrl` or Python's `Client(crl=...)` is asked for
explicitly: missing, it's a `FileError`. `bakashrot-cert revoke`
needs no file to start from (it writes the first one). A file
that's there but can't be read or isn't the CA's is refused;
- clients check it too when given one (`client_config()` takes the
same revocations): a server dialing its peer is a client, so servers
block each other whichever end dials;
@@ -394,7 +403,7 @@ hand in each).
| 10 | Retention | Background deletion, `node_heads` kept, attachments cleaned up | `Retention-Test`'s local checks | | Done 2026-11-14 |
| 11 | Replication | Peer links, sync state, batches by name, wildcards, attachments, skipping on arrival | `Names-Test` (replication), `Restart-Test`; the corrupted-attachment fix | Decided 2026-11-14 | Done 2026-11-14 |
| 12 | Operations | Signals and a clean stop, logs, release, wheel | Runs unattended, stops cleanly, the release's smoke test | Decided 2026-11-14 | Done 2026-11-14 |
| 13 | Finish | One test runner (the Rust tests, decided 2026-11-15), end-to-end tests in CI, the bench, Docker | Push speed against the old ~17,000 msg/s (4 servers, measured 2026-11-14: `docs/server.md`) | | |
| 13 | Finish | One test runner (the Rust tests, decided 2026-11-15), end-to-end tests in CI, the bench, Docker | Push speed against the old ~17,000 msg/s (4 servers, measured 2026-11-14: `docs/server.md`) | | Done 2026-11-16 (`bench.ps1`) |
Each step ends with its tests passing and its docs updated (the crate's
docs, `docs/`, this file's status), then a commit when the owner