English
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 vless | vless: {…, tls: {…}} — not every protocol takes tls |
update, via next to remote | remote: {url, update, via} — only a download has them |
kernel_tx, kernel_rx | ktls: {tx, rx} |
server_ports, hop_interval | hop: {ports, interval} |
udp_relay_mode + udp_over_stream | relay: 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:
| Block | Inbound | Outbound | Rule (do: options) |
|---|---|---|---|
tls | client_auth, the server certificate | client, utls, spoof, fragment | fragment, spoof |
udp | timeout, fragment | fragment | timeout, connect, disable_domain_unmapping |
tcp | fast_open, multi_path, keep_alive | the same | — |
quic | the same in hysteria, hysteria2, tuic | the 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_BLOCKSinentity.rs);quicis expanded by the protocol's decoder (ungroup(…, "quic", QUIC)). - Next to the protocol, at the entity level — socket and lifecycle blocks:
dialon an outbound,listeneron an inbound,reload. The address stays in the protocol:serveron an outbound,listenon an inbound. tcpandudp— insidedialandlistener.
Default values
A dial setting can be given at three levels; the one closest to the outbound wins:
- the outbound's own
dial; outbounds.defaults.dial— a template for outbounds, merged field by field;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 tablesINTERFACES,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'slistenerblock).