Skip to content

Auxiliary crates crates/ ​

Crates that are neither a module (modules/*/*, ours-mod-*, which describe themselves with a MODULE constant) nor a libs/ library (which may not depend on anything in the workspace outside libs/). This is where shared code goes that needs the ours-api contract, but that itself registers nothing in the kernel: it is called by modules or by the binary. ours-auto-nft is the exception: it needs no contract, only the binary uses it.

crates/api (the contract) and crates/kernel (the kernel) are described separately — see Contract and Kernel. The dependency rules are in Layers.

CratePackagePurposeDepends on modules (normal dependencies)
configours-configparsing the configuration: node values, shared blocks, schema helpers, defaults, option types and factory traits (dial, mux, cache); read by the crates in CONFIG_READERS (rule P-6 in Layers)no
runtimeours-runtimethe host and socket runtime: listening, shard placement, the QUIC window budget, the system Host (SystemHost)no
http-configours-http-configthe options of the HTTP clientno
native-configours-native-configthe native YAML loader, text editing, JSON Schemano
testkitours-testkitconfiguration loading and a free port for testsno
dns-typesours-dns-typesthe types of the dns section and the DNS rule interfaceno
relayours-relaypumping data between the sides, UDP NATno
route-apiours-route-apithe rule walk and the module conditions a rule keeps as writtenno
trackerours-trackerthe table of live connections, diagnosticsno
uotours-uotUDP-over-TCP v1/v2no
httpours-httpthe HTTP client for rule-sets, DoH, probes, subscriptions, tunnelsno
quicours-quicQUIC endpoints for hysteria/hysteria2/tuicno
transport-apiours-transport-apithe transport contract: client and server traits, Setup, the transport block's variants, the V2Ray*Options; protocols and transport modules take it instead of the transport moduleno
protoours-protowhat the protocol modules share: fallbacks, HTTP and SOCKS servers, HTTP/1 and HTTP/2 handshakes, decoy; see belowno
tls-optionsours-tls-optionsthe TLS options, the decoding of the tls block and Tls, the factory of TLS clients and servers the tls module publishesno
auto-nftours-auto-nftthe nftables table and policy routing for auto_nftno

ours-proto is split into features, one per shared piece:

  • fallback — fallbacks: trojan, vless, mtproto;
  • http-server, socks-server — the HTTP and SOCKS servers: http, socks, mixed;
  • http1 — bounded HTTP/1 handshake parsing: transport-ws, transport-httpupgrade, transport-xhttp; its Prefixed keeps splice and kTLS after the handshake;
  • h2 — the HTTP/2 tunnel of the HTTP-based transports: transport-http, transport-grpc, transport-xhttp;
  • decoy — the answer to a foreign connection: trojan, vless, anytls, mtproto;
  • users — the user lists of inbounds with users.

Plus app/ui — the Admin API and the dashboard: ui. It is not in crates/ but in app/, because it depends on ours-kernel, and only app/ crates are allowed to.

Why not a module and not a library ​

  • Not a module: the crate provides no inbound/outbound type, no section, no extension point; its code is needed by several modules at once (ours-relay — direct, shadowsocks, tproxy, tun, wireguard, dispatch, ours-proto; ours-proto — http, socks and mixed; ours-quic — three QUIC protocols). Were it a module, requires and services would be needed for an ordinary function call.
  • Not a library: it needs ours-api (Stream, Metadata, Outbound, options); what it takes from a module comes through the contract (ours-http builds TLS clients and ours-proto takes TLS servers through ours_api::tls, ours-quic dials through ours_api::udp). tests/layers.py forbids libraries to depend on anything outside libs/.

A module's dependency on a crate that itself depends on a module does not go into requires directly; the binary's test a_module_requires_the_modules_its_crate_depends_on checks only the direct dependencies of a module's crate on other modules' crates (see how-to: a module in the binary).

GPL-3.0-or-later