English
Libraries libs/
Reusable parts with no knowledge of the proxy kernel: formats, low-level protocols, system calls. Each is an ours-<name> crate in libs/<name>.
Layer rules
- A library does not depend on any workspace crate outside
libs/— neither onours-api, nor on modules, nor oncrates/. Checked bytests/layers.py(see Layers, Checks). Libraries may depend on each other (ours-codec→ours-json,ours-tls13→ours-ktls-sys,ours-quinn-ext→ours-h2). - External dependencies — through the root
Cargo.toml's[workspace.dependencies]. - Anything that depends on a module (for example, on
ours-mod-tls) lives not here but incrates/.
unsafe
The workspace has unsafe_code = "forbid" ([workspace.lints.rust] of the root Cargo.toml); every library enables it through [lints] workspace = true. The exceptions are ours-ktls-sys, ours-tun-sys, ours-sys and ours-alloc (jemalloc's options and mallctl): they have their own [lints] without forbid:
toml
[lints.rust]
unsafe_op_in_unsafe_fn = "deny"
[lints.clippy]
all = { level = "warn", priority = -1 }
undocumented_unsafe_blocks = "deny"Every unsafe block in them has a // SAFETY: comment. The unsafe call is kept in the smallest crate that needs it.
ours-net-sys is not an exception (see net-sys). ours-h2, ours-vlessenc and ours-wireguard also write #![forbid(unsafe_code)] in lib.rs.
List
| Library | Purpose |
|---|---|
alloc | the global allocator of the binary: jemalloc on x86_64 and aarch64 (see Build) |
| atomic64 | a 64-bit counter on any target, including MIPS32 |
| clock | the process time: the system clock moved by the ntp offset |
| bufpool | buffers with headroom and their pools |
| codec | decoding/encoding options by Go's encoding/json rules |
| codec-derive | #[derive(Options)] for ours-codec |
| dns-wire | RFC 1035 DNS messages |
geodat | V2Ray/Xray geosite.dat and geoip.dat |
| h2 | HTTP/2 for transports, without copies on the data path |
| http-client | HTTP/1.1 and an HTTP/2 connection pool over its own stream |
| journal | an append-only journal of records with CRC |
| json | JSON as sing-box reads and writes it, with positions |
| ktls-sys | unsafe: kTLS system calls |
metrics | per-thread counters and their Prometheus text for the Admin API's metrics |
| net-info | the host's network: netlink, INET_DIAG, /proc, nftables, conntrack |
| net-sys | Linux sockets: tproxy, mark, splice, zerocopy, netns |
| ntp-wire | the SNTP packet, computing the clock offset |
| quinn-ext | what quinn lacks for hysteria/hysteria2/tuic |
| sniff | detecting the protocol and domain from the first bytes |
| srs | the binary .srs rule-set format and its matchers |
| sys | unsafe: socket options by number, recvmsg/recvmmsg with control messages, a thread's CPU clock |
| tls13 | our own TLS 1.3: uTLS fingerprints, REALITY, kTLS, fragmentation |
| tun-sys | unsafe: TUN device ioctls |
| vlessenc | VLESS encryption (Xray): ML-KEM-768 + X25519 |
| wire | sans-IO codecs of what proxy protocols put on the wire: binary address layouts, UUIDs, varints |
| wireguard | the WireGuard protocol without I/O, TUN offloads |
| yaml | YAML 1.2 → a tree of values with positions |
Tests and fuzzing
Unit tests are in src/, integration tests — in each library's tests/; they are run with cargo test -p ours-<name> (through tests/run.py, see Checks).
Fuzzing — separate cargo-fuzz projects with their own [workspace], not part of the main workspace (the workspace members are only libs/*, not libs/*/fuzz). Every libs/<name>/fuzz/ is such a project; its targets are in fuzz/fuzz_targets/.
Run from the library's directory: cargo +nightly fuzz run <target>. Ordinary tests partially check the same properties without a fuzzer (for example, libs/srs/tests/mutations.rs).
The corpus (fuzz/corpus/) and libFuzzer findings (fuzz/artifacts/) are not stored in git: the corpus takes thousands of files per target and changes with every run, while coverage from an empty corpus builds up in minutes. In git — fuzz/regressions/<target>/: inputs on which a target once crashed, after the fix. A found crash is copied there together with the fix; checking all saved inputs without fuzzing:
sh
cargo +nightly fuzz run conn fuzz/regressions/conn -- -runs=0