Skip to content

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 on ours-api, nor on modules, nor on crates/. Checked by tests/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 in crates/.

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 ​

LibraryPurpose
allocthe global allocator of the binary: jemalloc on x86_64 and aarch64 (see Build)
atomic64a 64-bit counter on any target, including MIPS32
clockthe process time: the system clock moved by the ntp offset
bufpoolbuffers with headroom and their pools
codecdecoding/encoding options by Go's encoding/json rules
codec-derive#[derive(Options)] for ours-codec
dns-wireRFC 1035 DNS messages
geodatV2Ray/Xray geosite.dat and geoip.dat
h2HTTP/2 for transports, without copies on the data path
http-clientHTTP/1.1 and an HTTP/2 connection pool over its own stream
journalan append-only journal of records with CRC
jsonJSON as sing-box reads and writes it, with positions
ktls-sysunsafe: kTLS system calls
metricsper-thread counters and their Prometheus text for the Admin API's metrics
net-infothe host's network: netlink, INET_DIAG, /proc, nftables, conntrack
net-sysLinux sockets: tproxy, mark, splice, zerocopy, netns
ntp-wirethe SNTP packet, computing the clock offset
quinn-extwhat quinn lacks for hysteria/hysteria2/tuic
sniffdetecting the protocol and domain from the first bytes
srsthe binary .srs rule-set format and its matchers
sysunsafe: socket options by number, recvmsg/recvmmsg with control messages, a thread's CPU clock
tls13our own TLS 1.3: uTLS fingerprints, REALITY, kTLS, fragmentation
tun-sysunsafe: TUN device ioctls
vlessencVLESS encryption (Xray): ML-KEM-768 + X25519
wiresans-IO codecs of what proxy protocols put on the wire: binary address layouts, UUIDs, varints
wireguardthe WireGuard protocol without I/O, TUN offloads
yamlYAML 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

GPL-3.0-or-later