diff --git a/Source/.cargo/config.toml b/.cargo/config.toml similarity index 100% rename from Source/.cargo/config.toml rename to .cargo/config.toml diff --git a/Source/.gitattributes b/.gitattributes similarity index 100% rename from Source/.gitattributes rename to .gitattributes diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fa6f6a5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,142 @@ +# On a version tag, or run by hand: the same checks as test.ps1 (Windows +# and Linux), then a release for each platform (release.py), its archive +# kept as the run's artifact, and the server's Docker image for amd64 and +# arm64, checked (docker/test.sh), pushed to ghcr.io on a tag only. Gitea +# Actions runs this file too. +name: CI + +on: + push: + tags: ["v*"] + workflow_dispatch: + +env: + IMAGE: ghcr.io/aziascreations/bakashrot-server + +jobs: + check: + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + # Installs the toolchain rust-toolchain.toml pins. + - run: rustup toolchain install + - run: cargo fmt --all -- --check + - run: cargo clippy --workspace --all-targets --all-features -- -D warnings + - run: cargo test --workspace --all-features + - run: cargo doc --workspace --no-deps --all-features + env: + RUSTDOCFLAGS: -D warnings + + release: + # Build, package, smoke test, each on its own kind of machine: no + # cross-compiling, and the smoke test runs where the release will. + # Linux builds in manylinux 2.28 (glibc 2.28): the programs, the .so + # and the wheel run on systems that old. + needs: check + strategy: + fail-fast: false + matrix: + include: + - platform: windows-x64 + os: windows-latest + arch: x64 + - platform: windows-arm64 + # aws-lc needs clang-cl there: Visual Studio's, on this image. + os: windows-11-arm + arch: arm64 + - platform: linux-x64 + os: ubuntu-latest + container: quay.io/pypa/manylinux_2_28_x86_64 + - platform: linux-arm64 + os: ubuntu-24.04-arm + container: quay.io/pypa/manylinux_2_28_aarch64 + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + # Windows: a Python of the machine's architecture (the smoke test + # loads the DLL into it). Linux: the container's. + - if: ${{ !matrix.container }} + uses: actions/setup-python@v5 + with: + python-version: "3.12" + architecture: ${{ matrix.arch }} + - if: ${{ matrix.container }} + run: echo "/opt/python/cp312-cp312/bin" >> "$GITHUB_PATH" + # rustup, where the image has none. + - run: | + if ! command -v rustup; then + if [ "$RUNNER_OS" = Windows ]; then + curl --proto '=https' -sSfo rustup-init.exe https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe + ./rustup-init.exe -y --default-toolchain none + rm rustup-init.exe + echo "$USERPROFILE/.cargo/bin" >> "$GITHUB_PATH" + else + curl --proto '=https' -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none + echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" + fi + fi + - run: rustup toolchain install + - run: python release.py + - uses: actions/upload-artifact@v4 + with: + name: bakashrot-${{ matrix.platform }} + path: | + target/dist/*.zip + target/dist/*.tar.gz + if-no-files-found: error + + docker: + # The server's image, each architecture built on its own kind of + # machine (no emulation), checked, then pushed as - on a + # tag. Run by hand, it's built and checked only. + needs: check + strategy: + fail-fast: false + matrix: + include: + - arch: amd64 + os: ubuntu-latest + - arch: arm64 + os: ubuntu-24.04-arm + runs-on: ${{ matrix.os }} + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - run: | + if [ "$GITHUB_REF_TYPE" = tag ]; then version=${GITHUB_REF_NAME#v}; else version=manual; fi + echo "TAG=$IMAGE:$version-${{ matrix.arch }}" >> "$GITHUB_ENV" + - run: docker build -f docker/Dockerfile -t "$TAG" . + - run: sh docker/test.sh "$TAG" + - if: github.ref_type == 'tag' + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + docker push "$TAG" + + docker-index: + # One image for both architectures, and latest: an index of + # the two, once the releases passed too. GitHub reads the source label + # on an index from its annotations. + if: github.ref_type == 'tag' + needs: [docker, release] + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + version=${GITHUB_REF_NAME#v} + docker buildx imagetools create -t "$IMAGE:$version" -t "$IMAGE:latest" \ + --annotation "index:org.opencontainers.image.source=https://github.com/aziascreations/BakaShrot" \ + --annotation "index:org.opencontainers.image.description=BakaShrot server" \ + --annotation "index:org.opencontainers.image.licenses=CC0-1.0" \ + "$IMAGE:$version-amd64" "$IMAGE:$version-arm64" diff --git a/.github/workflows/source.yml b/.github/workflows/source.yml deleted file mode 100644 index 5290283..0000000 --- a/.github/workflows/source.yml +++ /dev/null @@ -1,71 +0,0 @@ -# The new sources (Source/): the same checks as Source/check.ps1, on Windows -# and Linux; a release of each (Source/release.py) on a version tag or when -# run by hand. Gitea Actions runs this file too. -name: Source - -on: - push: - branches: ["**"] - # Tags aren't filtered by paths. - tags: ["v*"] - paths: ["Source/**", ".github/workflows/source.yml"] - pull_request: - paths: ["Source/**", ".github/workflows/source.yml"] - workflow_dispatch: - -jobs: - check: - strategy: - fail-fast: false - matrix: - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} - defaults: - run: - working-directory: Source - steps: - - uses: actions/checkout@v4 - # Installs the toolchain Source/rust-toolchain.toml pins. - - run: rustup toolchain install - - run: cargo fmt --all -- --check - - run: cargo clippy --workspace --all-targets --all-features -- -D warnings - - run: cargo test --workspace --all-features - - run: cargo doc --workspace --no-deps --all-features - env: - RUSTDOCFLAGS: -D warnings - - release: - # Build, package, smoke test: target/dist/'s archive, kept as an - # artifact. Linux builds in manylinux 2.28 (glibc 2.28): the programs, - # the .so and the wheel run on systems that old. - if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v') - needs: check - strategy: - fail-fast: false - matrix: - include: - - os: windows-latest - python: python - - os: ubuntu-latest - container: quay.io/pypa/manylinux_2_28_x86_64 - python: /opt/python/cp312-cp312/bin/python - runs-on: ${{ matrix.os }} - container: ${{ matrix.container }} - defaults: - run: - working-directory: Source - shell: bash - steps: - - uses: actions/checkout@v4 - - if: matrix.container - run: | - curl --proto '=https' -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none - echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" - - run: rustup toolchain install - - run: ${{ matrix.python }} release.py - - uses: actions/upload-artifact@v4 - with: - name: bakashrot-${{ matrix.os }} - path: | - Source/target/dist/*.zip - Source/target/dist/*.tar.gz diff --git a/.gitignore b/.gitignore index 3d5678a..704996d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,8 @@ # Python __pycache__/ -# Rust (Source/) +# Rust target/ + +# The compose example's config (keys) +docker/config/ diff --git a/CLAUDE.md b/CLAUDE.md index e2ed56f..80502f5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,8 +9,8 @@ between peers by name. Clients: a C DLL, CLI tools, a Python module. An - `revamp.md`: why, what's decided, what's proposed and open, the plan and its status. Read it first. -- `Source/`: the implementation (`Source/README.md`: layout, commands, - conventions; `Source/docs/`: designs, `protocol.md` 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 @@ -20,10 +20,13 @@ between peers by name. Clients: a C DLL, CLI tools, a Python module. An - Rust via rustup, in `%USERPROFILE%\.cargo\bin`, which **isn't on every shell's PATH**: prepend it (`export PATH="$HOME/.cargo/bin:$PATH"` in - bash; `check.ps1` does it itself). The toolchain is pinned - (`Source/rust-toolchain.toml`, 1.100.0, MSVC; Visual Studio 18 has the + bash; the `.ps1` scripts and `release.py` do it themselves). The toolchain is pinned + (`rust-toolchain.toml`, 1.100.0, MSVC; Visual Studio 18 has the linker). -- `Source\check.ps1` runs what CI runs; it must pass before a step is done. +- `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`). + Run them by absolute path (`-File \test.ps1`): a relative one + fails when the shell's folder differs. ## Working rules @@ -33,10 +36,10 @@ between peers by name. Clients: a C DLL, CLI tools, a Python module. An - **Decisions go in `revamp.md`**: moved to "Decided" only when the owner decides, with the date. - **Use existing crates** rather than reimplementing (MessagePack is `rmp-serde`). -- **Files mix CRLF and LF:** edits must keep each file's line endings - (`Source/` is LF, the docs at the root mostly CRLF). +- **Line endings:** LF everywhere, `.ps1` CRLF (`.gitattributes`); edits + must keep them. - **Bash tool heredocs collapse `\\`:** write edit scripts to files, or use the Edit tool. -- **Run exes from a build folder** (`Source\target\`): +- **Run exes from a build folder** (`target\`): the antivirus blocks them in temp folders. - **Generated keys and certificates never go in git** (`target/`). diff --git a/Source/Cargo.lock b/Cargo.lock similarity index 100% rename from Source/Cargo.lock rename to Cargo.lock diff --git a/Source/Cargo.toml b/Cargo.toml similarity index 91% rename from Source/Cargo.toml rename to Cargo.toml index 77a6e8e..d9d045f 100644 --- a/Source/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ -# The BakaShrot workspace: every crate is in crates/, see README.md for the -# layout and ../revamp.md for the plan. +# The BakaShrot workspace: every crate is in crates/, see readme.md for the +# layout and revamp.md for the plan. [workspace] resolver = "3" diff --git a/Source/README.md b/Source/README.md deleted file mode 100644 index 83435f6..0000000 --- a/Source/README.md +++ /dev/null @@ -1,89 +0,0 @@ -# BakaShrot - new sources (Rust) - -The new implementation, see `../revamp.md` (why, decisions, the plan and -where it stands). - -## Layout - -A Cargo workspace. What's marked with a step number is planned, added by -that step of the plan; the rest exists: - -``` -Source/ - Cargo.toml the workspace: shared lints, release profile - rust-toolchain.toml the pinned toolchain (1.100.0) - check.ps1 what CI runs: fmt, clippy, tests, docs - 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 - crates/ - bakashrot-proto/ packets, frames, names, limits, error codes, shared by everything - bakashrot-pki/ certificates: issuing, identities, CRLs, the TLS setup - bakashrot-config/ the server's config (TOML): topics, retention, replication, roles - bakashrot-storage/ SQLite, schema v9: the writer, reads, attachments, queries - bakashrot-server/ the server: TLS, identities, requests, the writer thread (and its program) - bakashrot-client/ the client library, Rust API, blocking - bakashrot-capi/ the C DLL over bakashrot-client: the BakaShrot_* exports (bakashrot.dll) - bakashrot-tools/ the CLI tools: bakashrot (push, read, query, list), bakashrot-cert - bindings/ - c/ bakashrot.h, generated from bakashrot-capi - purebasic/ the prototypes and error codes, as the PureBasic version's - python/ bakashrot.py over the DLL, check_bakashrot.py, make_wheel.py - .cargo/config.toml the C runtime linked statically on Windows - tests/ (13) end-to-end suites across processes -``` - -Dependencies only point downward: `proto`, `pki`, `config` and `storage` -don't open sockets and are tested on their own; `server` and `client` use -them; the DLL and the tools only use `client`. - -## Building and checking - -- `cargo build`, `cargo test` from `Source/` (rustup picks the pinned - toolchain). -- `powershell -ExecutionPolicy Bypass -File Source\check.ps1`: everything - CI checks (`../.github/workflows/source.yml`), warnings are errors. -- Output in `target/` (git-ignored). Generated keys and certificates never - go in git. - -## Releases - -`python release.py` (Python 3.11+) on Windows x64 or Linux x86-64 builds -that platform's release into `target/dist/bakashrot--/` -and its archive (`.zip`, `.tar.gz`): the server, `bakashrot`, -`bakashrot-cert`, the client library with its C header and PureBasic -prototypes, `bakashrot.py` and a wheel with the library in it -(`bindings/python/make_wheel.py`), the example configs, `docs/`, a -`README.txt`, the licenses (`THIRD-PARTY.txt`: every crate built in, from -`cargo metadata`). Then it checks it, in the folder's `_test/`: a CA and -certificates, the server on a free port, the tool pushing (an attachment -too), reading back, listing and querying, Python through the library and -the wheel installed by pip, the server stopped by SIGTERM (Ctrl+Break on -Windows), which must end cleanly (`_test/` kept if not); `--skip-test`. - -CI runs it on a version tag (`v*`) or by hand, keeping the archives: the -Linux one in a manylinux 2.28 container, so it runs with glibc 2.28 and -later. The version is the workspace's (`Cargo.toml`), and -`bindings/python/bakashrot.py`'s `__version__` must be the same. - -Publishing, as the old version did: - -- **The wheel** to Gitea's registry, with twine 6.1+ (for the license - metadata) and a token with `write:package`: - `twine upload --repository-url https://git.nibblepoker.lu/api/packages/aziascreations/pypi -u aziascreations `. -- **On GitHub** (no Python registry), the archives and the wheels on a - release: `gh release create v --repo aziascreations/BakaShrot --title ` - (`gh release upload` for one that exists). - -## Conventions - -- LF line endings (`.gitattributes`), rustfmt's defaults. -- Every public item documented (`missing_docs`), no `unsafe` outside the C - API crate. -- A crate's root docs say what it does; designs that span crates go in - `docs/`, updated with the code. -- Use existing crates rather than reimplementing (MessagePack is `rmp-serde`). -- Protocol changes update `docs/protocol.md`; error codes are never - renumbered, packet ids never reused. -- `OldSource/` paths in comments and docs: the PureBasic version, removed - 2026-11-15, in git history up to commit `68966a8`. diff --git a/Source/bindings/c/bakashrot.h b/bindings/c/bakashrot.h similarity index 98% rename from Source/bindings/c/bakashrot.h rename to bindings/c/bakashrot.h index 2b3f7e6..bdb2727 100644 --- a/Source/bindings/c/bakashrot.h +++ b/bindings/c/bakashrot.h @@ -1,7 +1,7 @@ /* * BakaShrot's client DLL: bakashrot.dll (Windows), libbakashrot.so (Linux). - * Generated by cbindgen from Source/crates/bakashrot-capi: don't edit. - * Source/docs/client.md has the conventions and the whole API. + * Generated by cbindgen from crates/bakashrot-capi: don't edit. + * docs/client.md has the conventions and the whole API. */ #ifndef BAKASHROT_H diff --git a/Source/bindings/purebasic/BakaShrot_Client_Prototypes.pbi b/bindings/purebasic/BakaShrot_Client_Prototypes.pbi similarity index 99% rename from Source/bindings/purebasic/BakaShrot_Client_Prototypes.pbi rename to bindings/purebasic/BakaShrot_Client_Prototypes.pbi index cb0ca31..9b48eb2 100644 --- a/Source/bindings/purebasic/BakaShrot_Client_Prototypes.pbi +++ b/bindings/purebasic/BakaShrot_Client_Prototypes.pbi @@ -28,8 +28,8 @@ ; BakaShrot_UnloadClient() ; EndIf ; -; Source/docs/client.md has what each function does (and -; Source/bindings/c/bakashrot.h, generated from the DLL). The string +; docs/client.md has what each function does (and +; bindings/c/bakashrot.h, generated from the DLL). The string ; functions are mapped to the DLL's W (UTF-16) variants. After a failed ; call, BakaShrot_GetLastError() tells why: the codes and what to do about ; each are in BakaShrot_ErrorCodes.pbi, next to this file (included below), diff --git a/Source/bindings/purebasic/BakaShrot_ErrorCodes.pbi b/bindings/purebasic/BakaShrot_ErrorCodes.pbi similarity index 98% rename from Source/bindings/purebasic/BakaShrot_ErrorCodes.pbi rename to bindings/purebasic/BakaShrot_ErrorCodes.pbi index d40639b..a3b9acf 100644 --- a/Source/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, -; Source/crates/bakashrot-proto/src/error.rs, the same numbers as protocol 6). +; crates/bakashrot-proto/src/error.rs, the same numbers as protocol 6). ; The Python client has them in bakashrot.ErrorCode. Shipped next to ; BakaShrot_Client_Prototypes.pbi, which includes it. ; diff --git a/Source/bindings/python/bakashrot.py b/bindings/python/bakashrot.py similarity index 99% rename from Source/bindings/python/bakashrot.py rename to bindings/python/bakashrot.py index 97f88af..1cc62f0 100644 --- a/Source/bindings/python/bakashrot.py +++ b/bindings/python/bakashrot.py @@ -18,7 +18,7 @@ stored, a str that may or may not be JSON: parsing them is up to the app Who the client is comes from its certificate, issued by the CA the server trusts (bakashrot-cert): its name is its node, its roles say what it may do. client.toml says where the server is and where the certificates are -(Source/docs/client.md): +(docs/client.md): server = "10.0.0.2:7000" ca = "ca.crt" @@ -66,7 +66,7 @@ __all__ = [ "MAX_GET_MESSAGES", "MAX_MESSAGE_SIZE", ] -# The protocol's: Source/crates/bakashrot-proto/src/limits.rs. +# The protocol's: crates/bakashrot-proto/src/limits.rs. MAX_GET_MESSAGES = 10000 MAX_MESSAGE_SIZE = 16 * 1024 * 1024 - 4096 @@ -74,7 +74,7 @@ DLL_NAME = "bakashrot.dll" if sys.platform == "win32" else "libbakashrot.so" class ErrorCode(enum.IntEnum): - """What failed: the protocol's codes (Source/crates/bakashrot-proto/src/error.rs). + """What failed: the protocol's codes (crates/bakashrot-proto/src/error.rs). 1-99: refused by the server, 100+: the client's own.""" NONE = 0 # Refused by the server, the connection still open. diff --git a/Source/bindings/python/check_bakashrot.py b/bindings/python/check_bakashrot.py similarity index 100% rename from Source/bindings/python/check_bakashrot.py rename to bindings/python/check_bakashrot.py diff --git a/Source/bindings/python/make_wheel.py b/bindings/python/make_wheel.py similarity index 81% rename from Source/bindings/python/make_wheel.py rename to bindings/python/make_wheel.py index a84f185..a9c75b9 100644 --- a/Source/bindings/python/make_wheel.py +++ b/bindings/python/make_wheel.py @@ -3,14 +3,14 @@ so `pip install` is all a Python app needs, nothing to compile. python make_wheel.py [license files...] - is bakashrot.dll (Windows x64) or libbakashrot.so (Linux x86-64), + is bakashrot.dll (Windows) or libbakashrot.so (Linux), x64 or ARM64, from `cargo build --release`; the license files go in the wheel's dist-info/licenses/ (release.py gives LICENSE and THIRD-PARTY.txt). Prints the wheel's path. The wheel is bakashrot--py3-none-.whl, the version being bakashrot.py's __version__ (release.py checks it's the workspace's): -win_amd64, or manylinux__x86_64 with the glibc it was built +win_amd64 or win_arm64, or manylinux__ with the glibc it was built against (a Rust library only needs libc, libm and libgcc_s, which manylinux allows). Inside, bakashrot.py is bakashrot/__init__.py with the library next to it, where it looks first. Only the standard library, and @@ -62,17 +62,27 @@ def version(): def platform_tag(library): - """The wheel's platform, from the library's kind.""" + """The wheel's platform, from the library's kind and machine (its + header's).""" with open(library, "rb") as file: - magic = file.read(4) - if magic[:2] == b"MZ": - return "win_amd64", "Operating System :: Microsoft :: Windows" - if magic == b"\x7fELF": + header = file.read(4096) + if header[:2] == b"MZ": + # The PE header's offset at 0x3C, its machine after "PE\0\0". + pe = int.from_bytes(header[0x3C:0x40], "little") + machine = {0x8664: "amd64", 0xAA64: "arm64"}.get(int.from_bytes(header[pe + 4:pe + 6], "little")) + if machine is None or header[pe:pe + 4] != b"PE\0\0": + sys.exit(f"{library}: neither an x64 nor an ARM64 DLL") + return f"win_{machine}", "Operating System :: Microsoft :: Windows" + if header[:4] == b"\x7fELF": + # e_machine, little-endian on both. + machine = {62: "x86_64", 183: "aarch64"}.get(int.from_bytes(header[18:20], "little")) + if machine is None: + sys.exit(f"{library}: neither an x86-64 nor an ARM64 shared object") libc, glibc = platform.libc_ver() if libc != "glibc": sys.exit("Built against another libc than glibc: no manylinux tag") major, minor = glibc.split(".")[:2] - return f"manylinux_{major}_{minor}_x86_64", "Operating System :: POSIX :: Linux" + return f"manylinux_{major}_{minor}_{machine}", "Operating System :: POSIX :: Linux" sys.exit(f"{library}: neither a Windows DLL nor a Linux shared object") diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..3505129 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,19 @@ +# Builds everything (the server, the tools, the client library), release +# mode, into target\release\. +# Usage: powershell -ExecutionPolicy Bypass -File build.ps1 +$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 +} + +Push-Location $PSScriptRoot +try { + cargo build --workspace --release --locked + if ($LASTEXITCODE -ne 0) { "FAILED: cargo build"; exit 1 } +} finally { + Pop-Location +} +"Built into $(Join-Path $PSScriptRoot "target\release")" +exit 0 diff --git a/clean.ps1 b/clean.ps1 new file mode 100644 index 0000000..e2e1dd8 --- /dev/null +++ b/clean.ps1 @@ -0,0 +1,20 @@ +# Deletes what the builds and releases made: target\ (cargo's output and +# target\dist\), and Python's __pycache__ folders. +# Usage: powershell -ExecutionPolicy Bypass -File clean.ps1 +$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 +} + +Push-Location $PSScriptRoot +try { + cargo clean + if ($LASTEXITCODE -ne 0) { "FAILED: cargo clean"; exit 1 } + Get-ChildItem -Path bindings -Directory -Recurse -Filter __pycache__ | Remove-Item -Recurse -Force +} finally { + Pop-Location +} +"Cleaned" +exit 0 diff --git a/Source/crates/bakashrot-capi/Cargo.toml b/crates/bakashrot-capi/Cargo.toml similarity index 100% rename from Source/crates/bakashrot-capi/Cargo.toml rename to crates/bakashrot-capi/Cargo.toml diff --git a/Source/crates/bakashrot-capi/cbindgen.toml b/crates/bakashrot-capi/cbindgen.toml similarity index 72% rename from Source/crates/bakashrot-capi/cbindgen.toml rename to crates/bakashrot-capi/cbindgen.toml index d3bff38..3ebe5ec 100644 --- a/Source/crates/bakashrot-capi/cbindgen.toml +++ b/crates/bakashrot-capi/cbindgen.toml @@ -3,8 +3,8 @@ language = "C" header = """/* * BakaShrot's client DLL: bakashrot.dll (Windows), libbakashrot.so (Linux). - * Generated by cbindgen from Source/crates/bakashrot-capi: don't edit. - * Source/docs/client.md has the conventions and the whole API. + * Generated by cbindgen from crates/bakashrot-capi: don't edit. + * docs/client.md has the conventions and the whole API. */""" include_guard = "BAKASHROT_H" cpp_compat = true diff --git a/Source/crates/bakashrot-capi/src/lib.rs b/crates/bakashrot-capi/src/lib.rs similarity index 99% rename from Source/crates/bakashrot-capi/src/lib.rs rename to crates/bakashrot-capi/src/lib.rs index 771d4f1..ee13404 100644 --- a/Source/crates/bakashrot-capi/src/lib.rs +++ b/crates/bakashrot-capi/src/lib.rs @@ -1,6 +1,6 @@ //! BakaShrot's C DLL (`bakashrot.dll`, `libbakashrot.so`): the old //! `BakaShrot_*` exports over [`bakashrot_client`], for C, PureBasic, -//! Python (ctypes) and anything that loads a DLL. `Source/docs/client.md` +//! Python (ctypes) and anything that loads a DLL. `docs/client.md` //! has the whole API; `bindings/c/bakashrot.h` is generated from this file. //! //! The conventions, the old DLL's: diff --git a/Source/crates/bakashrot-capi/src/text.rs b/crates/bakashrot-capi/src/text.rs similarity index 100% rename from Source/crates/bakashrot-capi/src/text.rs rename to crates/bakashrot-capi/src/text.rs diff --git a/Source/crates/bakashrot-capi/tests/common/mod.rs b/crates/bakashrot-capi/tests/common/mod.rs similarity index 100% rename from Source/crates/bakashrot-capi/tests/common/mod.rs rename to crates/bakashrot-capi/tests/common/mod.rs diff --git a/Source/crates/bakashrot-capi/tests/exports.rs b/crates/bakashrot-capi/tests/exports.rs similarity index 100% rename from Source/crates/bakashrot-capi/tests/exports.rs rename to crates/bakashrot-capi/tests/exports.rs diff --git a/Source/crates/bakashrot-capi/tests/header.rs b/crates/bakashrot-capi/tests/header.rs similarity index 100% rename from Source/crates/bakashrot-capi/tests/header.rs rename to crates/bakashrot-capi/tests/header.rs diff --git a/Source/crates/bakashrot-capi/tests/python.rs b/crates/bakashrot-capi/tests/python.rs similarity index 100% rename from Source/crates/bakashrot-capi/tests/python.rs rename to crates/bakashrot-capi/tests/python.rs diff --git a/Source/crates/bakashrot-client/Cargo.toml b/crates/bakashrot-client/Cargo.toml similarity index 100% rename from Source/crates/bakashrot-client/Cargo.toml rename to crates/bakashrot-client/Cargo.toml diff --git a/Source/crates/bakashrot-client/src/lib.rs b/crates/bakashrot-client/src/lib.rs similarity index 99% rename from Source/crates/bakashrot-client/src/lib.rs rename to crates/bakashrot-client/src/lib.rs index b4c51d3..53cbe25 100644 --- a/Source/crates/bakashrot-client/src/lib.rs +++ b/crates/bakashrot-client/src/lib.rs @@ -15,7 +15,7 @@ //! //! The connection: TLS 1.3 with the CA's certificates (`bakashrot-pki`), //! ALPN `bakashrot`, both ends' protocol versions, then the server's -//! `Welcome` (`Source/docs/protocol.md`). Errors carry the protocol's codes +//! `Welcome` (`docs/protocol.md`). Errors carry the protocol's codes //! (`bakashrot_proto::ErrorCode`): a server's refusal keeps its own. use aws_lc_rs::digest; @@ -423,7 +423,7 @@ impl Client { } /// Runs read-only SQL: `{"columns":[...],"rows":[[...],...]}`, every - /// value a string or null (`Source/docs/storage.md`, "The query surface"). + /// value a string or null (`docs/storage.md`, "The query surface"). pub fn query(&mut self, sql: &str) -> Result { check_size(sql, "a query")?; let query = Query { diff --git a/Source/crates/bakashrot-config/Cargo.toml b/crates/bakashrot-config/Cargo.toml similarity index 100% rename from Source/crates/bakashrot-config/Cargo.toml rename to crates/bakashrot-config/Cargo.toml diff --git a/Source/crates/bakashrot-config/example.toml b/crates/bakashrot-config/example.toml similarity index 97% rename from Source/crates/bakashrot-config/example.toml rename to crates/bakashrot-config/example.toml index 571b381..a2243ff 100644 --- a/Source/crates/bakashrot-config/example.toml +++ b/crates/bakashrot-config/example.toml @@ -1,5 +1,5 @@ # A BakaShrot server's config, every key with its default where it has -# one. Read by bakashrot-config, explained in Source/docs/config.md. +# one. Read by bakashrot-config, explained in docs/config.md. # # Names (topics, nodes, roles): 1-64 of A-Z a-z 0-9 _ . -, not only digits, # case doesn't matter. Lists of topics or nodes also take patterns: * any diff --git a/Source/crates/bakashrot-config/src/lib.rs b/crates/bakashrot-config/src/lib.rs similarity index 99% rename from Source/crates/bakashrot-config/src/lib.rs rename to crates/bakashrot-config/src/lib.rs index 1213250..8f6ee89 100644 --- a/Source/crates/bakashrot-config/src/lib.rs +++ b/crates/bakashrot-config/src/lib.rs @@ -10,7 +10,7 @@ //! Who connects is the certificate's (`bakashrot-pki`): its name is its //! node, its roles are looked up here. Peers too: what's replicated with a //! peer is its roles'. The file, every key and its default: -//! `Source/docs/config.md`. +//! `docs/config.md`. //! //! Every value is checked as serde reads it, so a wrong one is refused with //! its line. diff --git a/Source/crates/bakashrot-config/src/roles.rs b/crates/bakashrot-config/src/roles.rs similarity index 100% rename from Source/crates/bakashrot-config/src/roles.rs rename to crates/bakashrot-config/src/roles.rs diff --git a/Source/crates/bakashrot-config/src/values.rs b/crates/bakashrot-config/src/values.rs similarity index 100% rename from Source/crates/bakashrot-config/src/values.rs rename to crates/bakashrot-config/src/values.rs diff --git a/Source/crates/bakashrot-config/tests/config.rs b/crates/bakashrot-config/tests/config.rs similarity index 100% rename from Source/crates/bakashrot-config/tests/config.rs rename to crates/bakashrot-config/tests/config.rs diff --git a/Source/crates/bakashrot-pki/Cargo.toml b/crates/bakashrot-pki/Cargo.toml similarity index 100% rename from Source/crates/bakashrot-pki/Cargo.toml rename to crates/bakashrot-pki/Cargo.toml diff --git a/Source/crates/bakashrot-pki/src/ca.rs b/crates/bakashrot-pki/src/ca.rs similarity index 100% rename from Source/crates/bakashrot-pki/src/ca.rs rename to crates/bakashrot-pki/src/ca.rs diff --git a/Source/crates/bakashrot-pki/src/identity.rs b/crates/bakashrot-pki/src/identity.rs similarity index 100% rename from Source/crates/bakashrot-pki/src/identity.rs rename to crates/bakashrot-pki/src/identity.rs diff --git a/Source/crates/bakashrot-pki/src/lib.rs b/crates/bakashrot-pki/src/lib.rs similarity index 95% rename from Source/crates/bakashrot-pki/src/lib.rs rename to crates/bakashrot-pki/src/lib.rs index c51e440..e7ece82 100644 --- a/Source/crates/bakashrot-pki/src/lib.rs +++ b/crates/bakashrot-pki/src/lib.rs @@ -9,7 +9,7 @@ //! strongest settings rustls has. //! //! Everything is PEM text in and out, as files hold it. The profile and the -//! reasons behind it: `Source/docs/certificates.md`. +//! reasons behind it: `docs/certificates.md`. mod ca; mod identity; @@ -27,7 +27,7 @@ use x509_parser::certificate::X509Certificate; /// /// **A placeholder** ([`IDENTITY_OID_IS_PLACEHOLDER`]): under PEN 32473, /// which RFC 5612 reserves for documentation. Replace it with one under -/// NibblePoker's own PEN once IANA gave it (`Source/docs/oid.md`), before +/// NibblePoker's own PEN once IANA gave it (`docs/oid.md`), before /// issuing certificates for real: certificates made with this one stop /// being read once it changes. pub const IDENTITY_OID: &[u64] = &[1, 3, 6, 1, 4, 1, 32473, 1, 1]; diff --git a/Source/crates/bakashrot-pki/src/revocation.rs b/crates/bakashrot-pki/src/revocation.rs similarity index 100% rename from Source/crates/bakashrot-pki/src/revocation.rs rename to crates/bakashrot-pki/src/revocation.rs diff --git a/Source/crates/bakashrot-pki/src/tls.rs b/crates/bakashrot-pki/src/tls.rs similarity index 100% rename from Source/crates/bakashrot-pki/src/tls.rs rename to crates/bakashrot-pki/src/tls.rs diff --git a/Source/crates/bakashrot-pki/tests/ca.rs b/crates/bakashrot-pki/tests/ca.rs similarity index 100% rename from Source/crates/bakashrot-pki/tests/ca.rs rename to crates/bakashrot-pki/tests/ca.rs diff --git a/Source/crates/bakashrot-pki/tests/tls.rs b/crates/bakashrot-pki/tests/tls.rs similarity index 100% rename from Source/crates/bakashrot-pki/tests/tls.rs rename to crates/bakashrot-pki/tests/tls.rs diff --git a/Source/crates/bakashrot-proto/Cargo.toml b/crates/bakashrot-proto/Cargo.toml similarity index 100% rename from Source/crates/bakashrot-proto/Cargo.toml rename to crates/bakashrot-proto/Cargo.toml diff --git a/Source/crates/bakashrot-proto/src/error.rs b/crates/bakashrot-proto/src/error.rs similarity index 100% rename from Source/crates/bakashrot-proto/src/error.rs rename to crates/bakashrot-proto/src/error.rs diff --git a/Source/crates/bakashrot-proto/src/frame.rs b/crates/bakashrot-proto/src/frame.rs similarity index 100% rename from Source/crates/bakashrot-proto/src/frame.rs rename to crates/bakashrot-proto/src/frame.rs diff --git a/Source/crates/bakashrot-proto/src/lib.rs b/crates/bakashrot-proto/src/lib.rs similarity index 92% rename from Source/crates/bakashrot-proto/src/lib.rs rename to crates/bakashrot-proto/src/lib.rs index 06ef671..8138a2a 100644 --- a/Source/crates/bakashrot-proto/src/lib.rs +++ b/crates/bakashrot-proto/src/lib.rs @@ -11,7 +11,7 @@ //! - [`frame`]: frames, a 4-byte size then a packet. //! - [`packets`]: every packet, and [`Packet`] to encode and decode them. //! -//! The wire format is described in `Source/docs/protocol.md`. +//! The wire format is described in `docs/protocol.md`. pub mod error; pub mod frame; diff --git a/Source/crates/bakashrot-proto/src/limits.rs b/crates/bakashrot-proto/src/limits.rs similarity index 99% rename from Source/crates/bakashrot-proto/src/limits.rs rename to crates/bakashrot-proto/src/limits.rs index 27a2115..edeb54f 100644 --- a/Source/crates/bakashrot-proto/src/limits.rs +++ b/crates/bakashrot-proto/src/limits.rs @@ -28,7 +28,7 @@ pub const MAX_TIMESTAMP: u64 = 253_402_300_799_999; /// The biggest message id: 2^43 - 1, about 8.8 trillion per topic and /// node. Servers store it in 43 bits of a packed key -/// (`Source/docs/storage.md`, "Keys"). +/// (`docs/storage.md`, "Keys"). pub const MAX_MESSAGE_ID: u64 = (1 << 43) - 1; /// The longest topic or node name, in characters (ASCII only). diff --git a/Source/crates/bakashrot-proto/src/names.rs b/crates/bakashrot-proto/src/names.rs similarity index 100% rename from Source/crates/bakashrot-proto/src/names.rs rename to crates/bakashrot-proto/src/names.rs diff --git a/Source/crates/bakashrot-proto/src/packets/attachments.rs b/crates/bakashrot-proto/src/packets/attachments.rs similarity index 100% rename from Source/crates/bakashrot-proto/src/packets/attachments.rs rename to crates/bakashrot-proto/src/packets/attachments.rs diff --git a/Source/crates/bakashrot-proto/src/packets/messages.rs b/crates/bakashrot-proto/src/packets/messages.rs similarity index 100% rename from Source/crates/bakashrot-proto/src/packets/messages.rs rename to crates/bakashrot-proto/src/packets/messages.rs diff --git a/Source/crates/bakashrot-proto/src/packets/mod.rs b/crates/bakashrot-proto/src/packets/mod.rs similarity index 99% rename from Source/crates/bakashrot-proto/src/packets/mod.rs rename to crates/bakashrot-proto/src/packets/mod.rs index c5d91e5..2662888 100644 --- a/Source/crates/bakashrot-proto/src/packets/mod.rs +++ b/crates/bakashrot-proto/src/packets/mod.rs @@ -4,7 +4,7 @@ //! array, `[type, [field, field, ...]]`. Structs inside are arrays of their //! fields too, `Option`s nil or their value, bytes binaries. All of it is //! derived with `serde` (`rmp-serde`'s compact form): the structs below -//! are the format, `Source/docs/protocol.md` lists them. +//! are the format, `docs/protocol.md` lists them. //! //! [`Packet::decode`] checks everything: the types and the number of //! fields (`serde`), then each packet's rules ([`Check`]: ranges, names, @@ -20,7 +20,7 @@ //! Adding a packet: a struct deriving `Serialize` and `Deserialize`, with //! its [`Check`], in the file of its family; a line in the `packets!` table //! below with the next id (never reuse one); a sample in `tests/packets.rs`; -//! its row in `Source/docs/protocol.md`. +//! its row in `docs/protocol.md`. mod attachments; mod messages; diff --git a/Source/crates/bakashrot-proto/src/packets/replication.rs b/crates/bakashrot-proto/src/packets/replication.rs similarity index 100% rename from Source/crates/bakashrot-proto/src/packets/replication.rs rename to crates/bakashrot-proto/src/packets/replication.rs diff --git a/Source/crates/bakashrot-proto/src/packets/session.rs b/crates/bakashrot-proto/src/packets/session.rs similarity index 100% rename from Source/crates/bakashrot-proto/src/packets/session.rs rename to crates/bakashrot-proto/src/packets/session.rs diff --git a/Source/crates/bakashrot-proto/tests/packets.rs b/crates/bakashrot-proto/tests/packets.rs similarity index 100% rename from Source/crates/bakashrot-proto/tests/packets.rs rename to crates/bakashrot-proto/tests/packets.rs diff --git a/Source/crates/bakashrot-server/Cargo.toml b/crates/bakashrot-server/Cargo.toml similarity index 100% rename from Source/crates/bakashrot-server/Cargo.toml rename to crates/bakashrot-server/Cargo.toml diff --git a/Source/crates/bakashrot-server/src/accept_from.rs b/crates/bakashrot-server/src/accept_from.rs similarity index 100% rename from Source/crates/bakashrot-server/src/accept_from.rs rename to crates/bakashrot-server/src/accept_from.rs diff --git a/Source/crates/bakashrot-server/src/connection.rs b/crates/bakashrot-server/src/connection.rs similarity index 99% rename from Source/crates/bakashrot-server/src/connection.rs rename to crates/bakashrot-server/src/connection.rs index 9fe9852..9855773 100644 --- a/Source/crates/bakashrot-server/src/connection.rs +++ b/crates/bakashrot-server/src/connection.rs @@ -1,5 +1,5 @@ //! One connection: TLS, the versions, who it is, then its requests, one at -//! a time (`Source/docs/protocol.md`). +//! a time (`docs/protocol.md`). use crate::writer::Write; use crate::{Shared, accept_from, now}; diff --git a/Source/crates/bakashrot-server/src/lib.rs b/crates/bakashrot-server/src/lib.rs similarity index 99% rename from Source/crates/bakashrot-server/src/lib.rs rename to crates/bakashrot-server/src/lib.rs index cfd6178..d8625f2 100644 --- a/Source/crates/bakashrot-server/src/lib.rs +++ b/crates/bakashrot-server/src/lib.rs @@ -252,7 +252,7 @@ impl Shared { /// Checkpoints the WAL every second, on a thread and a connection of its /// own, so the writer doesn't do it in the middle of a commit (2.5 times -/// the pushes: `Source/docs/storage.md`, "Against the old storage"). +/// the pushes: `docs/storage.md`, "Against the old storage"). fn start_checkpoints(database: &Database) -> Result<(), String> { let checkpointer = database.checkpointer().map_err(|error| error.to_string())?; std::thread::Builder::new() diff --git a/Source/crates/bakashrot-server/src/main.rs b/crates/bakashrot-server/src/main.rs similarity index 100% rename from Source/crates/bakashrot-server/src/main.rs rename to crates/bakashrot-server/src/main.rs diff --git a/Source/crates/bakashrot-server/src/push_to.rs b/crates/bakashrot-server/src/push_to.rs similarity index 100% rename from Source/crates/bakashrot-server/src/push_to.rs rename to crates/bakashrot-server/src/push_to.rs diff --git a/Source/crates/bakashrot-server/src/retention.rs b/crates/bakashrot-server/src/retention.rs similarity index 100% rename from Source/crates/bakashrot-server/src/retention.rs rename to crates/bakashrot-server/src/retention.rs diff --git a/Source/crates/bakashrot-server/src/writer.rs b/crates/bakashrot-server/src/writer.rs similarity index 100% rename from Source/crates/bakashrot-server/src/writer.rs rename to crates/bakashrot-server/src/writer.rs diff --git a/Source/crates/bakashrot-server/tests/end_to_end.rs b/crates/bakashrot-server/tests/end_to_end.rs similarity index 100% rename from Source/crates/bakashrot-server/tests/end_to_end.rs rename to crates/bakashrot-server/tests/end_to_end.rs diff --git a/Source/crates/bakashrot-storage/Cargo.toml b/crates/bakashrot-storage/Cargo.toml similarity index 100% rename from Source/crates/bakashrot-storage/Cargo.toml rename to crates/bakashrot-storage/Cargo.toml diff --git a/Source/crates/bakashrot-storage/src/batch.rs b/crates/bakashrot-storage/src/batch.rs similarity index 100% rename from Source/crates/bakashrot-storage/src/batch.rs rename to crates/bakashrot-storage/src/batch.rs diff --git a/Source/crates/bakashrot-storage/src/database.rs b/crates/bakashrot-storage/src/database.rs similarity index 100% rename from Source/crates/bakashrot-storage/src/database.rs rename to crates/bakashrot-storage/src/database.rs diff --git a/Source/crates/bakashrot-storage/src/lib.rs b/crates/bakashrot-storage/src/lib.rs similarity index 98% rename from Source/crates/bakashrot-storage/src/lib.rs rename to crates/bakashrot-storage/src/lib.rs index 7fc9b83..cd8adba 100644 --- a/Source/crates/bakashrot-storage/src/lib.rs +++ b/crates/bakashrot-storage/src/lib.rs @@ -11,7 +11,7 @@ //! //! **Everything is by name:** topics, nodes, message ids, times, as on the //! wire. Streams (one node's messages in one topic) and the packed keys -//! that store them stay inside this crate: `Source/docs/storage.md`. +//! that store them stay inside this crate: `docs/storage.md`. //! //! **Blocking:** SQLite is. The server runs these on threads of their own //! (the writer on one, readers on a pool), not on its async tasks. @@ -90,7 +90,7 @@ impl From for Error { /// A result of this crate. pub type Result = std::result::Result; -/// Where an attachment is at (`Source/docs/storage.md`, "Attachments"). +/// Where an attachment is at (`docs/storage.md`, "Attachments"). #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum AttachmentState { /// Pushed, its parts coming, no message yet. diff --git a/Source/crates/bakashrot-storage/src/query.rs b/crates/bakashrot-storage/src/query.rs similarity index 100% rename from Source/crates/bakashrot-storage/src/query.rs rename to crates/bakashrot-storage/src/query.rs diff --git a/Source/crates/bakashrot-storage/src/reader.rs b/crates/bakashrot-storage/src/reader.rs similarity index 100% rename from Source/crates/bakashrot-storage/src/reader.rs rename to crates/bakashrot-storage/src/reader.rs diff --git a/Source/crates/bakashrot-storage/src/schema_v9.sql b/crates/bakashrot-storage/src/schema_v9.sql similarity index 98% rename from Source/crates/bakashrot-storage/src/schema_v9.sql rename to crates/bakashrot-storage/src/schema_v9.sql index 60a8b50..68ed02d 100644 --- a/Source/crates/bakashrot-storage/src/schema_v9.sql +++ b/crates/bakashrot-storage/src/schema_v9.sql @@ -1,4 +1,4 @@ --- BakaShrot's database, schema v9. Read Source/docs/storage.md first: the +-- BakaShrot's database, schema v9. Read docs/storage.md first: the -- keys below are packed integers, on purpose, and only bakashrot-storage -- packs and unpacks them. -- diff --git a/Source/crates/bakashrot-storage/tests/storage.rs b/crates/bakashrot-storage/tests/storage.rs similarity index 100% rename from Source/crates/bakashrot-storage/tests/storage.rs rename to crates/bakashrot-storage/tests/storage.rs diff --git a/Source/crates/bakashrot-tools/Cargo.toml b/crates/bakashrot-tools/Cargo.toml similarity index 100% rename from Source/crates/bakashrot-tools/Cargo.toml rename to crates/bakashrot-tools/Cargo.toml diff --git a/Source/crates/bakashrot-tools/src/bin/bakashrot-cert.rs b/crates/bakashrot-tools/src/bin/bakashrot-cert.rs similarity index 98% rename from Source/crates/bakashrot-tools/src/bin/bakashrot-cert.rs rename to crates/bakashrot-tools/src/bin/bakashrot-cert.rs index 91c4aa8..054169b 100644 --- a/Source/crates/bakashrot-tools/src/bin/bakashrot-cert.rs +++ b/crates/bakashrot-tools/src/bin/bakashrot-cert.rs @@ -1,6 +1,6 @@ //! `bakashrot-cert`: makes a CA, issues certificates, revokes them, shows //! them. Every file is PEM; keys are written once, never over an existing -//! file. See `Source/docs/certificates.md`. +//! file. See `docs/certificates.md`. use bakashrot_pki::{ CA_DAYS, CERTIFICATE_DAYS, Ca, IDENTITY_OID_IS_PLACEHOLDER, Identity, Revocations, Usage, @@ -100,7 +100,7 @@ fn main() -> ExitCode { /// Said whenever a certificate is made while the OID is the placeholder. const PLACEHOLDER_WARNING: &str = "warning: the identity extension's OID is still a placeholder \ -(Source/docs/oid.md): fine for tests, not for certificates in use"; +(docs/oid.md): fine for tests, not for certificates in use"; fn run(command: Command) -> Result<(), String> { if IDENTITY_OID_IS_PLACEHOLDER && matches!(command, Command::Ca { .. } | Command::Issue { .. }) diff --git a/Source/crates/bakashrot-tools/src/bin/bakashrot.rs b/crates/bakashrot-tools/src/bin/bakashrot.rs similarity index 99% rename from Source/crates/bakashrot-tools/src/bin/bakashrot.rs rename to crates/bakashrot-tools/src/bin/bakashrot.rs index 191832a..5f533b8 100644 --- a/Source/crates/bakashrot-tools/src/bin/bakashrot.rs +++ b/crates/bakashrot-tools/src/bin/bakashrot.rs @@ -1,7 +1,7 @@ //! `bakashrot`: pushes messages, reads them and their attachments, runs //! queries and lists names from the command line, connecting with a //! `client.toml`. The old `BakaShrot*` tools in one program; see -//! `Source/docs/client.md`, "The tools". +//! `docs/client.md`, "The tools". use bakashrot_client::{Client, Error, Settings}; use bakashrot_proto::error::{code_name, is_refusal_code}; diff --git a/Source/crates/bakashrot-tools/tests/bakashrot.rs b/crates/bakashrot-tools/tests/bakashrot.rs similarity index 100% rename from Source/crates/bakashrot-tools/tests/bakashrot.rs rename to crates/bakashrot-tools/tests/bakashrot.rs diff --git a/Source/crates/bakashrot-tools/tests/cert.rs b/crates/bakashrot-tools/tests/cert.rs similarity index 100% rename from Source/crates/bakashrot-tools/tests/cert.rs rename to crates/bakashrot-tools/tests/cert.rs diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..e888ee0 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,64 @@ +# The BakaShrot server's image: bakashrot-server, with the bakashrot and +# bakashrot-cert tools beside it. Built from the repository's root: +# docker build -f docker/Dockerfile -t bakashrot-server . +# CI builds it for amd64 and arm64 on a version tag, checks it +# (docker/test.sh) and pushes it to ghcr.io/aziascreations/bakashrot-server +# (.github/workflows/ci.yml). +# +# The config goes in /etc/bakashrot (read-only: server.toml, the CA's +# certificate, the server's certificate and key, the CRL if any), the +# database in /var/lib/bakashrot (a volume). In server.toml: +# listen = "0.0.0.0:7000" every interface: 127.0.0.1 isn't reachable +# from outside the container +# database = "/var/lib/bakashrot/bakashrot.sqlite" +# and the certificates relative to it (ca = "ca.crt", ...). The server runs +# as uid 10001, which must be able to read its key (bakashrot-cert writes +# keys readable by their owner only): chown 10001:10001 config/server-1.key +# +# docker run -d --name bakashrot -p 7000:7000 \ +# -v ./config:/etc/bakashrot:ro -v bakashrot-data:/var/lib/bakashrot \ +# ghcr.io/aziascreations/bakashrot-server +# +# Or docker/compose.yml. `docker stop` stops it cleanly (SIGTERM). +# The tools: docker run --rm bakashrot-cert ... (or bakashrot ...). + + +# --- Build --------------------------------------------------------------------- + +FROM rust:1-slim-trixie AS build + +WORKDIR /src +# Only what the programs are built from (Dockerfile.dockerignore). +COPY . . +# The toolchain rust-toolchain.toml pins, then the release build. +RUN rustup toolchain install \ + && cargo build --release --locked -p bakashrot-server -p bakashrot-tools \ + && mkdir /out \ + && cp target/release/bakashrot-server target/release/bakashrot target/release/bakashrot-cert /out/ + + +# --- Runtime ------------------------------------------------------------------- + +# The same Debian as the build: the programs only need its glibc. +FROM debian:trixie-slim + +# The source label links the package to the repository on ghcr.io. CI +# pushes each architecture's image as is, then an index of both with the +# same as annotations: GitHub reads those on an index. +LABEL org.opencontainers.image.source="https://github.com/aziascreations/BakaShrot" \ + org.opencontainers.image.description="BakaShrot server" \ + org.opencontainers.image.licenses="CC0-1.0" + +RUN groupadd --system --gid 10001 bakashrot \ + && useradd --system --uid 10001 --gid 10001 --home-dir /var/lib/bakashrot --shell /usr/sbin/nologin bakashrot \ + && mkdir -p /etc/bakashrot /var/lib/bakashrot \ + && chown bakashrot:bakashrot /var/lib/bakashrot + +COPY --from=build /out/ /usr/local/bin/ + +USER bakashrot +WORKDIR /var/lib/bakashrot +VOLUME /var/lib/bakashrot +EXPOSE 7000 + +CMD ["bakashrot-server", "/etc/bakashrot/server.toml"] diff --git a/docker/Dockerfile.dockerignore b/docker/Dockerfile.dockerignore new file mode 100644 index 0000000..2ffdca4 --- /dev/null +++ b/docker/Dockerfile.dockerignore @@ -0,0 +1,8 @@ +# Only what the programs are built from: target/ alone can hold gigabytes +# of builds and test databases, and keys. +* +!Cargo.toml +!Cargo.lock +!rust-toolchain.toml +!.cargo +!crates diff --git a/docker/compose.yml b/docker/compose.yml new file mode 100644 index 0000000..d6adf72 --- /dev/null +++ b/docker/compose.yml @@ -0,0 +1,27 @@ +# BakaShrot's server with docker compose, from this folder: +# docker compose up -d pulls the image (--build: builds it here) +# docker compose logs -f +# docker compose down stops it cleanly (SIGTERM) +# +# config/, next to this file: server.toml, ca.crt, the server's certificate +# and key, the CRL if any (the Dockerfile says what server.toml needs; its +# key readable by uid 10001). The database lives in the bakashrot-data +# volume, kept by `down` (`down -v` deletes it). + +services: + bakashrot: + image: ghcr.io/aziascreations/bakashrot-server:latest + build: + context: .. + dockerfile: docker/Dockerfile + container_name: bakashrot + restart: unless-stopped + ports: + # server.toml's listen port. + - "7000:7000" + volumes: + - ./config:/etc/bakashrot:ro + - bakashrot-data:/var/lib/bakashrot + +volumes: + bakashrot-data: diff --git a/docker/test.sh b/docker/test.sh new file mode 100755 index 0000000..7fec479 --- /dev/null +++ b/docker/test.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# Smoke-tests a server image, as CI does before pushing it: certificates by +# its bakashrot-cert, its server started with them, its bakashrot pushing +# and reading back over a Docker network, then `docker stop`, which must +# end it cleanly (exit code 0, "stopped"). +# Usage: docker/test.sh +set -eu +image=$1 +name=bakashrot-test-$$ +work=$(mktemp -d) +# The image's user (10001) writes the certificates there. +chmod 777 "$work" + +cleanup() { + docker rm -f -v "$name" >/dev/null 2>&1 || true + docker network rm "$name" >/dev/null 2>&1 || true + rm -rf "$work" +} +trap cleanup EXIT +fail() { + echo "FAILED: $1" + docker logs "$name" 2>&1 || true + exit 1 +} +tool() { + docker run --rm -v "$work:/w" -w /w --network "$name" "$image" "$@" +} + +docker network create "$name" >/dev/null +tool bakashrot-cert ca --name "Image test CA" +tool bakashrot-cert issue --name server-1 --server +tool bakashrot-cert issue --name tester --role tester +cat >"$work/server.toml" <"$work/client.toml" </dev/null +tries=0 +until docker logs "$name" 2>&1 | grep -q "listening on"; do + tries=$((tries + 1)) + [ "$tries" -lt 100 ] || fail "the server isn't listening" + [ "$(docker inspect -f '{{.State.Running}}' "$name")" = true ] || fail "the server exited" + sleep 0.2 +done + +tool bakashrot push imagetest '{"image":"test"}' | grep -q "message #1" || fail "push" +tool bakashrot messages imagetest tester | grep -q '"image":"test"' || fail "messages" + +docker stop "$name" >/dev/null +[ "$(docker inspect -f '{{.State.ExitCode}}' "$name")" = 0 ] || fail "the server's exit code" +docker logs "$name" 2>&1 | grep -q "stopped" || fail "no clean stop" +echo "The image: certificates, the server, a push read back, a clean stop: OK" diff --git a/Source/docs/certificates.md b/docs/certificates.md similarity index 98% rename from Source/docs/certificates.md rename to docs/certificates.md index 7684e0e..91fff22 100644 --- a/Source/docs/certificates.md +++ b/docs/certificates.md @@ -2,7 +2,7 @@ Who connects to whom, and how it's checked. The code is `crates/bakashrot-pki` (the library) and `crates/bakashrot-tools` -(`bakashrot-cert`, the tool). Decided in `../../revamp.md`, "Decided". +(`bakashrot-cert`, the tool). Decided in `../revamp.md`, "Decided". ## The idea diff --git a/Source/docs/client.md b/docs/client.md similarity index 99% rename from Source/docs/client.md rename to docs/client.md index b82a58b..9d9b760 100644 --- a/Source/docs/client.md +++ b/docs/client.md @@ -11,7 +11,7 @@ What apps connect with, in layers: | Python | `bindings/python/bakashrot.py` | `Client` over the DLL (ctypes), standard library only | | The tools | `crates/bakashrot-tools`: `bakashrot` | the command line, over `bakashrot-client` | -Decided in `../../revamp.md`, "Decided" (2026-11-13). What goes over the +Decided in `../revamp.md`, "Decided" (2026-11-13). What goes over the wire: `protocol.md`; the server's side: `server.md`. **Status:** steps 7 to 9: connecting, pushes, messages, attachments, diff --git a/Source/docs/config.md b/docs/config.md similarity index 99% rename from Source/docs/config.md rename to docs/config.md index a7334cb..a33bfea 100644 --- a/Source/docs/config.md +++ b/docs/config.md @@ -4,7 +4,7 @@ One TOML file, read and checked at once by `crates/bakashrot-config`: a config that's wrong is refused whole, saying where (the line, shown) and why. Every value is checked as it's read (serde), so every refusal has its line. Every key, with its default: `crates/bakashrot-config/example.toml`. -Decided in `../../revamp.md`, "Decided". +Decided in `../revamp.md`, "Decided". ## What's in it diff --git a/Source/docs/known-issues.md b/docs/known-issues.md similarity index 100% rename from Source/docs/known-issues.md rename to docs/known-issues.md diff --git a/Source/docs/oid.md b/docs/oid.md similarity index 97% rename from Source/docs/oid.md rename to docs/oid.md index a270a57..d1989dc 100644 --- a/Source/docs/oid.md +++ b/docs/oid.md @@ -72,6 +72,6 @@ With `` the number IANA gave: `[1, 3, 6, 1, 4, 1, , 1, 1]`, `IDENTITY_OID_IS_PLACEHOLDER` to `false`. 3. **Update** this file (the table, "Now"), `certificates.md` and the open - point in `../../revamp.md`. + point in `../revamp.md`. 4. **Issue again** any certificate made with the placeholder, and run - `check.ps1` (the tests issue their own, nothing to change there). + `test.ps1` (the tests issue their own, nothing to change there). diff --git a/Source/docs/protocol.md b/docs/protocol.md similarity index 100% rename from Source/docs/protocol.md rename to docs/protocol.md diff --git a/Source/docs/server.md b/docs/server.md similarity index 93% rename from Source/docs/server.md rename to docs/server.md index 07fbf58..476b4c0 100644 --- a/Source/docs/server.md +++ b/docs/server.md @@ -2,7 +2,7 @@ `crates/bakashrot-server` (a library and the `bakashrot-server` program) and `crates/bakashrot-client` (the blocking client library the C DLL will -wrap). Decided in `../../revamp.md`, "Decided" (2026-11-13). What goes over +wrap). Decided in `../revamp.md`, "Decided" (2026-11-13). What goes over the wire: `protocol.md`. **Status:** steps 5, 6, 9, 10, 11 and 12: connecting, pushes and their @@ -17,7 +17,7 @@ bakashrot-server server.toml The config (`config.md`) gives where to listen, the certificates, the CRL, the database, the topics and the roles. Decided 2026-11-14 -(`../../revamp.md`, "Operations"): +(`../revamp.md`, "Operations"): - **Stopping:** SIGTERM or SIGINT on Linux; Ctrl+C, Ctrl+Break or its console closed on Windows. It stops taking connections and writes @@ -46,6 +46,29 @@ Restart=on-failure # SIGTERM, then 90 s at most: far more than a stop takes. ``` +### In Docker + +`docker/Dockerfile` (its comments have the details), the image +`ghcr.io/aziascreations/bakashrot-server` (amd64 and arm64, pushed by CI +on a version tag): the server, with `bakashrot` and `bakashrot-cert` +beside it, on `debian:trixie-slim`, as uid 10001. + +- **The config** in `/etc/bakashrot`, read-only: `server.toml`, the + certificates, the server's key (readable by uid 10001: `chown 10001` + it, `bakashrot-cert` writes keys for their owner only). `listen = + "0.0.0.0:7000"`: 127.0.0.1 isn't reachable from outside. +- **The database** in `/var/lib/bakashrot`, a volume: `database = + "/var/lib/bakashrot/bakashrot.sqlite"`. +- **Running it:** `docker/compose.yml` (`docker compose up -d` from + `docker/`, the config in `docker/config/`), or `docker run -d -p + 7000:7000 -v ./config:/etc/bakashrot:ro -v + bakashrot-data:/var/lib/bakashrot `. `docker stop` is SIGTERM: + a clean stop. The logs: `docker logs`. +- **The tools:** `docker run --rm bakashrot-cert ...`. +- **Checked** by `docker/test.sh ` (CI runs it on both before + pushing): certificates by the image's tool, its server, a push read + back over a Docker network, `docker stop` ending it cleanly. + ## Inside the server | What | Where | How | @@ -77,7 +100,7 @@ Each topic's count is logged ("deleted 3 messages of topic 'logs'"). ## Replication -Decided in `../../revamp.md` ("Replication by address", 2026-11-14). +Decided in `../revamp.md` ("Replication by address", 2026-11-14). Each server's config says who it replicates with, by address (`config.md`, "Peers"): `push_to`, the servers it dials and sends to; `accept_from`, the servers whose messages it takes (`"*"` for all). A link diff --git a/Source/docs/storage.md b/docs/storage.md similarity index 99% rename from Source/docs/storage.md rename to docs/storage.md index 2e31b16..d473386 100644 --- a/Source/docs/storage.md +++ b/docs/storage.md @@ -3,7 +3,7 @@ The server's database: one SQLite file. The code is `crates/bakashrot-storage`; the schema is `crates/bakashrot-storage/src/schema_v9.sql`, made in one go. Decided in -`../../revamp.md`, "Decided" (2026-11-13). +`../revamp.md`, "Decided" (2026-11-13). **Not compatible with v8:** a database of the old server isn't opened (refused at start, saying so); its data isn't carried over. diff --git a/readme.md b/readme.md index c902d3e..2b32095 100644 --- a/readme.md +++ b/readme.md @@ -19,13 +19,95 @@ store them in SQLite, and replicate them to other servers by topic and node name * A CLI tool to push, read, query and list * A Python module over the library, without dependencies, as a wheel with the library in it +See [revamp.md](revamp.md) for why it was rewritten in Rust, what was decided, and the plan. +The PureBasic version it replaced (protocol 6) is in the git history: `OldSource/`, up to commit `68966a8`. + ## Building -Written in Rust, see [Source/README.md](Source/README.md): `cargo build --release` from `Source/`, -`python release.py` for a release (Windows x64, Linux x86-64) with its smoke test. +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. -See [revamp.md](revamp.md) for why it was rewritten, what was decided, and the plan. -The PureBasic version it replaced (protocol 6) is in the git history: `OldSource/`, up to commit `68966a8`. +From the repository's root, on Windows (`powershell -ExecutionPolicy Bypass -File