Contributing to sculkworm
sculkworm is a standalone Rust crate (crates/sculkworm) with unit tests (src/) and TCP integration tests (tests/relay.rs).
Toolchain and prerequisites#
- Rust toolchain pinned in rust-toolchain.toml (
1.100.0, withrustfmtandclippy) musl-toolsand thex86_64-unknown-linux-muslRust target (only for static release builds outside Docker)- Docker Engine (only for testing the container build)
- Node.js 22.18 or later (only for regenerating assets or running a live
minecraft-protocolsmoke check)
Build from source#
Run all Cargo commands from crates/sculkworm:
cargo build --lockedFor an optimized release binary:
cargo build --release --lockedFor a static Linux musl binary (matching CI and Dockerfile):
rustup target add x86_64-unknown-linux-musl
CC_x86_64_unknown_linux_musl=musl-gcc cargo build --release --locked --target x86_64-unknown-linux-muslChecks and tests#
Format, lint, and Rust tests#
Run the same Rust checks CI executes:
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test --lockedcargo test --locked runs the 21 unit tests in src/ and the 8 integration tests in tests/relay.rs:
test result: ok. 21 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
...
test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered outLive check with a real minecraft-protocol client#
To verify the compiled release binary against a real minecraft-protocol client (version 1.21.4) instead of synthetic TCP fixtures:
-
Build the release binary:
cargo build --release --locked -
Run a local status-ping test (for example with the two-backend Node script in Getting started, or with
prototypes/sculkworm-relayif present in your checkout) pointingSCULKWORM_ROUTES_FILEat a temporaryroutes.jsonandSCULKWORM_LISTEN=127.0.0.1:25592. -
Confirm each hostname reaches its matching backend,
unknownhostnames close with zero bytes, and stderr emitsevent=listening,event=route,event=closed, andevent=unknown_host.
Container smoke test#
Build the Docker image and confirm it starts cleanly with a minimal routes file:
docker build -t sculkworm .
ROUTES_FILE="$(mktemp)"
printf '{"routes":{"smoke.example":"127.0.0.1:1"}}\n' > "$ROUTES_FILE"
chmod 644 "$ROUTES_FILE"
docker run -d --name sculkworm-smoke \
-v "$ROUTES_FILE:/etc/sculkworm/routes.json:ro" \
sculkworm
docker logs sculkworm-smoke
docker rm -f sculkworm-smoke
rm -f "$ROUTES_FILE"Code layout#
| File | Responsibility |
|---|---|
src/lib.rs |
Public module exports and RunningRelay lifecycle handle (start, shutdown). |
src/main.rs |
CLI entrypoint, SCULKWORM_* startup wiring, SIGHUP route reload loop, and SIGTERM/SIGINT handling. |
src/config.rs |
Config::from_env / from_lookup, environment variable parsing, defaults, and bounds checks. |
src/domain.rs |
Domain normalization, HostField parsing (\0 FML suffix, 26.4 query string, _o origin, _id), and percent-decoding. |
src/handshake.rs |
Streaming VarInt and Minecraft Handshake (0x00) parser, MAX_HANDSHAKE_PACKET_LEN (4096), legacy ping detection, and HandshakeError. |
src/routes.rs |
Target validation (host:port / [ipv6]:port), strict routes.json deserialization, and RwLock-backed RouteTable. |
src/relay.rs |
Relay::serve accept loop, Semaphore concurrency cap, handshake timeout, backend DNS/TCP connect, byte replay, bidirectional splice, and sanitize_log_value. |
tests/relay.rs |
End-to-end TCP integration tests (routing, 1-byte fragmentation, unknown host, timeouts, unreachable backend, live table swap, connection cap, handle drop). |
Conventions#
- Exact-pinned dependencies: every crate in Cargo.toml uses an exact version constraint (
=X.Y.Z) and Cargo.lock is committed. Pass--lockedtocargo buildandcargo test. - No
.unwrap()in non-test code: return typed errors (ConfigError,RoutesError,HandshakeError) or handle poisoned locks explicitly (as inRouteTablewithunwrap_or_else(|e| e.into_inner())). Keep.unwrap()inside#[cfg(test)]andtests/only. - Structured stderr logs: emit single-line
level=<info|warn|error> event=<name> key=valuerecords to stderr. Pass every untrusted client string throughsanitize_log_value(src/relay.rs) and format OS or parse errors with{:?}. - Documentation in sync:
- Environment variables live in
src/config.rsand are documented in docs/configuration.md. - Route validation errors live in
src/routes.rsand are documented in docs/configuration.md. - Handshake framing and rejection reasons live in
src/handshake.rsandsrc/domain.rsand are documented in docs/protocol.md. - Visual assets (
assets/icon-64.png,assets/logo-288.png,assets/logo.svg,assets/banner.png,assets/social.png,assets/mark.svg) are generated deterministically byassets/gen-logo.mjsandassets/gen-banner.mjs. - Use relative links only so every page resolves on GitHub and passes
node ../../scripts/check-doc-links.mjs .from the crate root (ornode scripts/check-doc-links.mjs crates/sculkwormfrom the repository root).pnpm lintdoes not check this crate's links, so run one of these yourself. It does parse every Mermaid diagram undercrates/(scripts/check-mermaid.mjs), so a diagram GitHub cannot render fails the build.
- Environment variables live in
Releases#
sculkworm is released from this monorepo with its own version and tags (sculkworm-v0.3.0), by the same release workflow as sculk.network. The release guide has the model and the steps. In short:
- Every night, if anything under
src/,Cargo.toml,Cargo.lock,rust-toolchain.tomlorDockerfilechanged andci-okpassed onmain, the workflow publishessculkworm-vX.Y.0-nightly.<date>.<run>and the image tags:X.Y.0-nightly.<date>.<run>and:nightly. - A maintainer promotes the latest nightly to a stable release with
gh workflow run release --ref main -f channel=stable -f product=sculkworm. It publishes:X.Y.0,:X.Yand:latest. - The version lives in the tag and the image's
org.opencontainers.image.versionlabel. LeaveCargo.tomlat0.1.0, and do not keep a changelog: the GitHub Release notes list the commits that touched sculkworm.
CI in .github/workflows/ci.yml runs cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test --locked, a static x86_64-unknown-linux-musl build, and a Docker smoke run on every pull request touching crates/sculkworm/.