English
Add a subscription format
Subscriptions are read by the subscriptions module (modules/config/subscriptions, the ours-mod-subscriptions crate). A format is a reader function; the module tries the readers in order and translates the understood servers into outbounds of the native schema, which the protocol modules then decode at load time.
How it works
parse(content, supported)(modules/config/subscriptions/src/lib.rs):- the whole content may be in base64 (
decode_base64) — any format, not only a list of links; - empty (
"",[],{}) —Error::Empty; - the readers from
READERSin order; the first that returnsSome(Collected)decides; if none does,Error::Unrecognized; finishdrops servers of protocols not inPROTOCOLSor not built into the binary (supported), then chains with a dropped link (dials through a server that could not be imported); nothing left —Error::NoneImportedwith the first reason.
- the whole content may be in base64 (
type Reader = fn(&str) -> Option<Collected>:None— "not my format".READERS— the order from the strictest to the loosest: Xray JSON (recognized by its members), Clash (byproxies), links — last.Collector(src/collector.rs) — what a reader gives its result through:add(tag, name, label, outbound),claim/add_claimed(a tag in advance, fordetour),group(name, members, rank),skip(tag, label, reason)(with a tag, those that dial through it drop out too),direct(tag)(freedom/DIRECT: dialing through it is not a detour),discard(tag)(REJECT),label(index, name),finish().json::Outbound/Object/Transport(src/json.rs) — building an outbound the way the native schema writes it. Shared parsing (uTLS, ECH, VLESS flow, ports, bandwidths, group ranks) is insrc/common.rs.
Steps
The file
modules/config/subscriptions/src/<format>.rswithpub fn read(content: &str) -> Option<Collected>: returnNonequickly if the content does not look like the format (aslinks::readchecks for://); otherwiseCollector::new(FORMAT), per server —addorskipwith a reason,finish().Labels (
label) name a server by position and name, never by address or credentials: the report about skipped servers is visible in logs and the dashboard.A feature in
modules/config/subscriptions/Cargo.toml:<format> = [...](an external parser —dep:), add it todefault. Insrc/lib.rs:rust#[cfg(feature = "<format>")] mod <format>; // and in READERS — at its place by strictness: #[cfg(feature = "<format>")] <format>::read,If the format uses
common/xhttp, add it to their#[cfg(any(...))].The binary:
sub-<format> = ["subscriptions", "ours-mod-subscriptions/<format>"]inapp/ours/Cargo.tomland indefault. No line inLISTis needed: there is one module (subscriptions), and the format is its feature.
Tests
modules/config/subscriptions/tests/formats.rs with fixtures in modules/config/subscriptions/tests/data/: per format — a sample file and <file>.expected.json (the result of render), plus tests for skips and errors under #[cfg(feature = "<format>")]. Loading subscriptions in a configuration (names, filters, groups) — crates/native-config/tests/subscriptions.rs.