English
Subscriptions
Code: modules/config/subscriptions/src/config.rs (section, expand, groups, apply_patch), crates/native-config/src/entity.rs (supplied_outbounds, the "gone" step), crates/native-config/src/tree.rs (Names), app/ours/src/subscriptions.rs.
A subscription is a section that supplies entities: servers become outbounds, the provider's groups become groups. The loader knows nothing about subscription formats: it gets entities from the module in native form and decodes them like written ones.
The module's declarations
rust
Provide::Section { key: "subscriptions", kind: None, decode: config::section }, // settings
Provide::Source { section: "subscriptions", expand: config::expand }, // entities right now
Provide::Unit(|| Box::new(runtime::Follow)), // downloading, the storeThe section and the source are separate: section gives the value (Subscriptions, a list of settings) by which the unit follows the subscriptions; expand gives out what the subscriptions contain right now.
Where expand takes servers from
expand(node, scope, held) reads the parsed servers not from the network but from the process's store (store, filled by the unit and by runtime::prime) — or from held, if the caller replaced it with Decoders::with_held("subscriptions", ...) (tests, a dashboard draft). So loading a configuration does not go to the network; the first prime pass reads file subscriptions and the cache file, and loading is repeated (loading).
What expand does
scope.namespace(name)for every subscription — before the servers:viacannot point to a subscription server, andname/...references are recognized as the subscription's namespace.- For every subscription: renaming, filters, protocols,
patch(candidates,apply_patch:nullremoves,dial/muxare added,tls/transport/the protocol are changed only where present). - Every candidate is checked with
scope.accepts(&Entity)— a trial lowering by the loader (entity::accepts). A server that did not load is thrown out with the warningsubscription `x`: `y` is left out: ..., together with those that go through it (drop_dependents). - Given out are
Entity { section: "outbounds", name: "<subscription>/<server>", namespace: Some(subscription) }and groups: those described by the provider (namespace: Some) and the subscription's own group named after the subscription, collecting all its servers (namespace: None).
What the loader does
supplied_outbounds:
- decodes the section as an ordinary one, then
Decoders::expand; - groups: the name in
Names—add_supplied(in the subscription's namespace) oradd(the subscription's group, an ordinary name, a conflict with a written one is an error); groups are appended after the written ones; - servers:
Names::add_server(a name with/, unique by construction),Origin—subscriptions.<subscription>; the outbound is lowered withoutbounds.defaultsand without checkingdial.detour(the module wrote it in).
A subscription's namespace is protected by the naming rules: servers are available only to groups (members, match: "work/*"), not to final, to or detour.
Emptiness is allowed
The set of servers changes in a running process, so a pattern, a group or a default that selects no server right now is a warning, not an error — see warnings. A DNS rule outbound: work/* with no servers matches nothing.
Vanished groups → final
A reference group: work/fast to a group the provider does not currently describe is accepted (Names::of_kind puts the name into gone). After route, for every such group the loader creates a substitute — a group with this name and the single member route.final (if final is an existing outbound or group):
WARN group `work/fast` is not among those of its subscription now: what goes to it goes where `final` saysIf final is not an outbound (block, a rule), the substitute is empty and refuses connections. This way a rule leading to a provider's group does not break loading when the provider removed it, and traffic keeps going by default.
Reload when servers change
The unit reports a change of servers (runtime::changes); the binary rereads the active configuration text (reload_subscriptions) with the same subscriptions::load and calls Instance::reload. Group patterns are recomputed, and the graph and fingerprints decide what to rebuild (canonical form).
check --fetch downloads the subscriptions once through the outbounds of a built but not started instance and prints the contents.
See also the subscriptions module.