English
Dashboard view
Code: crates/native-config/src/view.rs (runtime), crates/native-config/src/edit.rs, crates/native-config/src/tree.rs (Origin, Segment), app/ui/src/api.rs, app/ours/src/main.rs (check --view).
The dashboard shows the configuration in two ways: as the modules understood it (the runtime view) and as it is written (text objects). Origin links them.
The runtime view
ours_native_config::runtime(&Config) -> Value:
json
{
"sections": { "<key>": <canonical>, ... },
"inbounds": { "<name>": { "type": "<type>", "<block>": <canonical>, ... } },
"outbounds": { ... },
"endpoints": { ... },
"rule_sets": { ... }
}- The source is only
Config: sections with a non-emptycanonical, entities astype+ blocks. This is the view after all transformations: groups with resolved members, subscription servers, the syntheticblock, thedns.listenlisteners, thedomain_resolverblocks, thehijack-dnsrule first inroute.rules. - Field names are those of the sing-box option types (
routing_mark: "0x1",outbound,listen_port), not the native ones: this is the view of the decoded value. - The rules are those the router walks; their indices match the indices in the trace and in the component graph. Module conditions are lifted to the others (
flat).
Text objects
Along the way the loader records Origin { id, path, count } for every object:
id | path |
|---|---|
inbound[x] | inbounds.x; a DNS listener — dns.listen |
outbound[x] | outbounds.x, groups.x; a subscription server/group — subscriptions.<subscription>; the synthetic block — route.final |
endpoint[x] | endpoints.x |
rule-set[x] | rule_sets.x |
route, dns, route.final, dns.final | the key |
route.rules[i] | route.rules[j] with count (2 for do: options + to); a loader rule — dns.listen or route.final |
dns-server[x] | dns.upstreams.x or dns.fakeip |
dns.rules[i] | dns.rules[j] with count |
i is the index in the runtime view, j is the element's index in the text; they diverge when a rule takes two elements or the loader added its own. load_located returns origins, objects(source, decoders) — a map id → {path, text}, where text is a fragment of the source (object_fragment).
In-place editing
The dashboard changes the text, not the tree: the YAML is not regenerated, and the comments and formatting of the rest of the document are preserved.
replace_object(source, &origin, text)— replace an object (for an object made of several list elements — those elements);move_object(source, &origin, before)— move a list element before another one of the same list or to the end (rule order);object_fragment,path_text— read a fragment, a path as text.
After an edit the text is loaded again by the same loader; an error is returned with line:column in the new text. Saving to a file — only with a single -c.
check --view
ours check -c config.yaml --viewprints {"config": runtime(&config), "objects": objects(source)} — the same the dashboard gets, without starting an instance. Handy to see what defaults, group patterns, subscriptions and final turned into. Secrets are redacted unless --secrets is given.
Example: a group members: [direct-out, {match: "direct-*"}] gives in the runtime view "group": {"outbounds": ["direct-out"]} — the duplicate is dropped, the pattern is resolved; dial: {fwmark: 1} from defaults — "dial": {"routing_mark": "0x1"} on every outbound.
Other commands
checkwithout flags — loading, warnings,Instance::check(a build without starting and without opening the cache file).check --diff other.yaml— the reload plan between-candother.yaml(app/ours/src/diff.rs).check --fetch— the contents of the subscriptions (subscriptions).