English
subscriptions
Subscriptions: reads servers from share links, Xray JSON and Clash YAML (in base64 or not) and turns them into <subscription>/<server> outbounds of the native schema; at run time it keeps the content up to date and reloads the configuration when it changes.
| Crate | ours-mod-subscriptions, modules/config/subscriptions |
| Binary feature | subscriptions (the module in the list, runtime); the formats sub-links, sub-xray, sub-clash |
| Crate features | links, xray, clash (saphyr-parser), runtime (ours-tls-options, ours-http, ours-net-sys, tokio, …), cache (ours-journal, crc32fast: saved subscriptions; the binary's cache enables it) |
The crate is linked into the binary unconditionally (without default features), but MODULE gets into the list only with the subscriptions feature.
requires
tls, cache, dial — downloading goes through the outbounds and DNS of the current configuration (DialTable) with TLS from the ours_tls_options::Tls factory, and the last content is stored in the cache file's directory (<scope>/subscription/<name>, the path from CacheFileOptions); the module keeps these files itself, so it does not depend on ours-mod-cache.
provides
Provide::Section { key: "subscriptions" }— the subscription settings.Provide::Source { section: "subscriptions", expand: config::expand }— the subscription's servers as outbounds: renaming, filters, patches; each is checked as an ordinary outbound by its protocol's module at load time.Provide::Unit(runtime::Follow)(only withruntime) —buildassembles aReach(DialTable, DNS,Tls, the cache options),commithands it to the manager;closestops it.
Syntax: subscriptions.
Dependencies
ours-http, ours-tls-options, ours-journal, ours-net-sys (watching a file), ours-api, ours-codec, ours-json, saphyr-parser, regex (only with runtime: a build without it loads no subscriptions), base64, sha2.
Design
src/lib.rs—parse(content, supported): a server of a protocol not in the build, and a server that goes through it, are skipped with a reason (Skippedwithout addresses and credentials);PROTOCOLS,Server,Group.src/links.rs,src/url.rs,src/base64.rs— share links (URL parsing like Go'snet/url).src/xray.rs,src/xhttp.rs— Xray JSON,xhttpSettingsandextra; a setting without a counterpart excludes the server (the client must ask for exactly what the server serves).src/clash.rs,src/yaml.rs— Clash/mihomoproxies; YAML with anchors and merge keys.src/common.rs,src/json.rs,src/collector.rs— what the formats share, building outbounds, theCollector(a chain without its base is not imported broken).src/config.rs— the section and expanding the servers.src/store.rs— one store per process: the start, reload, the dashboard andchecksee the same servers.src/runtime.rs—prime(before loading — a file or the cache, without the network),update,status(the Admin API),changes(the "servers changed" channel for the binary, which reloads the configuration according to itsreload.connections),follow(a file — on change, a URL — everyupdate, conditional requests byETag/Last-Modified).src/saved.rs—SavedSubscription: the last download, in its own format (SBCS) at<scope>/subscription/<name>in the cache directory.
Tests
modules/config/subscriptions/tests/formats.rs — fixtures from real providers with the expected result next to them (UPDATE_EXPECTED=1 rewrites it); unit tests in most src/ files; end-to-end — app/ours/tests/subscriptions.rs.