Skip to content

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.

Crateours-mod-subscriptions, modules/config/subscriptions
Binary featuresubscriptions (the module in the list, runtime); the formats sub-links, sub-xray, sub-clash
Crate featureslinks, 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 with runtime) — build assembles a Reach (DialTable, DNS, Tls, the cache options), commit hands it to the manager; close stops 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 (Skipped without addresses and credentials); PROTOCOLS, Server, Group.
  • src/links.rs, src/url.rs, src/base64.rs — share links (URL parsing like Go's net/url).
  • src/xray.rs, src/xhttp.rs — Xray JSON, xhttpSettings and extra; 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/mihomo proxies; YAML with anchors and merge keys.
  • src/common.rs, src/json.rs, src/collector.rs — what the formats share, building outbounds, the Collector (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 and check see 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 its reload.connections), follow (a file — on change, a URL — every update, conditional requests by ETag/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.

GPL-3.0-or-later