Skip to content

Nesting and shared blocks ​

The rules of form by which every key of the native config is written. A new field is checked against them before it gets into the decoder and the schema.

A dependent field goes one level down ​

If a field makes sense only together with a neighbour, it is written inside it, not next to it with a prefix:

Instead of (sing-box, Xray)Ours
tls next to vlessvless: {…, tls: {…}} — not every protocol takes tls
update, via next to remoteremote: {url, update, via} — only a download has them
kernel_tx, kernel_rxktls: {tx, rx}
server_ports, hop_intervalhop: {ports, interval}
udp_relay_mode + udp_over_streamrelay: native | quic | stream — mutually exclusive ones become one field
sc_max_each_post_bytes, …posts: {max_bytes, …}

The reference's flat name is not accepted: the error says where the field has moved (`kernel_tx` is `ktls.tx`). This way every field has one spelling.

The kind is a key ​

Where a block selects a variant, the variant is the block's key, without a type field: transport: {ws: …}, obfs: {salamander: {password}}, mux: {smux: …}. A type field inside is an error (the kind is the key, no `type`). Parsing — config::unkind, variant_block.

Shared blocks depend on the side, but not on the protocol ​

A shared block (tls, transport, mux, dial, listener, tcp, udp, quic, reload) has one form in all protocols that take it. It may differ only by side:

BlockInboundOutboundRule (do: options)
tlsclient_auth, the server certificateclient, utls, spoof, fragmentfragment, spoof
udptimeout, fragmentfragmenttimeout, connect, disable_domain_unmapping
tcpfast_open, multi_path, keep_alivethe same—
quicthe same in hysteria, hysteria2, tuicthe same—

A protocol module decides only whether it takes the block as a whole (Provide::Blocks, decoders.takes); it does not change the block's form. Where a field's meaning is the same, the name is the same on all sides (udp.timeout on an inbound and in a rule).

What only one protocol has is written in its own block under its own name, not inside a shared block: nat in tproxy, relay in tuic, udp_over_tcp in socks and shadowsocks, fallback in trojan, handshake in shadowtls.

Where shared blocks live ​

  • Inside the protocol block — blocks that not every protocol takes: tls, transport, mux, quic. The loader takes out the first three (PROTOCOL_BLOCKS in entity.rs); quic is expanded by the protocol's decoder (ungroup(…, "quic", QUIC)).
  • Next to the protocol, at the entity level — socket and lifecycle blocks: dial on an outbound, listener on an inbound, reload. The address stays in the protocol: server on an outbound, listen on an inbound.
  • tcp and udp — inside dial and listener.

Default values ​

A dial setting can be given at three levels; the one closest to the outbound wins:

  1. the outbound's own dial;
  2. outbounds.defaults.dial — a template for outbounds, merged field by field;
  3. route.dial — for all of the kernel's sockets, including DNS upstreams and rule-set downloads.

The merge rules of outbounds.defaults — entities.

Code ​

  • ours_config (crates/config): ungroup (a block → flat option names, refusing flat names), unkind, dial_members, listener_block, tcp, route_dial, override_address, cache, the tables INTERFACES, DIAL_BIND, TCP, KEEP_ALIVE, DIAL_UDP, LISTEN_UDP, ROUTE_DIAL, ROUTE_INTERFACES, QUIC.
  • ours_config::schema: grouped, kinded, replaced, dial, listener_block, tcp, route_dial, cache — the same form in JSON Schema.
  • crates/native-config/src/entity.rs: split_entity (blocks inside the protocol), listener (an inbound's listener block).

GPL-3.0-or-later