Panel clients
Source files: 28 · checked against katana v6.1.0 · Etemenanki 2f00a88
katana/src/api/mod.rskatana/src/api/newv2board.rskatana/src/api/hysteria.rskatana/src/api/helium.rskatana/src/api/embedded_cert.rskatana/src/blocking.rskatana/src/config.rskatana/src/runtime.rskatana/src/main.rskatana/src/manager/mod.rskatana/src/manager/node.rskatana/src/lower/mod.rskatana/src/lower/inbound.rskatana/src/rule.rskatana/Cargo.tomlkatana/tests/unit/api/http.rskatana/tests/unit/api/newv2board.rskatana/tests/unit/api/helium.rskatana/tests/unit/lower/spec.rskatana/tests/unit/lower/inbound.rskatana/tests/unit/rule.rskatana/tests/unit/e2e.rskatana/tests/unit/runtime.rskatana/tests/unit/manager/node.rskatana/tests/support/mod.rskatana/tests/integration/xray_interop.rskatana/tests/integration/hysteria_interop.rsEtemenanki/supervisor/src/entity/user.rs
The api module is katana’s only contact with a panel. It turns two unrelated HTTP APIs, newV2board’s UniProxy and helium’s node API v2, into one small vocabulary: a Node that describes the node’s listener, a list of UserInfo, a list of compiled audit rules, and one report going the other way, a NodeReport of traffic and client addresses. Node is the node config of the helium-node-api crate, the contract katana shares with helium: helium’s config answer is one already, and since 6.1.0 the newV2board client converts a UniProxy answer into one, refusing by name what katana cannot serve as it reads the answer. Everything above it sees only that vocabulary: the node manager polls through it, lowering turns its answers into the supervisor’s spec, and traffic accounting reports through it. The newV2board client came over from katana 3. helium’s joined in 4.5.0; since 5.0.0 it speaks helium’s node API v2 alone and reads every body as a type of the helium-node-api crate, which helium serializes from the same definitions. katana 6.0.0 removed the SSPanel client, and with it the audit-hit report only SSPanel took (see Upgrading to katana 6). Every panel user is keyed by uid, and a node’s listener, users and audit rules are one lowered spec (see Lowering a node into a spec).
Read this page before you add a panel field, support a new node type, change how a response is parsed, or touch anything that could put the panel key into a log line. The operator’s view of the same behaviour is on Xboard and V2board (UniProxy) and helium.
Responsibilities
Section titled “Responsibilities”The module does seven things:
- Fetch the node description (
node_info) and the user list (user_list) as panel-independent values: helium’s config answer as the contract’sNodeit is, a UniProxy answer converted into one. - Refuse what katana cannot serve in a UniProxy answer, by name, as it is read: a transport other than TCP, WebSocket and gRPC, a TCP header other than
none, a flow other than Vision, REALITY off VLESS, SOCKS or HTTP without TLS, a Shadowsocks cipher katana does not serve, and every rule of the contract’svalidate(see Node configuration). On helium the contract’sDeserializerefuses the same. - Save bandwidth with a per-endpoint ETag cache, reporting an HTTP 304 answer as
Ok(None)instead of parsing the same body again, and by asking for every answer gzip-compressed. - Report a
NodeReport(report) in each panel’s body format. - Build the audit rule list (
node_rule) from an optional local rule file and, on newV2board, the panel’s block routes. - Keep the panel key out of status errors and out of the lines the node manager logs for panel errors, because newV2board carries it in the query string. helium carries it in an
Authorizationheader. - Parse off the async runtime. Each client parses its user list on the blocking pool through
blocking::off_runtime, because a list of tens of thousands of users takes long enough to stall every connection a worker serves.
It does not:
- decide what a change means. Lowering builds the node’s
Specfrom the answers, andNodeManager::reconciledecides whether an apply also closes every session. Both are on The node manager. - retry. A failed call returns an error. The node manager retries a failed bootstrap attempt with a backoff from 1 s to 60 s, capped at the poll period; after bootstrap, the next poll requests the node, the users and the rules again.
- judge this host’s settings. The certificate settings, the listen address, the PROXY and real-IP trust, handoff, the VMess clock check, and Hysteria 2’s credential kind and congestion control are not in the contract, and lowering judges them (see Lowering inbounds and outbounds). So does an sss chain: the contract holds each expression to its shape, and lowering parses it.
- turn a user record into a credential.
src/lower/inbound.rs→credentialsdoes that; this page summarizes it in From user records to credentials. - match destinations. Audit rules become routes to blackhole outbounds inside the supervisor (see Destination audit).
- report online users or node status. Only helium’s report carries the client addresses users connected from, and only where
enable_device_limitsays the node sees real ones.
| File | Contents |
|---|---|
src/api/mod.rs |
Shared models (NodeType; Node, a type alias of helium_node_api::config::NodeConfig; UserInfo, UserTraffic, NodeReport, DetectRule, RouteRule), unit conversion, EtagCache, error_for_status, build_http_client and http_client_builder, read_local_rules, panel_node_type, traffic_email, and the PanelClient enum with its constructor. Its tests module is tests/unit/api/http.rs. |
src/api/newv2board.rs |
The UniProxy client, the free function node_type_param, the constant NO_SSS, and the private conversion of a UniProxy config into the contract’s node: parse_node_config, check_protocol, the per-type builders v2ray, shadowsocks and proxy, the readers tls (with the enum TlsField), transport (with the enum Network), plain_tcp_header, either_settings, header_host and the REALITY reader reality, the error helpers unsupported and json_error, the lenient readers lenient_number, lenient_flag and mbps, detect_rules, and the private response structs ServerConfig, NetworkSettings, Route, UserListResponse and UserResponse. |
src/api/hysteria.rs |
A Hysteria 2 node a panel cannot describe in full, in the contract’s terms: local builds the node [node.hysteria] describes on its own, uniproxy completes a UniProxy node with [node.hysteria]’s UDP relay, masquerade and rate overrides, and obfs reads Salamander obfuscation as a panel or the block names it. The private complete, udp and masquerade build the rest (see Completing a Hysteria 2 node). |
src/api/helium.rs |
The helium client for node API v2, refuse_local_protocol, the parser parse, the mappings of the users and the report to and from katana’s models (parse_users, user_infos, report_body), and the private struct Fetched. The config answer is not mapped: it is a Node already. |
Cargo.toml |
The dependency on the helium-node-api crate (0.2.0), which holds the wire types of helium’s node API v2, katana’s node model among them: config::NodeConfig, users::Users, report::Report and report::ReportAnswer. reqwest’s features, gzip among them. |
src/api/embedded_cert.rs |
node_client_identity, the client certificate katana presents when a panel asks for one, unless the node sets enable_mtls = false. |
src/blocking.rs |
off_runtime and drop_off_runtime: work that grows with a node’s users, run on the blocking pool. |
src/config.rs |
NodeConfig with panel_type, enable_mtls and api, and ApiConfig, the [node.api] keys each client copies. |
src/runtime.rs |
The callers of PanelClient::new at startup, at reload and in --test, and the node identity (identity, display_id) that decides when a config edit respawns a node instead of reconfiguring it. |
src/manager/node.rs |
NodeManager, the only caller of the client’s methods. It builds the node of a local Hysteria 2 node with api::hysteria::local, and rebuilds and swaps the client when a config edit touches a field the client was built from. |
src/lower/mod.rs, src/lower/inbound.rs, src/rule.rs |
The consumers: test_spec, lower_users, lower_inbound with lower_hysteria, credentials, RuleManager and audit_routes. |
Where the models go
Section titled “Where the models go”| Model | Produced by | Consumed by |
|---|---|---|
Node |
node_info, or api::hysteria::local for a newV2board Hysteria 2 node with a local port |
lower::inbound::lower_inbound, which builds the node’s InboundSpec; NodeManager keeps the last applied one in Applied.node and compares the polled one with it through disruptive_part |
Vec<UserInfo> |
user_list |
lower::lower_users, which builds one UserSpec per admitted user, keyed by lower::Uid |
Vec<DetectRule> |
node_rule |
RuleManager::update; rule::audit_routes turns the rules in force into routes when the node’s spec is lowered |
NodeReport |
NodeManager::report, from Supervisor::take_usage and, on helium, the sessions’ sources |
PanelClient::report |
Key types
Section titled “Key types”PanelClient
Section titled “PanelClient”The two clients share no trait. PanelClient is a plain enum, and each method is a two-arm match that forwards to the concrete client:
pub enum PanelClient { NewV2board(newv2board::Client), Helium(helium::Client),}
impl PanelClient { pub fn new(cfg: &NodeConfig) -> Result<Self>; pub fn keeps_client_ips(&self) -> bool; pub async fn node_info(&self) -> Result<Option<Node>>; pub async fn user_list(&self) -> Result<Option<Vec<UserInfo>>>; pub async fn report(&self, report: &NodeReport) -> Result<()>; pub async fn node_rule(&self) -> Result<Option<Vec<DetectRule>>>; pub fn forget_etags(&self); pub fn inherit_routes(&self, old: &PanelClient);}Result is anyhow::Result. The enum keeps calls statically dispatched and the futures concrete, so NodeManager holds a PanelClient without boxing or an async trait. Adding a third panel means a new module, a new variant, an arm in new, and one arm in each of the five forwarding methods (the four panel calls and forget_etags), plus keeps_client_ips if its reports carry client addresses. inherit_routes and panel_node_type need an arm only if the new client learns state from responses, or if its panel finds a node by more than its id.
Ok(None) has one meaning in all three Option return types: the panel answered 304 Not Modified. Neither client’s node_rule sends a request, so neither returns it there.
| Method | newV2board | helium |
|---|---|---|
node_info |
GET /api/v1/server/UniProxy/config |
GET /api/node/v2/{node_id}/config |
user_list |
GET /api/v1/server/UniProxy/user |
GET /api/node/v2/{node_id}/users |
report |
POST /api/v1/server/UniProxy/push with the traffic; no request when there is none |
POST /api/node/v2/{node_id}/report with the whole report |
node_rule |
No request: built from the routes that node_info cached, plus the local rule file. Always Ok(Some(_)). |
No request: the local rule file alone. Always Ok(Some(_)). |
forget_etags |
No request: EtagCache::clear. |
No request: EtagCache::clear. |
inherit_routes |
No request: copies the cached routes of old when both clients are newV2board. |
No-op: helium sends no routes. |
keeps_client_ips |
false |
true |
Construction
Section titled “Construction”PanelClient::new lowercases panel_type and matches it against "newv2board", its alias "v2board", and "helium". "sspanel" is refused by name, so that a node which ran on SSPanel before is not taken for a typo: panel_type "SSpanel" is not supported: katana serves the NewV2board and Helium panels, the value quoted as the file spells it. Anything else fails with unknown panel_type "foo" (the lowercased value). Then each client checks the node’s local config before it builds anything:
- newV2board’s
Client::newparsesapi.node_typewithNodeType::parseand fails withunknown node_type "Vmess2"(the value as written; a missingnode_typeisunknown node_type ""). It also refuses an sss node withNO_SSS(see sss). - helium’s
Client::newreads no node type. It callsrefuse_local_protocol, which refuses a node that sets[node.api] node_type,enable_vlessor any[node.hysteria]key butcongestion(see Local keys a helium node refuses).
Client::new also fails if reqwest cannot build its client, for example because the TLS backend does not initialize. These checks run before build_http_client, so a bad node_type or a refused key is the error reported even on a host where reqwest could not build its client either.
| Caller | When | On error |
|---|---|---|
runtime::test_config |
katana --test (-c/--config names the file, default config.toml) |
Stops at the first node that fails; main prints it and exits with status 1, for example configuration error: node 1: unknown panel_type "foo". A node still on SSPanel prints configuration error: node 1: panel_type "SSpanel" is not supported: katana serves the NewV2board and Helium panels. When every node passes, it prints Configuration OK and exits with status 0. --test never contacts the panel. |
runtime::build_node, from spawn_node |
Startup | Logs ERROR katana::runtime: node 1: unknown panel_type "foo" and does not run the node. If no node builds, katana logs no nodes could be started and exits. |
runtime::build_node, from apply_reload |
A reload that adds a node, or changes a node’s identity | Refuses the whole reload before touching a running node. |
runtime::apply_reload |
A reload that changes a running node’s config, or the outbounds or DNS | Builds the client only to check it, then drops it. A failure refuses the whole reload. |
NodeManager::apply_static |
A StaticUpdate::Config that changes panel_type, any [node.api] field, enable_mtls or [node.hysteria] |
Builds the client the node will use from now on; see Config edits and the running client. |
test_config, build_node and the reload check build the client and then run check_node, which checks lower::test_spec with the supervisor. Without a panel answer there is no Node, so for most node types that spec holds only the shared outbounds, DNS and routes. test_spec first judges the local settings of every node, whatever its type: the real-IP header (inbound::real_ip), the handoff socket (inbound::handoff) and [node.hysteria] congestion (inbound::congestion), so unknown hysteria congestion "vegas" (expected "cubic", "bbr" or "reno") is reported by --test on any node. On newV2board a Hysteria 2 node’s listener settings are local, so for a node whose node_type parses to Hysteria2 test_spec lowers the node api::hysteria::local builds from [node.hysteria], on the block’s port or, when that is 0, on port 1 (NonZeroU16::MIN), and admits one placeholder user (uid 0, UUID text placeholder). Its listener settings, the block’s obfuscation, UDP relay and masquerade among them, are therefore checked before the panel is asked. A helium node has no node_type, so it is judged as every other node is: its listener is checked when the panel’s answer is lowered. The spec itself is on Lowering a node into a spec.
A refused reload logs the node by its display identity, captured from the v4.6.0 binary:
ERROR katana::runtime: reload: node newv2board@https://panel.example.com#1/vmess2: unknown node_type "Vmess2"; keeping current configThis edit also changes the node_type the node asks the panel for, and so its identity: the line shows the new one. On helium the identity does not include the node type, and any node_type at all refuses the reload, with the refuse_local_protocol message.
Each client copies what it needs from NodeConfig at construction and never reads the config again:
| Field copied | newV2board | helium |
|---|---|---|
api.host, trailing / trimmed |
base_url |
node_url, with /api/node/v2/{node_id} appended |
api.node_id |
node_id |
in node_url |
api.key |
token |
token |
api.node_type |
node_type, and node_type_param |
refused when set |
api.enable_vless |
enable_vless, and node_type_param |
refused when set |
api.speed_limit |
speed_limit_mbps |
speed_limit_mbps |
api.rule_list_path |
rule_list_path |
rule_list_path |
api.timeout |
baked into http |
baked into http |
api.device_limit |
not used | not used |
enable_mtls |
baked into http |
baked into http |
[node.hysteria] |
hysteria, a copy of the whole block, which completes a Hysteria 2 node (api::hysteria::uniproxy); lowering reads credential and congestion from the node’s own config |
every key but congestion refused when set; nothing copied |
ApiConfig is #[serde(deny_unknown_fields)] and every field has a serde default. A mistyped [node.api] key therefore stops the config from loading instead of being ignored, and a key left out takes its default: an empty string, 0, or false. katana 6.0.0 removed vless_flow and disable_custom_config from ApiConfig, so a file that still sets either fails the parse as an unknown key. A helium node must leave node_type and enable_vless at their defaults. enable_mtls is not in [node.api]: it sits directly under [[node]], on NodeConfig, and defaults to true (default_enable_mtls). timeout = 0 is read as 5 s by ApiConfig::timeout_secs. The whole schema is on Runtime and config reload.
Because the trailing / is trimmed, https://panel.example.com/ and https://panel.example.com send the same requests. A host with a path prefix keeps it: every endpoint path is appended to base_url.
Node identity
Section titled “Node identity”type NodeId = (String, String, u32, String, String);// (panel_type lowercased, api.host, api.node_id, api.key, api::panel_node_type(cfg))
fn identity(cfg: &NodeConfig) -> NodeId;fn display_id(id: &NodeId) -> String;pub fn panel_node_type(cfg: &NodeConfig) -> String;pub fn node_type_param(api: &ApiConfig) -> String;panel_node_type returns newv2board::node_type_param(&cfg.api) for a newv2board or v2board node, and an empty string otherwise. UniProxy finds a node by its id and the node_type it is asked for, so one id asked as vless and as v2ray is two panel nodes, each with its own users and traffic. helium finds a node by its id alone; a helium node has no node type of its own, because the panel’s config answer names the protocol. api.timeout, api.speed_limit, api.rule_list_path and enable_mtls are not part of the identity on either panel, and api.host is compared as written, before any trimming.
A change to any of the five values makes the entry another panel node: the runtime removes the running node and spawns a new one, with a new client, a new HTTP connection pool, an empty ETag cache and a new supervisor. On newV2board that includes an edit to api.node_type or api.enable_vless that changes the node_type parameter. "V2ray" to "v2ray" does not, and neither does enable_vless on a Trojan node. How the runtime classifies each reload is on Runtime and config reload.
display_id renders an identity for logs as panel@host#node_id for helium and panel@host#node_id/node_type for newV2board, for example newv2board@https://panel.example.com#1/v2ray. It destructures the key and never formats it.
Config edits and the running client
Section titled “Config edits and the running client”Every other edit to a node reaches the running node as StaticUpdate::Config, sent over the bounded channel (16 updates) that runtime::spawn_built gives each node. NodeManager::apply_static compares the old and new config and builds a new client when panel_type differs (a change of case included), when any [node.api] field differs (ApiConfig derives PartialEq, so api.device_limit, which nothing reads, counts too), when enable_mtls differs, because the client is built with or without the certificate, or, since 6.1.0, when [node.hysteria] differs (HysteriaConfig derives PartialEq), because the newV2board client completes a Hysteria 2 node with its own copy of the block. A helium client copies nothing of the block, but a congestion edit builds a new one all the same:
PanelClient::new(&new_cfg)builds the client.inherit_routescopies the running client’s cached newV2board routes into it, so the block rules derived from them hold until the new client reads the node config itself, even if the panel is unreachable at that moment. helium sends no routes, so for it this does nothing.- The new config and the new client replace the old ones in
NodeManager.cfgandNodeManager.api. - If the node is up, it runs one poll at once. The new client holds no ETags, so that poll reads the node and its users in full, as the edited settings read them. A node that is still bootstrapping stores the client and starts its next attempt at once.
If step 1 fails, the node logs node {id}: config edit refused, keeping the running one: {e} at ERROR and keeps its current client and config. The reload check in apply_reload builds a client from each running node’s edited config before any update is sent, so a typo such as an unknown node_type, or a key a helium node refuses, is refused there, for the whole reload. This branch catches a client that does not build at swap time, for example when reqwest cannot build its client.
The same poll also runs, with rebuild set, when the edit changes a local setting the listener or its routes are built from: [node.route], controller.listen_ip (the listener is built from it), controller.cert, controller.disable_sniffing or anything in [node.hysteria]. The panel’s answer cannot show such an edit, so the apply that follows closes every session. Since 6.0.0 api.enable_vless is not on the list, because lowering no longer reads it. On a newV2board V2ray node an edit to it changes the node_type parameter, and so the identity, and respawns the node, unless node_type is vless already; there, as on a node of another type, it builds a new client, and the poll applies whatever the new client’s answer changes; a helium node refuses the key. On a helium node, where congestion is the only [node.hysteria] key allowed, a congestion edit takes this path, with a new client. A StaticUpdate::Globals, sent when [[outbound]] or [dns] changes, builds no client and sends no request: the node lowers its last panel answer again under the new outbounds and DNS, and that apply closes every session too. The effect of each kind of change is tabulated on The node manager.
NodeManager holds the client as parking_lot::Mutex<Arc<PanelClient>>, so the swap needs no &mut self. Every call site clones the Arc first (NodeManager::api) and releases the lock before the request.
NodeType
Section titled “NodeType”pub enum NodeType { V2ray, Trojan, Shadowsocks, Hysteria2, Anytls, // AnyTLS, over TLS Socks, // a SOCKS5 proxy, over TLS only Http, // an HTTP proxy, over TLS only Sss, // sss, over any stream transport but REALITY}
impl NodeType { pub fn parse(s: &str) -> Option<Self>;}NodeType is Copy and Eq. parse lowercases its input (ASCII) first:
| Accepted, any case | Variant |
|---|---|
v2ray, vmess, vless |
V2ray |
trojan |
Trojan |
shadowsocks |
Shadowsocks |
hysteria2, hysteria, hy2 |
Hysteria2 |
anytls |
Anytls |
socks, socks5 |
Socks |
http |
Http |
sss |
Sss |
katana 4.9.0 added Anytls, Socks and Http, and 4.10.0 added Sss. On newV2board the node_type parameter of a new type is its lowercased name, for example anytls. Since 5.0.0 newV2board refuses Sss too: only helium describes an sss node.
NodeType::parse reads api.node_type on newV2board, where it picks the arm of parse_node_config that builds the node, and the protocol tag of a UniProxy answer (see The protocol tag). A helium node parses no name: the config answer’s protocol tag picks the Node variant as the crate deserializes it (see Node configuration and rules). NodeType is not part of a Node, whose variants name VMess and VLESS apart; src/lower/inbound.rs → inbound_tag still names both V2ray.
The node type no longer decides how a user is keyed: every panel user is keyed by lower::Uid(uid), whatever the node type.
vless parses to V2ray. Whether a newV2board V2ray node serves VLESS or VMess is decided by the client as it reads the answer: v2ray builds a Node::Vless when api.enable_vless is set and a Node::Vmess otherwise. Lowering reads api.enable_vless no longer; until 6.0.0 it ORed the key into the node’s flag. So on newV2board node_type = "vless" without enable_vless = true serves VMess, and still asks the panel for node_type=vless. On helium the config’s protocol alone decides.
pub type Node = helium_node_api::config::NodeConfig;pub enum NodeConfig { // tagged by "protocol" Vmess(Vmess), // port, transport, security Vless(Vless), // port, transport, security (VlessSecurity), flow Trojan(Trojan), // port, transport Shadowsocks(Shadowsocks), // port, cipher (SsCipher), transport, security Anytls(Anytls), // port, padding_scheme Socks(TlsProxy), // port, transport Http(TlsProxy), // port, transport Sss(Sss), // port, transport, security, transform, udp_max_datagram Hysteria2(Hysteria2), // port, obfs, up_mbps, down_mbps, ignore_client_bandwidth, udp, masquerade}
impl NodeConfig { pub fn port(&self) -> NonZeroU16; pub fn validate(&self) -> Result<(), ConfigError>;}
pub enum Transport { Tcp, Ws { path: String, host: Option<String> }, Grpc { service_name: String } }pub enum Security { None, Tls }pub enum VlessSecurity { None, Tls, Reality(Reality) }pub struct Reality { pub server_name: String, pub server_port: NonZeroU16, pub private_key: RealityPrivateKey, pub short_id: ShortId }pub enum VlessFlow { Vision }pub enum SsCipher { Ss2022 { cipher: Ss2022Cipher, server_key: Ss2022Key }, Legacy(SsLegacyCipher) }Node is what a panel says a node serves, in the vocabulary of the helium-node-api crate that katana and helium share. Since 6.1.0 it is the one node model: helium’s answer is one already, a UniProxy answer is converted into one by parse_node_config, and a local Hysteria 2 node is built as one by api::hysteria::local, so lowering reads one vocabulary whichever panel a node has. Its doc comment lists what is never in it, because only this host decides it: the certificates, the listen address, the PROXY and real-IP trust, handoff, the VMess clock check, and Hysteria 2’s credential kind and congestion control. Lowering reads those from the TOML.
katana 6.1.0 removed the model this replaced, NodeInfo, with its parts RealityNode, SssNode, HysteriaNode, MasqueradeNode, Hy2Bandwidth and the transport enum api::Transport, and with them the node-level speed limit (see Unit conversion).
The crate keeps out of its types what Etemenanki cannot serve, where that is cheap: REALITY exists only in VLESS’s security; Trojan, SOCKS, HTTP and AnyTLS have no security, because they always run inside TLS; AnyTLS has no transport, because it is always TLS over TCP; the transport has only tcp, ws and grpc, and no TCP header; every port is a NonZeroU16; a Shadowsocks 2022 cipher holds its server key, and a legacy one holds none. The rest is refused by validate, which the crate’s Deserialize runs and which parse_node_config and api::hysteria run on the node they build. Each message names the field as it is spelt in the JSON and never repeats a key, a password or a path:
| Rule | Message |
|---|---|
A WebSocket path starts with /, and has no whitespace, control character or # in it |
transport.path must start with /, transport.path must not have whitespace, a control character or # in it |
A WebSocket path’s one query may be ?ed=N |
transport.path must have no query but ?ed=N; a node matches the path of an upgrade without one |
| A WebSocket host, when there is one, is not empty, has no whitespace or control character, and has no port (an IPv6 address in brackets is not a port) | transport.host must not be empty; leave it out instead, transport.host must not have whitespace or a control character in it, transport.host must not have a port; a node matches it against the Host of an upgrade without one |
| A gRPC service name is not empty | transport.service_name must not be empty |
| REALITY runs over TCP only | security reality runs over transport tcp only |
A REALITY server name is ASCII letters, digits, -, _ and ., at most 253 bytes, not ending in a dot |
security.server_name must be a host name of ASCII letters, digits, -, _ and ., at most 253 bytes, with no wildcard and not ending in a dot |
| Vision runs over REALITY only | flow xtls-rprx-vision needs security reality |
| A Shadowsocks 2022 key is as long as the cipher’s key | server_key is <len> bytes, but <cipher> takes a <n>-byte key |
| An sss chain lists at most 8 expressions, none empty, none with whitespace around it or a control character in it | transform.<chain> has <n> expressions, more than 8, transform.<chain>[<i>] must be a non-empty expression without control characters or whitespace around it |
| A Hysteria 2 UDP idle timeout is 2 to 600 seconds | udp.idle_timeout_secs is <n>, but must be 2 to 600 |
| A masquerade status is 100 to 999, and not 233, the status that tells a Hysteria 2 client it authenticated | masquerade.status is <n>, but must be 100 to 999, masquerade.status must not be 233, the Hysteria 2 authentication success status |
The parts check their own shape when they are built, through the same messages: an AnyTLS PaddingScheme of no line, a blank line, a line with a line break or more than 2048 bytes joined with \n (padding_scheme[1] is empty), a Salamander password shorter than 4 bytes, a REALITY key that is not 32 bytes, a shortId that is not an even number of hex digits, at most 16. The keys, the shortId and the Salamander password print as Type(..) in Debug, such as ShortId(..), so a node logged with {:?} shows none of them.
Node derives Clone, PartialEq and Eq. NodeManager::reconcile compares the polled node with the last applied one (Applied.node) through disruptive_part (src/manager/node.rs): the node with an AnyTLS padding scheme, a Hysteria 2 node’s up_mbps, down_mbps and ignore_client_bandwidth, and its UDP idle timeout cleared. If the two differ, drop_all is set, and after the apply commits the node calls Supervisor::close(Selector::All), which closes every session. Its doc comment gives the reason for the three it clears: the supervisor applies them to the connections that arrive after them. Whether a Hysteria 2 node relays UDP at all is kept: turned off, it would go on relaying for every client connected before, for as long as its connection lasts; turned on, they would go on being refused.
| A change to | Drops every connection |
|---|---|
| An AnyTLS padding scheme | no: a new scheme reaches the sessions that start after it |
A Hysteria 2 node’s rates (up_mbps, down_mbps, ignore_client_bandwidth) |
no: the live connections keep the rate they agreed |
| A Hysteria 2 node’s UDP idle timeout | no |
| Whether a Hysteria 2 node relays UDP | yes |
| A Hysteria 2 node’s masquerade, given, changed or dropped | yes: one connection kept open would go on answering the old way |
| The obfuscation, the port, the transport, the security, a REALITY key, shortId or cover site, the Shadowsocks cipher or key, the flow, the protocol | yes: a client holding the old ones can no longer get in |
| An sss node’s chains or datagram limit | yes: a client holding the old ones decodes nothing the new ones send |
only_a_disruptive_change_drops_every_connection (tests/unit/manager/node.rs) pins the table’s rows for AnyTLS, Hysteria 2, a VMess transport and sss. Until 6.1.0 the comparison was split into the hand-written NodeInfo::transport_eq and protocol_eq; it now covers the whole node, so a field the contract gains drops every connection when it changes unless disruptive_part clears it. A change to a UniProxy host or server_name on a Trojan, Hysteria 2 or AnyTLS node no longer drops anything, because those fields are no longer read. The full effect table for each kind of change is on The node manager.
UserInfo, UserTraffic and the traffic label
Section titled “UserInfo, UserTraffic and the traffic label”pub struct UserInfo { pub uid: i64, pub email: String, pub uuid: String, pub speed_limit: u64, pub device_limit: u32,}
pub struct UserTraffic { pub uid: i64, pub upload: i64, pub download: i64,}
pub struct NodeReport { pub id: uuid::Uuid, pub traffic: Vec<UserTraffic>, pub ips: Vec<(i64, Vec<IpAddr>)>,}
impl NodeReport { pub fn is_empty(&self) -> bool;}
pub fn traffic_email(u: &UserInfo) -> compact_str::CompactString;Lowering reads every field of a UserInfo:
| Field | Read by | As |
|---|---|---|
uid |
lower::lower_users |
The user’s key, Uid(uid) |
uuid |
lower::inbound::credentials |
The source of every credential |
email, through traffic_email |
credentials |
The account name of a Hysteria 2 node with credential = "user_pass", and nothing else |
speed_limit |
lower_users |
The user’s UserSpec.speed_limit as it is, 0 meaning none; already [node.api] speed_limit where that overrides the panel’s |
device_limit |
lower_users |
The user’s UserSpec.device_limit, kept only when controller.enable_device_limit is on; 0 is no limit |
katana 6.0.0 dropped passwd, method, port and alter_id, which nothing read. UserInfo derives Clone, PartialEq, Eq and Hash, but nothing compares users: a user change matters only through the spec lowered from it, and NodeManager::reconcile compares whole specs (applied.spec == spec). An edit to a field the node’s lowering does not read, such as email off a user_pass Hysteria 2 node, therefore changes nothing.
traffic_email returns email when it is non-empty and the decimal uid otherwise:
| Panel | email in UserInfo |
traffic_email |
|---|---|---|
| newV2board | "{uuid}@v2board.user" |
11111111-2222-3333-4444-555555555555@v2board.user |
| helium | empty | the uid, for example 42 |
The label every flow of the user carries is not traffic_email but the key’s name: lower::Uid implements the supervisor’s UserId with name() returning UserName::Username of the decimal uid. That is the label NodeManager::spawn_client_ips parses back into a uid when it collects a user’s client address.
UserTraffic (Clone, Eq) is what NodeManager::report builds from the supervisor’s usage deltas; upload and download are wire bytes. A NodeReport wraps one cycle’s traffic with a random id chosen when the report is made, and, for a panel that keeps them, each user’s client addresses by uid; is_empty is true when both lists are. The counters and the report’s life are on Traffic accounting and reporting.
Audit rule types
Section titled “Audit rule types”pub struct DetectRule { pub id: i64, pub pattern: Regex,}
pub struct RouteRule { pub match_: Vec<String>, pub action: String,}A DetectRule holds a pattern compiled with the regex crate when node_rule builds the list, so a pattern that does not compile is dropped there, with a warning. Its id says where it came from:
| Source | id |
|---|---|
| Local rule file | -1 |
newV2board routes entry with action = "block" |
the entry’s index in the whole routes array |
RouteRule is a copy of one UniProxy routes entry, cached so that node_rule needs no request; helium’s node API sends no routes. DetectRule and RouteRule derive Clone only.
The node manager hands each fetched list to RuleManager::update (src/rule.rs), which replaces its Mutex<Arc<[DetectRule]>> only when the ids or pattern sources differ. When the node’s spec is lowered, rule::audit_routes groups the rules by id into one blackhole outbound audit#<id> and one route per id, placed before the node’s own routes, so a matching flow is blackholed. Nothing records the hits or reports them to a panel: katana 6.0.0 removed the hit ledger with the SSPanel client, the only one whose panel took them. The routing side is on Destination audit.
Unit conversion
Section titled “Unit conversion”pub const MBPS_TO_BPS: f64 = 1_000_000.0 / 8.0;
pub fn mbps_to_bps(mbps: f64) -> u64;Panels speak decimal megabits per second; the supervisor paces bytes per second. mbps_to_bps returns 0 (“no limit”) when its input is zero or negative, a check made before any arithmetic. Otherwise it multiplies by MBPS_TO_BPS (125 000) and casts with as u64, which drops the fraction and saturates at u64::MAX. 10 Mbps is 1 250 000 B/s.
Both clients apply the same override: when api.speed_limit is greater than zero, it replaces every user’s panel-supplied limit. helium’s own limit arrives once per users answer, in bytes per second, and is used as it is; only the override is converted from Mbps. A Hysteria 2 node described locally takes its users from user_list like any other node, so the override reaches them the same way.
Lowering takes each user’s limit as it is: UserSpec.speed_limit is NonZeroU64::new(u.speed_limit), None meaning unlimited (a_user_is_held_to_their_speed_limit). katana 6.1.0 removed the node-level limit, and determine_rate, which took the smaller non-zero of it and the user’s: no panel client set it to anything but 0, and a local Hysteria 2 node’s was the override its users already carried, so the limits are what they were. How the supervisor paces a user is on Tracking flows, stats and speed limits.
Data flow
Section titled “Data flow”Every call is made from the node’s own task, one at a time. At bootstrap the order is forget_etags, node_info (or the local Hysteria 2 node), user_list, then node_rule unless controller.disable_get_rule is set. A poll makes the same three calls without forget_etags, then reconciles and reports:
sequenceDiagram participant NM as NodeManager participant C as PanelClient participant P as Panel participant R as RuleManager participant S as Supervisor NM->>C: node_info() C->>P: GET node config C-->>NM: Some(Node), or None on 304 NM->>C: user_list() C->>P: GET users C-->>NM: Some(users), or None on 304 NM->>C: node_rule() C-->>NM: Some(rules), with no request NM->>R: update(rules) NM->>S: apply_with(spec), if anything changed NM->>S: take_usage() NM->>C: report(NodeReport) C->>P: POST traffic, or the helium report
node_rule sends no request on either panel. report runs when the report is not empty: with controller.disable_upload_traffic on, its traffic is empty, and its addresses are empty unless the panel keeps them and enable_device_limit is on. How the node manager treats each answer is in How the node manager uses the results.
On newV2board, a Hysteria 2 node with a non-zero [node.hysteria].port never calls the client’s node_info. NodeManager::node_info checks for it before it reaches the client and returns api::hysteria::local(&cfg.hysteria, port) instead, so the panel is never asked for that node’s config; a block that function refuses is returned as node_info’s error. Its users still come from user_list, and its rules from node_rule. A helium node never takes this path: its client refuses a node_type and a [node.hysteria].port, so the panel is always asked.
The first poll comes one poll period after bootstrap: NodeManager::serve consumes the interval’s immediate first tick. A static update that changes controller.update_periodic restarts the interval with the new period.
The HTTP layer
Section titled “The HTTP layer”Client, timeout and transport
Section titled “Client, timeout and transport”pub fn build_http_client(timeout_secs: u64, mtls: bool) -> Result<reqwest::Client>;fn http_client_builder(timeout_secs: u64, mtls: bool) -> Result<reqwest::ClientBuilder>;impl ApiConfig { pub fn timeout_secs(&self) -> u64;}Each panel client owns one reqwest::Client. build_http_client builds it from http_client_builder, with timeout(Duration::from_secs(timeout_secs)), gzip(true) and redirect(Policy::none()), and both clients pass the node’s enable_mtls as mtls. katana presents a client certificate when a panel asks for one, unless the node sets enable_mtls = false, and does not follow redirects. http_client_builder stops short of build, so that a_panel_that_asks_is_given_the_certificate_under_mtls_only can make a client that trusts the test’s own panel. timeout_secs returns api.timeout, or 5 when it is 0, the serde default; there is no way to turn the timeout off. reqwest applies it to the whole request, from connecting until the response body has been read, so it bounds every request in this module. It does not bound the local rule file read (see The local rule file). katana adds no connect or read timeout of its own.
Cargo.toml builds reqwest 0.13 with default-features = false and the gzip, json, query and native-tls-vendored features. That means:
- every request says
Accept-Encoding: gzip, and an answer sent withContent-Encoding: gzipis decompressed as it is read, before any parser sees it (thegzipfeature withgzip(true), since 6.0.1). The comment inhttp_client_buildergives the reason: a users list of tens of thousands of customers is megabytes of JSON. An answer sent uncompressed is read as it is; - HTTPS goes through native-tls with a vendored, statically built OpenSSL;
- the
http2feature is off, so panel requests are HTTP/1.1; - reqwest’s default proxy handling stays on, so the proxy environment variables (
HTTPS_PROXY,HTTP_PROXY,ALL_PROXY,NO_PROXY) apply to panel requests.
The reqwest::Client is shared by the calls of one client, so they reuse pooled connections, until a config edit replaces the client and its pool with it. Clients are never shared between nodes, even when two nodes point at the same panel.
ETag cache and HTTP 304
Section titled “ETag cache and HTTP 304”#[derive(Default)]pub struct EtagCache { map: Mutex<HashMap<&'static str, String>>,}
impl EtagCache { pub fn new() -> Self; pub fn get(&self, key: &'static str) -> Option<String>; pub fn set(&self, key: &'static str, value: String); pub fn clear(&self);}Each client owns one EtagCache, keyed by endpoint name: "node" and "users". The lock is a parking_lot::Mutex, held only for one get, insert or clear and never across an .await. set ignores an empty value.
The GET helpers, newv2board::Client::get and helium::Client::get, follow the same path:
flowchart TB
A["URL: base_url + path with the query, or node_url + endpoint"] --> B{"ETag stored for this endpoint"}
B -->|yes| H["add If-None-Match"]
B -->|no| S["send"]
H --> S
S -->|"send fails"| E1["Err: GET path"]
S --> C{"status"}
C -->|304| N["Ok(None)"]
C -->|4xx or 5xx| E2["Err: GET path, URL stripped"]
C -->|other| D["read the body in full"]
D -->|"read fails"| E3["Err: GET path body"]
D --> OK["body to the caller's parser"]
- The 304 check runs before
error_for_status, so a 304 is never an error. - No redirect is followed: a redirect’s body goes to the caller’s parser, which refuses it as not the JSON it expects.
- Each helper remembers the endpoint’s
ETagheader when the panel sends one that is visible ASCII (HeaderValue::to_strsucceeds), and sends it back asIf-None-Matchverbatim, quotes and anyW/prefix included. A server that compresses an answer marks its tag weak (W/"…"), as nginx does; the comment inhttp_client_buildersays it “is kept and sent back as it came”, anda_panel_answer_is_asked_for_and_read_gzip_compressedpins that the weak tag of a compressed answer reaches the client unchanged. helium’s helper hands the body back together with the tag (Fetched { body, etag }), andnode_infoanduser_liststore the tag (keep_etag) once the body has been read.
The cache lives as long as the client. forget_etags (EtagCache::clear) empties it, and NodeManager::try_bootstrap calls it at the start of every bootstrap attempt, so every attempt reads the node and its users in full. A client built for a config edit, and a respawned node, start with an empty cache too.
These are the requests a newV2board node makes at bootstrap and on its first poll, against a panel that answered with the ETags "n1" and "u1":
GET /api/v1/server/UniProxy/config If-None-Match: (none)GET /api/v1/server/UniProxy/user If-None-Match: (none)GET /api/v1/server/UniProxy/config If-None-Match: "n1"GET /api/v1/server/UniProxy/user If-None-Match: "u1"Status errors and error contexts
Section titled “Status errors and error contexts”pub fn error_for_status(resp: reqwest::Response) -> Result<reqwest::Response>;newV2board authenticates with the key in the query string, as token. helium takes it as Authorization: Bearer, through reqwest’s bearer_auth, so its URLs hold no key. reqwest’s own Response::error_for_status builds an error whose message ends in for url (...), the full request URL. katana’s error_for_status wraps it and calls reqwest::Error::without_url before converting to anyhow::Error, so a 4xx or 5xx error carries the status and not the URL. No client calls reqwest’s method directly.
The anyhow contexts and messages that the helpers and parsers put on an error name the path or the endpoint, never the URL or the query:
| Text | Where |
|---|---|
GET {path} |
Sending a GET, and a 4xx or 5xx answer to it |
GET {path} body |
Reading a GET answer’s body |
POST UniProxy push |
newV2board report_user_traffic |
parse UniProxy config response: <reason> |
newV2board config reading, the reason inside the message |
parse UniProxy user response |
newV2board user list parsing |
GET config, GET users, GET config body, GET users body |
helium GETs, named by endpoint |
parse helium config response: <e>, parse helium users response: <e> |
helium JSON parsing (parse), serde’s text inside the message |
POST report, POST report answer |
helium report, and reading its answer |
The node manager logs panel errors with {}, which renders only the outermost message, here the context, so the log line names the path. These lines were captured from the v4.6.0 binary with the panels unreachable:
ERROR katana::manager::node: node 1: node_info failed: GET /api/v1/server/UniProxy/config; retrying in 1sERROR katana::manager::node: node 3: node_info failed: GET config; retrying in 1sThe node 1 in these lines is api.node_id. The runtime names nodes by display_id instead (see Node identity).
A refused config answer has to say why in that outermost message, because the causes beneath it are never shown. So the newV2board client builds it as parse UniProxy config response: {e:#}, the reason and its causes in one line, and helium’s parse as parse helium config response: {e}. The comment on parse gives the reason: a node logs only the outermost message of an error, whose causes may carry another panel’s URL and key, and the reason is what an operator needs. Since 6.1.0 a refused UniProxy config logs, for example:
| Level | Line |
|---|---|
ERROR, at bootstrap |
node 1: node_info failed: parse UniProxy config response: node requests kernel-unsupported feature: tcp header type "http"; retrying in 1s |
WARN, on a poll |
node 1: node_info: parse UniProxy config response: server_port 70000 is not a port (1 to 65535) |
No reason quotes a key, a password or a shortId: the REALITY and Shadowsocks decoders’ refusals name the field alone, and json_error renders a serde type error without the value it found (see Node configuration).
When you add a request, an error or a log line, keep to the same rules: name the path, never the URL; never format api.key or a user’s UUID into a message; and log a panel error with {}, as the node manager does. Lowering follows the same rule for users: a user who cannot be admitted is named by uid, never by credential (see From user records to credentials).
The local rule file
Section titled “The local rule file”pub fn read_local_rules(path: &str) -> Vec<DetectRule>;api.rule_list_path names a text file with one regular expression per line. read_local_rules trims each line, skips blank lines and lines starting with #, and compiles the rest into DetectRule { id: -1, .. }. It never fails:
| Situation | Result |
|---|---|
path is empty |
No rules, no log line. |
| The file cannot be read | WARN katana::api: cannot read rule_list_path {path}: {e}, and no local rules. |
| A line is not a valid regex | WARN katana::api: invalid local rule "{line}": {e}, and that line is skipped. |
Every client calls it from node_rule with a synchronous std::fs::read_to_string, on the node’s task. Neither client asks a panel for its rules, so no ETag stands in front of the file: it is read again on every rule refresh, on newV2board and helium alike.
newV2board (UniProxy)
Section titled “newV2board (UniProxy)”Endpoints and query
Section titled “Endpoints and query”const CONFIG_PATH: &str = "/api/v1/server/UniProxy/config";const USER_PATH: &str = "/api/v1/server/UniProxy/user";const PUSH_PATH: &str = "/api/v1/server/UniProxy/push";
pub fn node_type_param(api: &ApiConfig) -> String;
pub struct Client { http: reqwest::Client, base_url: String, node_id: u32, node_type_param: String, token: String, node_type: NodeType, enable_vless: bool, speed_limit_mbps: f64, rule_list_path: String, hysteria: Box<HysteriaConfig>, // what a Hysteria 2 node's answer has no field for etags: EtagCache, routes: Mutex<Vec<RouteRule>>, // parking_lot::Mutex}
impl Client { pub fn new(cfg: &NodeConfig) -> Result<Self>; pub fn forget_etags(&self); pub fn inherit_routes(&self, old: &Client); fn query(&self) -> [(&'static str, String); 3]; async fn get(&self, path: &str, etag_key: &'static str) -> Result<Option<bytes::Bytes>>;}Every request, GET and POST alike, carries the same three query parameters, in this order, URL-encoded by reqwest:
| Parameter | Value |
|---|---|
node_id |
api.node_id |
node_type |
node_type_param(&cfg.api), computed once in Client::new: "vless" for a node whose api.node_type parses to V2ray with api.enable_vless = true; otherwise api.node_type lowercased, as written ("V2ray" becomes v2ray, "hy2" stays hy2) |
token |
api.key |
The API has no envelope: the response body is the object itself. Because the panel finds the node by node_id and node_type together, the same node_type_param value is also part of the node identity.
Node configuration
Section titled “Node configuration”node_info fetches CONFIG_PATH with ETag key "node" and hands the body to parse_node_config, a private free function, with the client’s node_type, enable_vless and its copy of [node.hysteria]. parse_node_config returns the node in the contract’s terms and the answer’s routes. Its doc comment describes the conversion: what UniProxy spells in strings is decoded here, what it asks for and katana cannot serve is refused here by name, and what it has no field for comes from [node.hysteria]; “Every refusal says why in its own message, which is the one a node logs.” node_info turns any refusal into parse UniProxy config response: <reason> and caches the routes for node_rule. Before 5.0.0 helium’s client called it too; since then it serves the UniProxy client alone. Until 6.1.0 it returned a NodeInfo that kept the keys, the flow, the cipher and the transport as text, and lowering decoded and refused them.
flowchart TB
A["GET config"] --> B{"status"}
B -->|304| N["Ok(None)"]
B -->|other| C["ServerConfig, server_port"]
C --> K["check_protocol"]
K --> T{"client's node_type"}
T --> V["v2ray: Vmess or Vless"]
T --> TR["Trojan"]
T --> SS["shadowsocks"]
T --> HY["hysteria::uniproxy"]
T --> AT["Anytls"]
T --> PX["proxy: Socks or Http"]
T --> SSS["sss: refused, NO_SSS"]
V & TR & SS & HY & AT & PX --> VAL["Node::validate"]
VAL --> OK["Some(Node), routes cached"]
The arm is chosen by the client’s own node_type, from the config, not by anything in the response. A 4xx or 5xx answer is an error before any of this (see ETag cache and HTTP 304).
const NO_SSS: &str = "newV2board: no UniProxy panel describes an sss node; sss is Helium's own \ protocol, served with panel_type = \"Helium\"";
fn parse_node_config(body: &[u8], node_type: NodeType, enable_vless: bool, hysteria: &HysteriaConfig) -> Result<(Node, Vec<RouteRule>)>;fn unsupported(feature: &str) -> anyhow::Error; // "node requests kernel-unsupported feature: {feature}"fn json_error(e: &serde_json::Error) -> String;fn check_protocol(tag: Option<&str>, node_type: NodeType, enable_vless: bool) -> Result<()>;fn v2ray(cfg: &ServerConfig, port: NonZeroU16, enable_vless: bool) -> Result<Node>;fn shadowsocks(cfg: &ServerConfig, port: NonZeroU16) -> Result<Node>;fn proxy(cfg: &ServerConfig, port: NonZeroU16, node_type: NodeType) -> Result<Node>;fn tls(cfg: &ServerConfig) -> TlsField; // None, Tls or Realityfn transport(cfg: &ServerConfig, settings: Option<&NetworkSettings>) -> Result<contract::Transport>;fn plain_tcp_header(header: Option<&serde_json::Value>) -> Result<()>;fn reality(cfg: &ServerConfig) -> Result<contract::Reality>;fn detect_rules(rule_list_path: &str, routes: &[RouteRule]) -> Vec<DetectRule>;ServerConfig declares protocol, server_port (an i64), network, the transport settings object (NetworkSettings, with path, headers, serviceName and header), flow, tls, cipher, obfs, obfs-password, server_key, up_mbps, down_mbps, ignore_client_bandwidth, tls_settings, padding_scheme and routes. katana 6.1.0 stopped declaring host, server_name and the settings’ host: no node katana serves read them, since a Trojan, Hysteria 2 or AnyTLS node’s never reached its listener and the transports whose host was read, httpupgrade and splithttp, are refused. ServerConfig reads no sss keys, does not deny unknown fields, so anything it does not declare is ignored, and gives every declared field a serde default. The text fields are Option<String>; headers, header and tls_settings take any JSON; padding_scheme is a list of strings; tls is an Option<i64>. Each route declares match (an array of strings) and action (a string), both with serde defaults, so a route without action is never a block rule.
A body that does not deserialize is refused with json_error’s text. Its doc comment gives the rule: serde’s own message can quote a value of the body, a key or a password among them, so only a missing field is named. A value of the wrong type, such as a tls that is not a JSON integer, is a value of the wrong type at line <l>, column <c>; a body that is not JSON keeps serde’s text, which names the line and column (a_malformed_body_is_refused_without_quoting_it), and so does a missing field of the REALITY settings, which names the field.
server_port must be 1 to 65535. It becomes the node’s NonZeroU16 port, and anything else is refused as server_port <n> is not a port (1 to 65535), so a port is never truncated into another (a_port_outside_one_to_65535_is_refused, for 0, -1, 65536 and 70000). Until 6.1.0 a port above 65535 was cut to its low 16 bits, and the node listened on a port its panel did not name.
What the conversion refuses, each after parse UniProxy config response: , in the order a body meets them:
| The answer asks for | Refused with | Pinned by |
|---|---|---|
| a value of the wrong type | a value of the wrong type at line <l>, column <c> |
a_malformed_body_is_refused_without_quoting_it |
| a port outside 1 to 65535 | server_port <n> is not a port (1 to 65535) |
a_port_outside_one_to_65535_is_refused |
a protocol tag of another family, or one katana does not serve |
the panel's node is protocol "<tag>", but this node is configured as <Type>, the panel's node is protocol "<tag>", which katana does not serve |
the_panels_protocol_tag_must_match_the_node |
| a transport other than TCP, WebSocket and gRPC | node requests kernel-unsupported feature: httpupgrade transport, … splithttp transport (for splithttp and xhttp), … transport "<network>" |
a_transport_katana_cannot_serve_is_refused |
| V2Ray’s TCP header obfuscation | node requests kernel-unsupported feature: tcp header type "<type>", tcp header is not an object, tcp header type is not a string |
a_tcp_header_other_than_none_is_refused |
| a flow on VMess, or a VLESS flow other than Vision | node requests kernel-unsupported feature: an XTLS flow off VLESS, … VLESS flow "<flow>" |
only_vision_and_only_on_vless |
| REALITY on VMess, Shadowsocks, SOCKS or HTTP | node requests kernel-unsupported feature: REALITY on a VMess node, newV2board: shadowsocks over REALITY is not supported, node requests kernel-unsupported feature: socks over REALITY (or http) |
a_reality_node_with_bad_settings_is_refused_without_repeating_them, shadowsocks_reads_its_transport, parse_socks_and_http_read_their_transport_over_tls |
| REALITY settings that are missing or unusable | see V2ray | a_reality_node_with_bad_settings_is_refused_without_repeating_them, a_reality_node_without_its_settings_is_refused |
| Shadowsocks obfuscation | newV2board: shadowsocks obfs "<obfs>" is not supported |
shadowsocks_ciphers_and_keys |
a Shadowsocks cipher katana does not serve, 2022-blake3-chacha20-poly1305 included |
node requests kernel-unsupported feature: shadowsocks cipher "<name>" |
shadowsocks_ciphers_and_keys |
| a Shadowsocks 2022 key that is not base64, or shorter than the cipher’s | shadowsocks server_key is not base64, shadowsocks-2022: PSK too short (<n> < <len>) |
shadowsocks_ciphers_and_keys |
| SOCKS or HTTP without TLS | node requests kernel-unsupported feature: socks without TLS (or http) |
parse_socks_and_http_read_their_transport_over_tls |
| Hysteria 2 obfuscation that is half set, unknown or short | obfs_password is set but obfs is not; did you mean obfs = "salamander"?, unknown obfs "<obfs>" (expected "salamander"), obfs_password must be at least 4 bytes for salamander |
a_hysteria_node_is_completed_with_the_local_block |
| an AnyTLS padding scheme the contract refuses | the contract’s text, such as padding_scheme[1] is empty |
|
| an sss node | NO_SSS |
an_sss_node_is_refused |
anything validate refuses |
the contract’s text (see Node), such as security reality runs over transport tcp only or flow xtls-rprx-vision needs security reality |
a_reality_node_with_bad_settings_is_refused_without_repeating_them, only_vision_and_only_on_vless |
A Hysteria 2 node’s [node.hysteria] is held to its rules here too, because hysteria::uniproxy builds the node with it (see Completing a Hysteria 2 node); --test and the reload check refuse a bad block first. Since 6.1.0 these are refusals of the answer, logged as a failed node_info (see Status errors and error contexts): at bootstrap node <id>: node_info failed: parse UniProxy config response: <reason>; retrying in <n>s, on a poll node <id>: node_info: parse UniProxy config response: <reason>. Most were lowering’s refusals until then, logged as initial start failed: … or cannot build the node, keeping the running one: …, and the reason of a few was not logged at all. --test never asks the panel, so it sees none of these.
The protocol tag
Section titled “The protocol tag”A UniProxy panel may name the node’s protocol in a protocol field; check_protocol’s doc comment names Xboard as one that does. check_protocol holds the tag to the node type this node is configured as. Its doc comment gives the reason: serving one protocol where the panel hands its users another would lock every one of them out.
protocol |
Result |
|---|---|
| absent | Accepted: a panel that sends no tag is taken at its word. |
a name NodeType::parse does not know |
Refused: the panel's node is protocol "tuic", which katana does not serve. |
| a name of another node type | Refused: the panel's node is protocol "vmess", but this node is configured as Trojan. |
a V2ray name on a V2ray node, vless while enable_vless is off or another while it is on |
Accepted with a warning; the node serves what enable_vless says. |
| the node’s own type otherwise | Accepted. |
The tag is read as NodeType::parse reads node_type, so its case does not matter, and hysteria (as helium’s node API v1 spelled it) and hy2 are Hysteria 2. A body tagged sss on a node configured as another type is refused here, as any other family is. Within V2ray the tag only warns, because whether a node speaks VLESS is enable_vless, and a node may run VLESS on a panel row stored in VMess’s shape. The warning is logged at WARN, target katana::api::newv2board, on every config answer that carries the mismatch:
the panel's node is protocol "vmess", but enable_vless is true; serving VLESS as configuredThe transport: transport and tls
Section titled “The transport: transport and tls”VMess, VLESS, Shadowsocks, SOCKS and HTTP nodes spell their transport the same way and share one reading of it, transport(cfg, settings), which reads network and the node’s transport settings:
network, ASCII-lowercased |
contract::Transport |
|---|---|
missing or empty, tcp, raw |
Tcp, once plain_tcp_header passes the settings’ header |
ws, websocket |
Ws { path, host }: path is the settings’ path, or / when it is missing or empty; host is the settings’ headers.Host when it is a JSON string (the key matched case-sensitively, by header_host), and none when it is missing or empty |
grpc, gun |
Grpc { service_name }: the settings’ serviceName, empty when missing, which validate refuses |
httpupgrade, splithttp, xhttp, anything else |
refused by name |
plain_tcp_header refuses V2Ray’s TCP header obfuscation: a header that is not an object (tcp header is not an object), a type that is not a string (tcp header type is not a string), and any type but none, in any case (node requests kernel-unsupported feature: tcp header type "http"). No header, a null one, or one without a type is bare TCP, as the panels’ subscriptions read it. Its doc comment gives the reason: served as bare TCP, its clients would open with an HTTP head, fail to authenticate and count toward their IP’s ban. REALITY rides TCP, so a REALITY node’s header is held to the same rule.
tls(cfg) reads the integer tls as a TlsField: 1 is TLS, 2 is REALITY, and 0, a missing field or any other integer is nothing under the transport.
v2ray builds a Node::Vless when enable_vless is set and a Node::Vmess otherwise:
| VMess | VLESS | |
|---|---|---|
| Transport | transport |
transport |
tls = 1 |
Security::Tls |
VlessSecurity::Tls |
tls = 2 |
refused: REALITY on a VMess node |
VlessSecurity::Reality, from reality(cfg) |
any other tls |
Security::None |
VlessSecurity::None |
flow |
refused when not empty: an XTLS flow off VLESS |
empty is none, xtls-rprx-vision is VlessFlow::Vision, any other is refused: VLESS flow "<flow>" |
validate then holds Vision to REALITY (flow xtls-rprx-vision needs security reality) and REALITY to TCP (security reality runs over transport tcp only), so the flow xtls-rprx-vision serves Vision over REALITY and over nothing else.
REALITY settings. reality(cfg) decodes tls_settings in the shape helium’s node API v1 gave them: server_port, server_name and private_key are required, and a missing short_id is empty. It runs only when tls is 2. Its doc comment: other node kinds send tls_settings of other shapes, and those must not stop their config from parsing; Xboard sends one on TLS nodes (another_tls_settings_shape_is_ignored_off_reality). It refuses:
| Settings | Refused with |
|---|---|
| missing | a REALITY node (tls = 2) carries no tls_settings |
| not of that shape | the REALITY tls_settings: <e>, json_error’s text |
an empty server_name |
REALITY needs a server_name |
a server_port of 0 |
REALITY needs the cover site's port |
| a key or shortId Xray’s formats do not allow | REALITY private_key: <e>, REALITY short_id: <e> |
The key and the shortId are read by the kernel’s decoders, etemenanki_protocols::transports::reality → decode_private_key and decode_short_id, and neither refusal repeats them. The result is a contract::Reality: server_name, which is both the SNI answered and the cover site’s host, server_port, the port the cover site is dialed at, the key’s 32 bytes, and the shortId, held lowercase. validate then holds the server name to the contract’s rule.
Trojan
Section titled “Trojan”A Trojan node is a Node::Trojan on the answer’s port. The contract’s Trojan has no security, because it always runs inside TLS, and katana serves it with the node’s own certificate (parse_trojan_fixed).
Hysteria 2
Section titled “Hysteria 2”hysteria::uniproxy builds a Hysteria 2 node from the answer’s obfuscation, its rates and the client’s copy of [node.hysteria] (see Completing a Hysteria 2 node). The obfuscation type is obfs and its key obfs-password, hyphenated, as the reference node agent’s Hysteria2Node spells it.
The rates up_mbps, down_mbps and ignore_client_bandwidth are read leniently: lenient_number takes a JSON number or a string holding one, and mbps takes the whole Mbit/s V2board sends and rounds a float to one, a missing, non-finite or below-1 figure counting as 0. lenient_flag takes a boolean, an integer (non-zero is true), or the string true, false, 1 or 0, and anything else is unset. The comment in ServerConfig gives the reason: until the release that read them they were ignored outright, so a panel spelling one oddly must not stop the whole node config from parsing. A Hysteria 2 node described locally, by a non-zero [node.hysteria].port, never reaches this code (see Data flow).
Shadowsocks
Section titled “Shadowsocks”shadowsocks accepts an obfs that is empty, "plain" or "none", and refuses anything else: newV2board: shadowsocks obfs "http" is not supported. It reads the transport through transport, so a Shadowsocks node rides the transport the panel names, as Xray serves it (shadowsocks_reads_its_transport); an answer that names neither stays on plain TCP. tls = 1 puts TLS under it, and tls = 2 refuses the node config, because Shadowsocks over REALITY is not served. Its doc comment: the key is read as the kernel reads one, so a key it takes is taken.
cipher |
SsCipher |
Key |
|---|---|---|
2022-blake3-aes-128-gcm, 2022-blake3-aes-256-gcm, as written |
Ss2022 { cipher, server_key } |
server_key, read by the kernel’s decode_psk as standard base64 (refused as shadowsocks server_key is not base64, without the key), then normalise_psk, which folds a longer key to the cipher’s length and refuses a shorter one (shadowsocks-2022: PSK too short (16 < 32)) |
a legacy name ss_legacy::Method::from_name knows, in any case: aes-128-gcm or aead_aes_128_gcm; aes-256-gcm or aead_aes_256_gcm; chacha20-poly1305, chacha20-ietf-poly1305 or aead_chacha20_poly1305; xchacha20-poly1305 or xchacha20-ietf-poly1305 |
Legacy(SsLegacyCipher) |
none: each user’s password is their own |
anything else, 2022-blake3-chacha20-poly1305 and a missing cipher included |
refused: node requests kernel-unsupported feature: shadowsocks cipher "<name>" |
The contract’s legacy ciphers are new in helium-node-api 0.2.0 (SsCipher::Legacy). How each user’s key or password is made is in From user records to credentials.
AnyTLS
Section titled “AnyTLS”An AnyTLS node is a Node::Anytls with the port and padding_scheme, one line per entry, as the contract’s PaddingScheme. A missing, null or empty list is none, the default; its comment: an empty list says no more than an absent one. A list the contract refuses (a blank line, a line with a line break, more than 2048 bytes joined) refuses the node config. The contract’s AnyTLS has no transport and no security: it is always TLS over TCP with the node’s own certificate, so network, tls and server_name change nothing (parse_anytls_keeps_the_padding_scheme). The supervisor parses the scheme; see AnyTLS.
SOCKS and HTTP
Section titled “SOCKS and HTTP”proxy(cfg, port, node_type) builds a Node::Socks or a Node::Http, a TlsProxy with the port and the transport, which must be TLS: tls = 1. It refuses one without TLS (node requests kernel-unsupported feature: socks without TLS, or http) and one marked tls = 2 (… socks over REALITY). Its doc comment gives the reason: in the clear, its account and everything it relays would cross the network readable, and a plain proxy on a public port is an open proxy’s first step (parse_socks_and_http_read_their_transport_over_tls).
No UniProxy panel describes an sss node, and since 5.0.0 the UniProxy parser reads no sss keys. Client::new refuses a node whose node_type parses to Sss, before it builds anything, with NO_SSS:
newV2board: no UniProxy panel describes an sss node; sss is Helium's own protocol, served with panel_type = "Helium"Every build, --test and reload builds the client, so each of them refuses such a node; katana --test prints configuration error: node 1: newV2board: no UniProxy panel describes an sss node; …. parse_node_config refuses NodeType::Sss as well, and a body tagged sss on a node of another type fails check_protocol (an_sss_node_is_refused). sss nodes are served from helium alone (see Node configuration and rules); the protocol is on sss.
user_list fetches USER_PATH with ETag key "users":
{ "users": [ { "id": 1001, "uuid": "11111111-2222-3333-4444-555555555555", "speed_limit": 10, "device_limit": 3 } ] }id and uuid are required in each entry: a user without either fails the whole response with parse UniProxy user response. The list is parsed on the blocking pool.
UserInfo field |
Value |
|---|---|
uid |
id |
email |
"{uuid}@v2board.user" |
uuid |
uuid |
speed_limit |
mbps_to_bps(api.speed_limit) if it is greater than 0, else mbps_to_bps(speed_limit) |
device_limit |
device_limit; missing, null or negative is 0 |
The panel’s speed_limit is in Mbps; 0 or less means no limit. The users are returned in panel order. The UUID is the source of every credential; see From user records to credentials.
Traffic push
Section titled “Traffic push”report_user_traffic posts a JSON object keyed by the uid as a string, with [upload, download] in bytes:
{ "1001": [123, 456], "1002": [0, 789] }The body is a HashMap<String, [i64; 2]>, so two rows with the same uid would overwrite each other. The caller prevents that: NodeManager::report sums its totals by uid. PanelClient::report calls this method with the report’s traffic only, and sends nothing when there is none. The request carries the same three query parameters as every other.
node_rule sends no request. It calls detect_rules, which starts from read_local_rules, then walks the routes node_info cached. For each entry whose action is exactly "block", it joins the entry’s match strings with |, compiles the result as one regular expression, and adds it with the entry’s index in the array as id. Route declares only match and action, so a route’s own id field is never read. A route that does not compile is skipped with WARN katana::api::newv2board: invalid block rule [...]: {e}, the match list printed in debug form. node_rule returns Ok(Some(_)), and it holds the routes lock with no .await inside.
Because the routes come from the cached config answer, they change only when node_info reads a new config answer. A client built for a config edit has read no config yet, so NodeManager::apply_static calls inherit_routes on it first. A Hysteria 2 node described locally never fetches the config, so its rules are the local file plus whatever it inherited.
Completing a Hysteria 2 node: api::hysteria
Section titled “Completing a Hysteria 2 node: api::hysteria”pub fn local(cfg: &HysteriaConfig, port: NonZeroU16) -> io::Result<Node>;pub fn uniproxy( port: NonZeroU16, obfs_type: &str, obfs_password: &str, up_mbps: u64, down_mbps: u64, ignore_client_bandwidth: Option<bool>, local: &HysteriaConfig,) -> io::Result<Node>;pub fn obfs(obfs_type: &str, password: &str) -> io::Result<Option<Obfs>>;
fn complete( port: NonZeroU16, obfs: io::Result<Option<Obfs>>, up_mbps: u64, down_mbps: u64, ignore_client_bandwidth: Option<bool>, local: &HysteriaConfig,) -> io::Result<Node>;fn udp(cfg: &HysteriaConfig) -> io::Result<Option<UdpRelay>>;fn masquerade(cfg: &HysteriaConfig) -> Option<Masquerade>;The module builds a Hysteria 2 node, in the contract’s terms, that a panel cannot describe in full. Its comment gives the split: UniProxy says a node’s obfuscation and rates, and nothing of its UDP relay or its masquerade, so those come from [node.hysteria], which also overrides the rates; a helium node’s panel says all of it, and its client refuses the block, so nothing here touches one. katana 6.1.0 moved this out of lowering, where lower_hysteria read the same keys from [node.hysteria] and lower::local_hysteria_node built a NodeInfo for the local node.
Both public builders end in complete, which fills a Hysteria2:
Hysteria2 field |
uniproxy (a UniProxy node) |
local (a node [node.hysteria].port describes) |
|---|---|---|
port |
the answer’s server_port |
[node.hysteria].port |
obfs |
obfs of the answer’s obfs and obfs-password |
obfs of the block’s obfs and obfs_password |
up_mbps, down_mbps |
the block’s when set, else the answer’s | the block’s when set, else 0, no cap and no limit |
ignore_client_bandwidth |
the block’s when set, else the answer’s, else true |
the block’s when set, else true |
udp |
udp of the block |
udp of the block |
masquerade |
masquerade of the block |
masquerade of the block |
complete’s comment on the last default: neither saying whether to ignore a client’s figures leaves the node answering auto, as before it read rates at all. complete then runs the contract’s validate on the node, so the masquerade the block describes is held to the contract’s rules too: a status outside 100 to 999, or 233, is refused with the contract’s text, for example masquerade.status must not be 233, the Hysteria 2 authentication success status.
obfs(obfs_type, password) reads an empty string as unset:
obfs |
obfs_password |
Result |
|---|---|---|
| unset | unset | no obfuscation: packets go as plain QUIC |
| unset | set | refused: obfs_password is set but obfs is not; did you mean obfs = "salamander"? |
salamander |
at least 4 bytes | Obfs::Salamander with the password |
salamander |
shorter, or unset | refused: obfs_password must be at least 4 bytes for salamander |
| any other | either | refused: unknown obfs "<obfs>" (expected "salamander") |
Its comment on the second row: a typo in obfs would otherwise silently disable the obfuscation the operator plainly asked for. The answer’s obfuscation is held to the same rules as the block’s (a_hysteria_node_is_completed_with_the_local_block).
udp(cfg) relays no UDP unless udp is on, and refuses an idle timeout set without it: udp_idle_timeout is set but udp is not enabled. With it, the idle timeout is udp_idle_timeout, 60 s when unset, and must be 2 to 600 seconds: udp_idle_timeout must be between 2 and 600 seconds. The range is upstream’s, for its reasons: below 2 s a busy association would be swept between packets, above 600 s a dead one holds its socket for ten minutes.
masquerade(cfg) is none when [node.hysteria.masquerade] says nothing, so the node answers 404 as an unconfigured server does. A key left out takes Go’s own 404 page’s: status 404, body 404 page not found\n, content type text/plain; charset=utf-8.
The callers:
| Caller | Builder | A refusal is |
|---|---|---|
newv2board::parse_node_config, for a newV2board node of type Hysteria 2 |
uniproxy |
a refused config answer: parse UniProxy config response: <reason> |
NodeManager::node_info, when [node.api].node_type parses as Hysteria 2 and [node.hysteria].port is not 0 |
local |
node_info’s error: at bootstrap node <id>: node_info failed: <reason>; retrying in <n>s |
lower::test_spec, for every node whose node_type parses as Hysteria 2, on the block’s port or port 1 |
local |
a refused --test, start or reload: configuration error: node 1: <reason> under --test |
test_spec builds the node from the block whether or not the panel will name the port, so --test and the reload check refuse a bad block before it is used. What the listener makes of the node, with the two [node.hysteria] keys only lowering reads, credential and congestion, is on Lowering inbounds and outbounds.
helium
Section titled “helium”Endpoints and authentication
Section titled “Endpoints and authentication”pub struct Client { http: reqwest::Client, node_url: String, // {host}/api/node/v2/{node_id} token: String, speed_limit_mbps: f64, rule_list_path: String, etags: EtagCache,}
impl Client { pub fn new(cfg: &NodeConfig) -> Result<Self>; pub fn forget_etags(&self); async fn get(&self, endpoint: &str, etag_key: &'static str) -> Result<Option<Fetched>>; fn keep_etag(&self, etag_key: &'static str, etag: Option<String>); pub async fn node_info(&self) -> Result<Option<Node>>; pub async fn user_list(&self) -> Result<Option<Vec<UserInfo>>>; pub async fn report(&self, report: &NodeReport) -> Result<()>; pub async fn node_rule(&self) -> Result<Option<Vec<DetectRule>>>;}
struct Fetched { body: bytes::Bytes, etag: Option<String>,}
fn refuse_local_protocol(cfg: &NodeConfig) -> Result<()>;fn parse_users(body: &[u8], override_mbps: f64) -> Result<Vec<UserInfo>>;fn parse<T: serde::de::DeserializeOwned>(endpoint: &str, body: &[u8]) -> Result<T>;fn user_infos(answer: Users, override_mbps: f64) -> Vec<UserInfo>;fn report_body(report: &NodeReport) -> Report;The client speaks helium’s node API v2 only. katana 4.5.0 to 4.10.x called node API v1, under /api/node/v1/; katana 5 and 6 never do. Every request names the node in its path and sends api.key as Authorization: Bearer; no request has a query string.
| Call | Method and path | Body | ETag key |
|---|---|---|---|
node_info |
GET {node_url}/config |
answer: helium_node_api::config::NodeConfig |
"node" |
user_list |
GET {node_url}/users |
answer: users::Users |
"users" |
report |
POST {node_url}/report |
request: report::Report; answer: report::ReportAnswer |
none |
The API has no envelope. Every body is a type of the helium-node-api crate (0.2.0), which helium serializes from the same definitions. The config answer is katana’s node model as it is (Node), so it goes to lowering untouched; helium.rs maps the users and the report to and from katana’s models by type, never by guessing at a loose shape. Error contexts name the endpoint (GET config, GET users body), not the path.
get sends the tag the client holds for the endpoint as If-None-Match and returns Ok(None) for a 304; otherwise it returns the body together with the answer’s ETag header (Fetched). node_info and user_list store that tag with keep_etag once the body has been read. A 304 means unchanged, and the node keeps what it has.
Local keys a helium node refuses
Section titled “Local keys a helium node refuses”helium’s config answer describes the whole inbound: the protocol, the port, the transport, TLS or REALITY, and each protocol’s own settings, sss’s chains and Hysteria 2’s obfuscation, rates, UDP relay and masquerade among them. A local key that said the same would either overrule the panel, and lock its clients out, or be overruled while an operator believes it is in force. So Client::new first calls refuse_local_protocol, which refuses a node whose config sets any of these keys and names the first one it finds, in this order:
| Key | Counts as set when |
|---|---|
[node.api] node_type |
it is not empty |
[node.api] enable_vless |
it is true |
[node.hysteria] port |
it is not 0 |
[node.hysteria] credential |
it is not empty |
[node.hysteria] udp |
it is true |
[node.hysteria] udp_idle_timeout |
it is present, whatever its value |
[node.hysteria] obfs |
it is present |
[node.hysteria] obfs_password |
it is present |
[node.hysteria.masquerade] |
any of its keys is present |
[node.hysteria] up_mbps |
it is present |
[node.hysteria] down_mbps |
it is present |
[node.hysteria] ignore_client_bandwidth |
it is present |
The message names the key; captured from katana --test (6.0.0):
configuration error: node 1: [node.api] node_type is set, but a helium node's protocol is described by the panel; remove it (of [node.hysteria], only congestion is this host's to choose)Only [node.hysteria] congestion may be set (cubic, the default, bbr or reno): it says how this host sends when no fixed rate is agreed, not what a client meets. refuse_local_protocol destructures HysteriaConfig, so a key added to [node.hysteria] does not compile until it is placed in the list or among the keys allowed.
Every build, --test and reload builds the panel client, so each of them refuses such a node, and a reload that hits it is refused as a whole (local_keys_the_panel_describes_are_refused checks every key through Client::new and PanelClient::new, and that congestion passes). It follows that on helium:
- a node has no
node_type, and the panel’sprotocolalone says what it serves; - a Hysteria 2 node is never described locally, so the panel is always asked for its config;
- a Hysteria 2 node reads its credential the default way,
uuid: theHysteria-Authstring is the user’s UUID, anduser_passis not available; - obfuscation, rates, the UDP relay and the masquerade are the panel’s alone:
[node.hysteria]cannot override them.
Node configuration and rules
Section titled “Node configuration and rules”node_info reads the config answer with parse("config", &body) into a Node, keeps its tag, and returns the node as helium wrote it: nothing is mapped. A body that does not parse fails with parse helium config response: <e>, serde’s text. The crate’s Deserialize also checks every rule validate does (see Node), so a config that breaks one fails the same way, with the rule in the message and no key in it: a REALITY node over WebSocket fails with parse helium config response: security reality runs over transport tcp only, followed by serde’s line and column (the_node_config_is_the_contracts_as_helium_wrote_it).
The config answer
Section titled “The config answer”NodeConfig is a JSON object tagged by protocol, beside the variant’s own fields. Every variant has port, the port the node listens on and clients dial, from 1 to 65535:
protocol |
Fields |
|---|---|
vmess |
port, transport, security |
vless |
port, transport, security (none, tls, or reality with server_name, server_port, private_key and short_id), and an optional flow, xtls-rprx-vision |
trojan, socks, http |
port, transport; no security, because they always run inside TLS |
shadowsocks |
port, cipher, transport, security; for 2022-blake3-aes-128-gcm or 2022-blake3-aes-256-gcm also server_key (padded standard base64, as long as the cipher’s key: 16 or 32 bytes), and for the legacy aes-128-gcm, aes-256-gcm, chacha20-ietf-poly1305 or xchacha20-ietf-poly1305 no server_key, because each customer’s password is their own. A 2022 cipher without the key is refused, and so is a legacy one with a key |
anytls |
port and an optional padding_scheme, a list of lines; always TLS over TCP |
sss |
port, transport, security, an optional transform (up and down, each at most 8 expressions), and an optional udp_max_datagram (65535 when left out) |
hysteria2 |
port; an optional obfs, {"type": "salamander", "password": "…"} with a password of at least 4 bytes; up_mbps and down_mbps, both required, 0 meaning no cap and no limit; ignore_client_bandwidth, true when left out; an optional udp, {"idle_timeout_secs": …}, 2 to 600, 60 when left out; an optional masquerade with status, body and content_type, the status between 100 and 999 and never 233 |
transport is {"type": "tcp"}, {"type": "ws", "path": "/…", "host": "…"} (host optional) or {"type": "grpc", "service_name": "…"}. security is {"type": "none"} or {"type": "tls"}, and on VLESS also REALITY. Both are required wherever they are a choice, so nothing missing is read as plaintext or plain TCP. REALITY runs only over transport tcp, and Vision only over REALITY, so only over TCP.
{"protocol":"vmess","port":443,"transport":{"type":"ws","path":"/ws"},"security":{"type":"tls"}}{"protocol":"vless","port":443,"transport":{"type":"tcp"},"security":{"type":"reality","server_name":"www.example.com","server_port":443,"private_key":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","short_id":"0123456789abcdef"},"flow":"xtls-rprx-vision"}{"protocol":"hysteria2","port":443,"obfs":{"type":"salamander","password":"replace-with-a-long-random-password"},"up_mbps":100,"down_mbps":100,"ignore_client_bandwidth":true,"udp":{"idle_timeout_secs":60}}What lowering reads
Section titled “What lowering reads”Lowering reads the Node as helium wrote it. Until 6.1.0, helium.rs mapped each variant into a NodeInfo (node_info, hysteria2, stream, tls, bare), and lowering decoded the key and the shortId again; that mapping is gone, and every_protocol_helium_writes_is_read reads one config of each protocol into a Node. Since helium-node-api 0.2.0 a helium node may also be legacy Shadowsocks, whose users present their UUID as their password. A Hysteria 2 node’s obfuscation, rates, UDP relay and masquerade reach the listener from the config, never from [node.hysteria], whose keys but congestion the client refuses. An sss node’s chains are held to their shape by the contract and parsed by lowering, which refuses one it cannot parse (sss transform.up: <e>). The listener is on Lowering inbounds and outbounds.
Audit rules
Section titled “Audit rules”The config carries no routes. node_rule sends no request and returns read_local_rules(rule_list_path), so a helium node’s audit rules are its local rule file alone, read again on every rule refresh.
{"limits":{"speed_limit":12500000,"device_limit":3},"users":[{"id":7,"uuid":"11111111-2222-3333-4444-555555555555"}]}parse_users runs on the blocking pool. It reads the body as users::Users with parse("users", …) and hands it to user_infos. limits is said once per answer and applies to every user on their own: speed_limit in bytes per second, 0 for none, and device_limit, 0 for any. Each user has an id, an i32, and a uuid. Every field is required: an answer without its limits, with a negative limit or with a malformed UUID does not parse and fails with parse helium users response, and the node keeps the users it has, as for any failed fetch.
UserInfo field |
Value |
|---|---|
uid |
id, widened to i64 |
email |
empty, so traffic_email is the uid |
uuid |
the UUID in its lowercase hyphenated form (uuid.hyphenated()), from which every protocol’s credential is made |
speed_limit |
mbps_to_bps(api.speed_limit) if it is greater than 0, else limits.speed_limit as sent, in bytes per second |
device_limit |
limits.device_limit; the local override never touches it |
The per-user speed_limit and device_limit of node API v1 are gone.
The report
Section titled “The report”report posts report_body(report), the crate’s report::Report, with traffic and client addresses together:
{ "report_id": "6f9619ff-8b86-d011-b42d-00c04fc964ff", "agent_version": "6.0.0", "traffic": [ { "id": 7, "up": 1048576, "down": 52428800 } ], "ips": [ { "id": 7, "ips": ["203.0.113.7", "2001:db8::7"] } ]}report_id is the report’s id, agent_version katana’s own version, up and down wire bytes. ips lists, by uid, the client addresses users connected from since the last report, plus those of every session still open, each user’s sorted; it is empty unless enable_device_limit is on (see How the node manager uses the results).
helium’s IDs are i32 and its counts unsigned. report_body leaves out an entry whose uid does not fit an i32, or whose byte count is negative, rather than wrap it into another customer’s ID or a count nobody moved. Each one is logged at WARN, target katana::api::helium, with a warning that names the uid alone, as a field:
traffic left out of the report: the uid or a byte count is out of rangeclient addresses left out of the report: the uid is out of rangehelium answers with report::ReportAnswer: {"duplicate": false}, or {"duplicate": true} for a report_id it has already recorded; katana logs a duplicate at INFO as panel already had this report, with the report id as a field.
The panels side by side
Section titled “The panels side by side”| newV2board | helium | |
|---|---|---|
panel_type |
newv2board or v2board, any case |
helium, any case |
| API | UniProxy | node API v2, bodies of the helium-node-api crate |
| Key | token in the query |
Authorization: Bearer |
| Node found by | node_id and node_type |
node_id, in the path |
| Envelope | none | none |
| Node types | V2ray, Trojan, Shadowsocks, Hysteria2, AnyTLS, SOCKS, HTTP | VMess, VLESS, Trojan, Shadowsocks (2022 and legacy), Hysteria2, AnyTLS, SOCKS, HTTP, sss |
| Node model | the answer converted into a Node by parse_node_config |
the answer, a Node as it is |
| What katana cannot serve | refused by name as the answer is read, then by validate |
refused by the contract’s Deserialize |
| Protocol | api.node_type; a protocol tag is checked when the answer carries one |
the config’s protocol alone; a local node_type is refused |
| REALITY | from tls_settings when tls = 2 |
from a VLESS config’s security of type reality |
| TCP header | the settings’ header; any type but none is refused as the answer is read |
none: the contract has none |
| Per-user speed limit | speed_limit, Mbps |
limits.speed_limit, bytes per second, one for every user |
| Per-user device limit | device_limit |
limits.device_limit, one for every user |
| Hysteria 2 rates | up_mbps, down_mbps, ignore_client_bandwidth; [node.hysteria] overrides each (hysteria::uniproxy) |
up_mbps, down_mbps, ignore_client_bandwidth (default true); no override |
| Hysteria 2 UDP relay and masquerade | [node.hysteria], through hysteria::uniproxy |
the config’s udp and masquerade |
| sss | refused | transform and udp_max_datagram |
traffic_email |
{uuid}@v2board.user |
the uid |
| Report | traffic only | traffic and client addresses, under a report id |
| Audit rules | routes entries with action = "block", no request |
the local rule file only |
| ETag keys | node, users |
node, users |
From user records to credentials
Section titled “From user records to credentials”The panel client hands over UserInfo values as they came. src/lower/mod.rs → lower_users processes them in panel order into the node’s one user set (tag users), a BTreeMap<Uid, UserSpec> keyed and ordered by Uid. Panel order decides only who wins a repeated uid or a shared credential. For each user, in order:
src/lower/inbound.rs→credentials(protocol, u)builds the one credential the node’s inbound protocol takes. A user it refuses is skipped withskipping user {uid}: {why}.- A uid already admitted is skipped with
skipping user {uid}: listed twice; the first row wins. - A user whose credential another admitted user already holds is skipped with
skipping user {uid}: shares its credential with user {first}. The supervisor refuses a whole user set over one credential two users share, so the first user keeps it and the node still comes up. - Otherwise the user becomes
UserSpec { credentials, speed_limit, device_limit }, with the user’s ownspeed_limit(0is none) and theirdevice_limitundercontroller.enable_device_limit.
All three lines are logged at WARN with the target katana::lower. None of them contains a credential: credentials’ reasons name no value, because the value is a secret. One malformed row therefore costs only that user.
| Inbound protocol | Credential set (Credentials field) |
From | why when refused |
|---|---|---|---|
| every protocol | not reached | an empty uuid |
uuid is empty |
| VLESS, VMess, sss | uuid, parsed with Uuid::parse_str |
uuid |
uuid is not a valid UUID |
| Trojan, AnyTLS, Shadowsocks (legacy ciphers) | password |
the UUID text | never refused |
| SOCKS, HTTP | account: user and pass both the UUID text |
uuid |
never refused |
| Shadowsocks 2022 | ss2022_psk |
the first key_len bytes of the UUID text: 16 for 2022-blake3-aes-128-gcm, 32 for 2022-blake3-aes-256-gcm |
shadowsocks-2022 key too short (< 16) (the method’s length) |
Hysteria 2, credential = "uuid" or empty |
password |
the UUID text | never refused |
Hysteria 2, credential = "user_pass" |
account: user traffic_email(u), pass the UUID text |
email or uid, and uuid |
its name holds ':' |
| any other (TUN) | not reached | the inbound admits no panel users |
A helium answer always holds a well-formed UUID, written lowercase and hyphenated, because a malformed one fails the whole answer: on helium uuid is empty and uuid is not a valid UUID cannot arise, while listed twice and shares its credential with user … still can. Since credential cannot be set on helium, a helium Hysteria 2 node always takes the password row. Since 6.1.0 a helium Shadowsocks node may take the legacy row too, as helium-node-api 0.2.0 describes legacy ciphers.
Two users collide when their credentials are equal as lower::identity sees them: the UUID’s 16 bytes (so two spellings of one UUID collide), the password text, the PSK bytes, or the account name lowercased, because Hysteria 2 compares account names case-insensitively; SOCKS and HTTP account names, the UUID text, are lowercased too. The rest of lowering, and the Credentials and UserSpec types, are on Lowering a node into a spec and Users, principals and sessions.
How the node manager uses the results
Section titled “How the node manager uses the results”NodeManager in src/manager/node.rs is the only caller. Its bootstrap, poll loop and static updates run in one task, so a client never sees two of its own calls at once, and every method takes &self. What each return value of the three fetches means to it:
| Return | In a bootstrap attempt | On a poll |
|---|---|---|
Ok(Some(_)) |
Node info and users are lowered into the node’s first spec; rules go to RuleManager::update. |
Node info and users become the node’s current answer; rules go to RuleManager::update, a no-op when the ids and pattern sources are unchanged. |
Ok(None) (HTTP 304) |
The attempt fails with panel returned no node info or panel returned no user list. The rules stay as they are. |
Unchanged: the last answer, or the current rules, are kept. |
Err(e) |
The attempt fails with node_info failed: {e} or user_list failed: {e}, logged at ERROR as node {id}: {reason}; retrying in {n}s. A rules error is logged at WARN as node {id}: node_rule: {e}. |
Logged at WARN as node {id}: node_info: {e}, node {id}: user_list: {e} or node {id}: node_rule: {e}; the last answer, or the current rules, are kept. |
A refused config answer is such an error, its reason in {e}: parse UniProxy config response: <reason> on newV2board, parse helium config response: <e> on helium (see Status errors and error contexts).
The report call returns Ok(()) or an error. NodeManager::report builds each cycle’s NodeReport with a new random id (uuid::Uuid::new_v4): the traffic summed by uid, and the client addresses when collects_ips holds, that is when the client keeps_client_ips (helium) and controller.enable_device_limit is on. A failed report is logged at WARN as node {id}: report {report id}: {e}. What happens to the traffic totals is on Traffic accounting and reporting. Bootstrap and its backoff, the poll loop, the reconcile and shutdown are on The node manager.
Invariants
Section titled “Invariants”| Invariant | Mechanism | Pinned by |
|---|---|---|
| A 4xx or 5xx error never contains the request URL, and so never the panel key. | api::error_for_status calls reqwest::Error::without_url; contexts name the path only. |
No dedicated test. |
helium’s key travels only in the Authorization header. |
bearer_auth on every request; node_url holds no query. |
The e2e tests’ fake helium panel (tests/unit/e2e.rs) refuses a request without the bearer token or with a query string. |
Client addresses reach the panel only where enable_device_limit is on. |
collects_ips. |
a_helium_node_without_enable_device_limit_reports_no_addresses. |
| A node identity is logged without the panel key. | display_id prints panel type, host, node id and, for newV2board, the node type. |
a_node_is_logged_by_its_panel_node_not_its_key and a_wireguard_outbound_several_nodes_route_to_is_reported in tests/unit/runtime.rs. |
| A user who cannot be admitted is named by uid, never by credential, and does not keep the others out. | lower_users logs and skips; credentials’ reasons carry no value. |
users_without_a_usable_credential_are_skipped and a_shared_credential_admits_only_the_first_user in tests/unit/lower/spec.rs (the log text is not asserted). |
| HTTP 304 means “unchanged” and is never an error. | The 304 check runs before error_for_status in each client’s get. |
No dedicated test. a_node_whose_port_is_taken_comes_up_once_it_is_free in tests/unit/e2e.rs runs against a fake panel that answers 304 to a repeated ETag. |
| Every panel request asks for a gzip-compressed answer, a compressed answer is read decompressed, and a weak ETag is kept as it came. | gzip(true) in http_client_builder, with reqwest’s gzip feature. |
a_panel_answer_is_asked_for_and_read_gzip_compressed in tests/unit/api/http.rs. |
| Every bootstrap attempt reads the node and its users in full. | NodeManager::try_bootstrap calls forget_etags before its first request. |
a_node_whose_port_is_taken_comes_up_once_it_is_free. |
An unknown panel_type or node_type fails at construction, where --test and the reload check see it; so do sspanel, a newV2board sss node and a helium node that sets a key the panel describes. |
PanelClient::new; NodeType::parse in newV2board’s Client::new, NO_SSS there too, refuse_local_protocol in helium’s; test_config builds every node’s client; apply_reload builds a client for each added or changed node before it touches a running one. |
a_reload_with_a_node_that_does_not_build_changes_nothing, an_sspanel_node_is_refused_at_test_and_at_start (through test_config, build_node and spawn_node) and a_reload_to_sspanel_changes_nothing in tests/unit/runtime.rs; an_sss_node_is_refused and local_keys_the_panel_describes_are_refused, both through PanelClient::new too. |
A helium node’s --test judges its [node.hysteria] congestion before the panel is asked. |
inbound::congestion in lower::test_spec, for every node. |
a_helium_nodes_check_judges_its_congestion_control in tests/unit/lower/spec.rs. |
An edit to panel_type, any [node.api] field, enable_mtls or [node.hysteria] reaches the panel client. |
An identity change respawns the node; any other such edit makes apply_static build and swap in a new client. |
a_client_edit_takes_effect_without_dropping_connections and a_newv2board_type_edit_respawns_the_node in tests/unit/runtime.rs; a_reload_of_enable_mtls_alone_rebuilds_the_client in tests/unit/manager/node.rs, which also pins that an edit to nothing the client is built from keeps it. No test pins the [node.hysteria] comparison. |
A panel that asks for a client certificate is given one only while the node’s enable_mtls is on, and enable_mtls is on unless the file turns it off. |
http_client_builder adds the identity only with mtls; both clients pass cfg.enable_mtls; default_enable_mtls. |
a_panel_that_asks_is_given_the_certificate_under_mtls_only in tests/unit/api/http.rs; enable_mtls_is_on_unless_turned_off in tests/unit/runtime.rs, which also pins that it is not part of the identity. |
| A rebuilt newV2board client enforces the block rules of the client it replaces until it reads the config. | PanelClient::inherit_routes, called by apply_static before the swap. |
a_rebuilt_client_keeps_the_routes_it_has_not_read in tests/unit/api/newv2board.rs. |
The UniProxy node_type parameter and the node identity agree. |
newv2board::node_type_param, called by Client::new and by api::panel_node_type. |
node_type_param_vless in tests/unit/api/newv2board.rs; a_newv2board_node_is_also_the_type_it_asks_for in tests/unit/runtime.rs. |
tls = 2 is REALITY on a VLESS node and refused on VMess, Shadowsocks, SOCKS and HTTP; a REALITY node’s key and shortId are read as the kernel reads them, and neither the node’s Debug nor a refusal shows them. |
tls, reality, v2ray, shadowsocks, proxy; the contract’s Debug of its keys. |
parse_v2ray_reality_takes_its_tls_settings, a_reality_node_with_bad_settings_is_refused_without_repeating_them, helium_reality_body. |
| A helium node config reaches lowering as helium wrote it; one that breaks a rule of the contract is refused with the rule in the message and no key. | helium::Client::node_info returns the parsed Node; parse puts serde’s text in the outermost message. |
the_node_config_is_the_contracts_as_helium_wrote_it, every_protocol_helium_writes_is_read in tests/unit/api/helium.rs. |
A REALITY node without tls_settings is refused; tls_settings of another shape off REALITY are never decoded. |
reality runs only when tls is 2. |
a_reality_node_without_its_settings_is_refused, another_tls_settings_shape_is_ignored_off_reality. |
A protocol tag of another family than the node, or one katana does not serve, refuses the config; VMess against VLESS only warns; no tag is accepted. |
check_protocol. |
the_panels_protocol_tag_must_match_the_node. |
| Shadowsocks, SOCKS and HTTP nodes read the transport the panel names, as V2ray nodes do. | newV2board: transport, shared by every arm that reads one. helium: the contract’s Transport. |
shadowsocks_reads_its_transport, parse_socks_and_http_read_their_transport_over_tls, helium_shadowsocks_bodies, helium_socks_http_and_anytls_bodies; on helium every_protocol_helium_writes_is_read. |
| Trojan, SOCKS, HTTP, AnyTLS and Hysteria 2 nodes are always TLS. | The contract gives them no security; newV2board refuses SOCKS and HTTP without TLS. | parse_trojan_fixed, parse_socks_and_http_read_their_transport_over_tls; in lowering socks_and_http_nodes_are_tls_and_relay_no_udp and an_anytls_node_is_tls_with_its_padding_scheme. |
| An AnyTLS node is TLS with the panel’s padding lines; an empty or absent list is the default. | The Anytls arm of parse_node_config; the contract’s Anytls. |
parse_anytls_keeps_the_padding_scheme, helium_socks_http_and_anytls_bodies. |
| An sss node comes from helium alone, with its chains and datagram limit; changed chains drop every connection. | NO_SSS in newv2board::Client::new and parse_node_config; disruptive_part keeps the chains. |
an_sss_node_is_refused in tests/unit/api/newv2board.rs; only_a_disruptive_change_drops_every_connection in tests/unit/manager/node.rs. |
| Shadowsocks obfuscation other than none is refused, not ignored. | shadowsocks. |
shadowsocks_ciphers_and_keys. |
A UniProxy TCP node is bare TCP only when its header asks for none; any other is refused as the answer is read, REALITY included. |
plain_tcp_header in transport. |
a_tcp_header_other_than_none_is_refused in tests/unit/api/newv2board.rs, for VMess, VLESS and Shadowsocks bodies. |
| A transport other than TCP, WebSocket and gRPC, a flow other than Vision, SOCKS or HTTP without TLS, and a Shadowsocks cipher katana does not serve are refused by name as a UniProxy answer is read. | transport, v2ray, proxy, shadowsocks, through unsupported. |
a_transport_katana_cannot_serve_is_refused, only_vision_and_only_on_vless, parse_socks_and_http_read_their_transport_over_tls, shadowsocks_ciphers_and_keys. |
| A UniProxy refusal says why in the message a node logs, and never quotes a value of the wrong type. | node_info builds the message with {e:#}; json_error. |
a_malformed_body_is_refused_without_quoting_it. |
A config answer with a server_port outside 1 to 65535 is refused, never truncated into another port. |
parse_node_config reads it into a NonZeroU16. |
a_port_outside_one_to_65535_is_refused, a_config_body_parses_with_its_routes. |
| Obfuscation from the panel reaches the Hysteria listener. | hysteria::uniproxy reads obfs and obfs-password; helium’s config carries obfs; disruptive_part keeps it. |
a_panel_described_hysteria_node_serves_obfuscated_traffic in tests/unit/e2e.rs; a_hysteria_node_is_completed_with_the_local_block. |
| A change to a Hysteria 2 node’s masquerade, obfuscation or port, or turning its UDP relay on or off, closes every session; a new idle timeout, new rates or a new AnyTLS padding scheme do not. | disruptive_part. |
only_a_disruptive_change_drops_every_connection. |
A Hysteria 2 node’s UDP relay and masquerade reach the listener from the node: helium’s from its config, a UniProxy node’s from [node.hysteria]. |
hysteria::uniproxy; lower_hysteria reads the node. |
a_hysteria_node_is_completed_with_the_local_block; the_nodes_hysteria_udp_and_masquerade_reach_the_spec in tests/unit/lower/spec.rs. |
A field the contract gains drops every connection when it changes, unless disruptive_part clears it. |
disruptive_part clones the whole node and clears three things. |
Keep by review; only_a_disruptive_change_drops_every_connection pins the three. |
| Every panel user is keyed by uid, and every flow of theirs is labelled with it. | lower::Uid, whose name() is the decimal uid. |
vmess_traffic_is_metered_and_reported and a_hysteria_node_relays_and_meters (pushes attribute the bytes to "1001"). |
A configured api.speed_limit overrides every panel limit, and lowering holds each user to their limit as it is. |
newv2board::Client::user_list and helium::user_infos; lower_users. |
the_local_speed_override_wins in tests/unit/api/helium.rs; for newV2board conversion only: user_response_speed_limit_and_email; a_user_is_held_to_their_speed_limit in tests/unit/lower/spec.rs. |
| A helium users answer without its limits is refused, never read as no limits; the limits apply to every user. | Every field of users::Users is required; user_infos gives each user the answer’s limits. |
an_answer_without_limits_is_refused, users_are_held_to_the_answers_limits. |
| A helium node’s audit rules are its local rule file alone. | helium::Client::node_rule returns read_local_rules. |
the_audit_rules_are_the_local_list. |
A helium report is the crate’s Report, and never wraps a uid into another customer’s ID or a negative count into a large one; the warning names the uid alone. |
report_body. |
the_report_body_is_the_crates_wire_form, an_out_of_range_uid_or_a_negative_count_is_left_out. |
The UniProxy push body is keyed by uid string with [upload, download]. |
HashMap<String, [i64; 2]> in report_user_traffic. |
vmess_traffic_is_metered_and_reported reads real push bodies; push_body_shape pins only how that map type serializes. |
Failure paths and cancellation
Section titled “Failure paths and cancellation”Nothing in this module retries or logs at ERROR or WARN, apart from the rule warnings below, the protocol-tag warning and helium’s two report warnings. Each call returns a value or an anyhow::Error, and the node manager decides what to keep.
Errors
Section titled “Errors”| Message (outermost) | Raised by | Cause |
|---|---|---|
panel_type "SSpanel" is not supported: katana serves the NewV2board and Helium panels |
PanelClient::new |
panel_type is sspanel in any case; the value is quoted as written. |
unknown panel_type "..." |
PanelClient::new |
panel_type is not newv2board, v2board, helium or sspanel. |
unknown node_type "..." |
newV2board Client::new |
NodeType::parse returned None. |
newV2board: no UniProxy panel describes an sss node; sss is Helium's own protocol, served with panel_type = "Helium" |
newV2board Client::new |
An sss node on newV2board. |
[node.api] node_type is set, but a helium node's protocol is described by the panel; remove it (of [node.hysteria], only congestion is this host's to choose), likewise for the other keys |
helium::refuse_local_protocol, from helium’s Client::new |
A helium node sets a key the panel describes (see Local keys a helium node refuses). |
GET {path} |
GET helpers | The request could not be sent or completed (connect failure, timeout), or the answer was 4xx or 5xx. |
GET {path} body |
GET helpers | The body could not be read in full, including a timeout while reading. |
parse UniProxy config response: <reason> |
newV2board node_info |
The body is not a UniProxy config, or asks for what katana cannot serve; the reasons are in Node configuration. |
parse helium config response: <e> |
helium node_info |
The body is not a node config, or breaks a rule of the contract. |
obfs_password is set but obfs is not; did you mean obfs = "salamander"?, unknown obfs "<obfs>" (expected "salamander"), obfs_password must be at least 4 bytes for salamander, udp_idle_timeout must be between 2 and 600 seconds, udp_idle_timeout is set but udp is not enabled, or a rule of the contract |
api::hysteria::local, from NodeManager::node_info and lower::test_spec |
A local Hysteria 2 node’s [node.hysteria] is refused (see Completing a Hysteria 2 node). |
parse UniProxy user response, parse helium users response: <e> |
newV2board, helium | The body is not the expected JSON; on helium, for example, a users answer without its limits. |
GET config, GET users, GET config body, GET users body |
helium get |
As GET {path} and GET {path} body. |
The report calls add the contexts listed in Status errors and error contexts. A failed report is logged as described in How the node manager uses the results.
Rule problems are warnings, not errors: cannot read rule_list_path ..., invalid local rule ... and invalid block rule ... each drop what they name and keep the rest. helium’s two report warnings (see The report) likewise drop only the entry they name. Lowering adds one more when the routing crate refuses a group: audit rule {id} skipped: {e} (see Destination audit).
Cancellation
Section titled “Cancellation”Every method is at most one request, and spawns nothing but its parse on the blocking pool. Dropping a call’s future abandons its request. The two places a call can be dropped:
- Bootstrap.
NodeManager::bootstrapraces eachtry_bootstrapagainst the shutdown token in abiasedselect!, so a shutdown drops the request in flight.a_node_that_never_bootstraps_still_stopspins that a node retrying against a failing panel stops within 2 s. - Steady state.
NodeManager::servechecks the shutdown token between polls; a poll that has started runs to completion, each of its requests bounded byapi.timeout. Whatrundoes once the loop ends is on The node manager.
No lock in this module (the ETag map, the newV2board routes) is held across an .await, so a dropped future leaves no lock held. A parse handed to the blocking pool runs to its end even when the call is dropped; its result is discarded.
Limits
Section titled “Limits”| Name | Value | Where |
|---|---|---|
| Request timeout | api.timeout seconds, the whole request; 5 when 0 |
ApiConfig::timeout_secs, applied by build_http_client |
| HTTP version | HTTP/1.1 | reqwest built without its http2 feature (Cargo.toml) |
| Retries per call | none in this module | the node manager retries a failed bootstrap attempt; after bootstrap, the next poll requests the node, the users and the rules again |
| Bootstrap retry delay | 1 s, doubling after each failure up to 60 s, never longer than the poll period | BOOTSTRAP_RETRY_MIN, BOOTSTRAP_RETRY_MAX, NodeManager::poll_period |
| Poll period | controller.update_periodic seconds, default 60, at least 1 s |
NodeManager::poll_period |
| Requests per poll, newV2board | config (unless the node is a local Hysteria 2 node) and users; one push when disable_upload_traffic is off and there is traffic to report |
poll_cycle |
| Requests per poll, helium | config and users; one report when there is traffic or there are client addresses to send | poll_cycle, NodeManager::report |
MBPS_TO_BPS |
1_000_000.0 / 8.0 = 125 000 |
src/api/mod.rs |
| ETag keys | "node", "users" |
per client |
| Redirects followed | none | http_client_builder |
| Compression | gzip asked for on every request and decoded; an uncompressed answer read as it is | reqwest’s gzip feature, gzip(true) in http_client_builder |
| Panel port | 1 to 65535; anything else refuses the config | parse_node_config; the contract’s NonZeroU16 |
| Local rule id | -1 |
read_local_rules |
| Shadowsocks 2022 user key | 16 or 32 bytes of the UUID text | credentials |
| helium uid in a report | an i32; any other is left out |
report_body |
| sss chain | at most 8 expressions each way | the helium-node-api crate |
| AnyTLS padding scheme | at most 2048 bytes, the lines joined with \n |
the helium-node-api crate |
| Hysteria 2 UDP idle timeout | 2 to 600 s, 60 when not given | api::hysteria::udp for [node.hysteria]; the helium-node-api crate for helium, and for every node through validate |
The unit tests live outside src/ and are compiled into the modules they test with #[cfg(test)] #[path = "../../tests/unit/api/…"] mod tests;. Being child modules, they call the private functions (parse_node_config, detect_rules, helium’s parse, parse_users and report_body) and build the private response structs directly, so most need no HTTP server. tests/unit/api/http.rs runs one, to see what the HTTP client presents and asks for, and the_node_config_is_the_contracts_as_helium_wrote_it answers node_info from a canned panel on loopback. The newV2board tests compare what parse_node_config returns with the contract’s Node written out; the helium tests build their bodies from the helium-node-api types, or from JSON in their wire form.
tests/unit/api/newv2board.rs:
| Test | Pins |
|---|---|
node_type_param_vless |
vless for a VLESS-enabled V2ray node; otherwise the lowercased type (v2ray, trojan, shadowsocks). |
parse_v2ray_ws_tls |
ws with headers.Host as host, the path, and tls = 1, as a VMess node over WebSocket and TLS; a missing path is /, and an empty Host is none. |
parse_v2ray_reality_takes_its_tls_settings |
tls = 2 on a VLESS node is REALITY with the server name, the cover site’s port, the key and the shortId, held lowercase; the node’s Debug shows neither the key nor the shortId. |
a_reality_node_with_bad_settings_is_refused_without_repeating_them |
A bad shortId, a key that does not decode, an empty server name, a cover-site port of 0, a key of the wrong JSON type and missing tls_settings are each refused for what is wrong, and no refusal repeats the key or the shortId; REALITY over WebSocket fails with reality runs over transport tcp only, and REALITY on VMess is refused. |
only_vision_and_only_on_vless |
xtls-rprx-vision-udp443 is refused as a VLESS flow, a flow off VLESS is refused, Vision over TLS fails with needs security reality, and Vision over REALITY parses. |
a_reality_node_without_its_settings_is_refused |
tls = 2 without tls_settings fails, naming them. |
another_tls_settings_shape_is_ignored_off_reality |
A tls = 1 node with tls_settings of Xboard’s shape parses as VMess over TLS. |
the_new_node_type_names_parse |
anytls (any case), socks and http parse, and the node_type parameter of anytls is anytls. |
shadowsocks_reads_its_transport |
A Shadowsocks node over gRPC with TLS and over WebSocket reads its transport; a node that names none stays on TCP; tls = 2 is refused (over REALITY). |
shadowsocks_ciphers_and_keys |
Every legacy name the kernel knows, aliases included, is its SsLegacyCipher; a 2022 key is read as given, and a 32-byte key on 2022-blake3-aes-128-gcm is folded to 16 bytes; rc4-md5 and 2022-blake3-chacha20-poly1305 are refused by name, a key that is not base64 without being quoted, a 16-byte key on the 256-bit cipher as PSK too short, and obfs = "http" by name. |
parse_anytls_keeps_the_padding_scheme |
The port and the padding lines kept in order; null and [] are none. |
parse_socks_and_http_read_their_transport_over_tls |
A SOCKS and an HTTP node over WebSocket with TLS read the transport, path and Host; without TLS each is refused (without TLS), and with tls = 2 too (over REALITY). |
parse_trojan_fixed |
A Trojan node’s port; its host and server_name are not read. |
a_transport_katana_cannot_serve_is_refused |
httpupgrade, splithttp, xhttp and quic are each refused by name, as node requests kernel-unsupported feature. |
a_tcp_header_other_than_none_is_refused |
On VMess, VLESS and Shadowsocks bodies, no header, {}, a null type and none in any case are bare TCP; the types http and "", a type that is not a string and a header that is not an object are refused; a REALITY body with an http header is refused too. |
a_port_outside_one_to_65535_is_refused |
0, -1, 65536 and 70000 are refused as is not a port. |
a_malformed_body_is_refused_without_quoting_it |
A server_key of the wrong type is refused as wrong type, without the value; a body that is not JSON names line 1. |
a_hysteria_node_is_completed_with_the_local_block |
The panel’s Salamander obfuscation and rates are read (down_mbps as a string, ignore_client_bandwidth as 0), [node.hysteria]’s up_mbps overrides the panel’s, and its UDP relay (60 s) and masquerade status reach the node; the panel’s obfuscation is refused by the block’s rules (a password without obfs, an unknown obfs, a 2-byte password). |
a_config_body_parses_with_its_routes |
parse_node_config returns the node and every route; detect_rules turns only the block route into a rule, with its index as id, and a body without a port is refused. |
user_response_speed_limit_and_email |
mbps_to_bps(10.0) is 1 250 000. |
a_users_device_limit_may_be_a_number_null_or_absent |
3, null and a missing field read as Some(3), None and None. |
push_body_shape |
A HashMap<String, [i64; 2]> holding "1001" → [123, 456] serializes as {"1001": [123, 456]}. The test builds the map itself and does not call report_user_traffic. |
a_rebuilt_client_keeps_the_routes_it_has_not_read |
After inherit_routes, a new client’s node_rule returns the old client’s block route as a rule before the new client has fetched the config. |
helium_shadowsocks_bodies, helium_socks_http_and_anytls_bodies, helium_reality_body |
Bodies in the UniProxy shape that helium’s node API v1 sent, tagged with the node’s protocol, verbatim, parse through parse_node_config into the contract’s nodes: Shadowsocks 2022 over gRPC with TLS and plain, SOCKS and HTTP over TLS, AnyTLS with a padding scheme, VLESS with REALITY and Vision and the empty shortId. |
the_panels_protocol_tag_must_match_the_node |
A vmess tag on a Trojan node fails, an unknown tag fails, vmess against a VLESS node is accepted and stays VLESS, an untagged body is accepted, and hysteria is Hysteria 2. |
an_sss_node_is_refused |
A newV2board node configured as sss fails Client::new and PanelClient::new with a text naming sss; parse_node_config refuses an sss body both for an sss node and for a V2ray node. |
tests/unit/api/helium.rs reads node configs in helium’s wire form and compares them with the Node the crate deserializes them to:
| Test | Pins |
|---|---|
the_node_is_named_in_the_path |
A trailing / on the host is trimmed, and node_url is {host}/api/node/v2/{node_id}. |
the_node_config_is_the_contracts_as_helium_wrote_it |
Against a canned panel on loopback, a REALITY node with Vision comes back from node_info as the Node the crate reads from the same JSON; a REALITY node over WebSocket is refused with security reality runs over transport tcp only, and the message holds no key. |
every_protocol_helium_writes_is_read |
One config of each protocol, VMess over gRPC with TLS, Trojan, Shadowsocks 2022 with keys of both lengths, AnyTLS with a scheme, SOCKS, HTTP over WebSocket, sss with a chain and Hysteria 2 with Salamander, rates and UDP, parses through parse and keeps its protocol. |
users_are_held_to_the_answers_limits |
Every user takes the answer’s limits; the UUID is written lowercase and hyphenated; email is empty; 0 is no limit. |
an_answer_without_limits_is_refused |
An answer without limits, or without either of its two fields, fails. |
the_local_speed_override_wins |
api.speed_limit (8 Mbps) wins as 1 000 000 B/s, and the device limit stays the panel’s. |
the_report_body_is_the_crates_wire_form |
The JSON body, key by key: report_id, agent_version, traffic with id, up and down, and ips by uid; it reads back as the same Report. |
an_out_of_range_uid_or_a_negative_count_is_left_out |
A uid above i32::MAX or below i32::MIN, and a negative upload or download, are left out; the log names each uid and none of the counts or addresses. |
the_audit_rules_are_the_local_list |
node_rule returns the local file’s rule with id -1, and no rule without a file. |
local_keys_the_panel_describes_are_refused |
Each of the 12 keys refuses Client::new and PanelClient::new with a text that names it; congestion = "bbr" passes. |
tests/unit/api/http.rs is compiled into src/api/mod.rs as its tests module. It stands up two panels on loopback: one that asks every client for a certificate and answers whether it was given one, and one, compressing_panel, that answers a client accepting gzip with a gzip-compressed users body and a weak ETag, and any other client with 406, so a client that did not ask for gzip fails:
| Test | Pins |
|---|---|
a_panel_that_asks_is_given_the_certificate_under_mtls_only |
A client built by http_client_builder with mtls is answered cert, and one built without it none. |
a_panel_answer_is_asked_for_and_read_gzip_compressed |
A client from build_http_client is answered 200, keeps the ETag W/"7" as it came, and reads the decompressed JSON. |
tests/unit/lower/spec.rs, tests/unit/lower/inbound.rs, tests/unit/rule.rs and tests/unit/manager/node.rs pin what happens to the models after this module:
| Test | Pins |
|---|---|
users_without_a_usable_credential_are_skipped |
On a VMess node, a user whose UUID does not parse and a user with an empty UUID are left out; the third is admitted. |
a_shared_credential_admits_only_the_first_user |
Of [5:A, 2:A, 3:B, 5:B], uids 3 and 5 are admitted, and uid 5 keeps its first row’s credential. |
a_user_is_held_to_their_speed_limit |
A user’s limit of 2000 B/s is their UserSpec.speed_limit, and 0 is unlimited (None). |
a_vless_node_lowers_vless |
A Node::Vless lowers a VLESS inbound. |
acme_cert_mode_rejected, reject_unknown_sni_is_refused_rather_than_ignored, tls_without_cert_file_errors |
What lowering still refuses is this host’s: an ACME cert mode, reject_unknown_sni, and a TLS node without its certificate files. |
a_reality_node_lowers_to_its_server_spec |
A contract Reality with the flow Vision lowers to a VLESS inbound with Vision over REALITY: one server name, the empty shortId, the cover site at its port, no certificate; without a flow, no flow. |
ss2022_builds, every_legacy_cipher_lowers_to_the_kernels |
A Shadowsocks 2022 user’s key is the first 16 bytes of the UUID’s text on 2022-blake3-aes-128-gcm; each SsLegacyCipher lowers to the kernel’s method of the same name. |
hysteria_accepts_both_credential_kinds |
"" and "uuid" lower to password auth, "user_pass" to account auth. |
a_panels_masquerade_the_kernel_cannot_answer_with_is_refused |
A node whose masquerade status the kernel cannot answer with (99) is refused (not an HTTP status code) before the certificate is read. |
the_nodes_hysteria_udp_and_masquerade_reach_the_spec |
A Hysteria 2 node’s 90 s idle timeout and 502 masquerade reach the inbound; a node that relays no UDP and keeps the 404 does so whatever [node.hysteria] says; a node from hysteria::uniproxy takes both from the block (60 s, status 403). |
a_helium_nodes_check_judges_its_congestion_control |
A helium node’s test_spec lowers no inbound, passes congestion = "bbr" and refuses "vegas". |
audit_rules_route_first_to_one_blackhole_per_rule_id |
Rules with ids 7, 9 and 7 lower to the routes audit#7 and audit#9, each one domain-regex matcher to a blackhole outbound, ahead of the node’s own block route. |
an_audit_tag_is_reserved |
An [[outbound]] tagged audit#1 fails lowering (duplicate/reserved outbound tag audit#1). |
update_skips_identical_ruleset |
Same ids and pattern sources are not a change. |
only_a_disruptive_change_drops_every_connection |
In tests/unit/manager/node.rs: a new padding scheme, new rates and a new UDP idle timeout keep every connection; turning UDP off, a new obfuscation key, a new port, a new transport, a new or dropped masquerade and new sss chains drop them. |
tests/unit/e2e.rs is compiled into the binary crate as mod e2e from src/main.rs. It runs a real NodeManager and a real PanelClient over loopback HTTP against hand-written panels:
| Fake panel | Serves |
|---|---|
fake_panel, fake_panel_dynamic, fake_panel_with_config |
newV2board: /UniProxy/config and /UniProxy/user, and records every /UniProxy/push body. fake_panel_dynamic serves a user body the test can swap between phases. |
fake_panel_quirky |
The same, with Quirks: config_failures answers that many config requests with a 500 first; etags tags every answer with an ETag (a hash of the body) and answers a request that sends it back with 304, as Xboard does. It also counts config requests. |
fake_helium |
helium’s node API v2 for node 1: /api/node/v2/1/config and /api/node/v2/1/users from the bodies a test gives it, with ETags and 304, and /api/node/v2/1/report, which it records and answers with duplicate. It refuses with 403, and counts, a request without the bearer token or with a query string. helium_users_body builds a users body with no limits from the crate’s types, and helium_node_cfg a helium node with no node_type. |
The tests that exercise this module most directly:
| Test | Pins |
|---|---|
vmess_traffic_is_metered_and_reported |
The config and user answers become a working VMess node, and the push body attributes the bytes to uid 1001. |
unchanged_user_survives_user_refresh |
A changed user answer is picked up by a later poll: when a second user is added, the first user’s live connection survives; when the first user is then removed, that connection drops; the pushes attribute both phases’ bytes to uid 1001. |
a_users_speed_limit_paces_their_traffic |
A panel speed_limit of 8 Mbps paces the user at 1 000 000 B/s: 3 MB take at least 1.5 s. |
a_panel_described_hysteria_node_serves_obfuscated_traffic |
obfs and obfs-password from the panel reach the listener; a client using the same key relays. |
a_retired_user_stops_while_the_rest_keep_their_connections |
A Hysteria 2 user dropped from the panel’s list stops relaying, while the remaining user’s QUIC connection stays up. |
repeated_user_refreshes_never_disturb_a_live_connection |
Six polls, each of which adds or removes a second user, leave a Hysteria 2 user’s one QUIC connection up and relaying. |
a_hysteria_node_refuses_an_unknown_credential |
A UUID the panel’s user list does not hold does not authenticate on a Hysteria 2 node. |
a_node_comes_up_once_the_panel_answers |
A panel that answers the first two config requests with 500 delays the node; it comes up on the first real answer and relays. |
a_node_whose_port_is_taken_comes_up_once_it_is_free |
A failed bind is retried against a panel that answers 304 to a repeated ETag; the retry reads the node and users in full, and the node comes up once the port is free. |
a_node_that_never_bootstraps_still_stops |
A node retrying its bootstrap against a panel that always fails stops within 2 s of shutdown. |
a_helium_node_without_enable_device_limit_reports_no_addresses |
Traffic is reported and every ips list is empty. |
an_sss_node_relays_through_its_chains_and_meters |
A helium config of protocol sss, with a chain each way, served by fake_helium, becomes a working sss node, and the reports attribute the bytes to uid 1001. |
a_panel_that_sets_rates_has_the_node_send_at_the_agreed_one |
UniProxy Hysteria 2 rates (up_mbps = 24, down_mbps = 16, ignore_client_bandwidth = false) reach the listener: a client offering 40 up and 32 down is told 16, and downloads at about 24, the smaller of its 32 and the node’s 24. |
tests/unit/runtime.rs is compiled into src/runtime.rs as its tests module. It checks the node identity and the config keys, runs test_config, startup and reloads against running nodes, using the fake panels above:
| Test | Pins |
|---|---|
a_newv2board_node_is_also_the_type_it_asks_for |
On newV2board the node_type parameter is part of the identity too; api.speed_limit, api.rule_list_path, api.timeout and a case-only node_type edit are not; enable_vless on a Trojan node is not. |
a_node_is_logged_by_its_panel_node_not_its_key |
display_id is newv2board@https://panel.example#3/v2ray for a newV2board V2ray node and helium@https://panel.example#3 for helium. |
a_wireguard_outbound_several_nodes_route_to_is_reported |
The shared-WireGuard warning lists nodes by display_id, and no entry contains the key. |
a_newv2board_type_edit_respawns_the_node |
Turning enable_vless off on newV2board respawns the node, which then serves VMess. |
a_reload_with_a_node_that_does_not_build_changes_nothing |
A node_type typo refuses the whole reload: the running node, its recorded config and a live connection are untouched. |
an_sspanel_node_is_refused_at_test_and_at_start |
A file with panel_type = "SSpanel" fails test_config and build_node with panel_type "SSpanel" is not supported, and spawn_node runs no node. |
a_reload_to_sspanel_changes_nothing |
A reload that turns a running newV2board node’s panel_type into SSpanel is refused whole: the node, its recorded config and VMess service are kept. |
enable_mtls_is_on_unless_turned_off |
A node that does not name enable_mtls has it on, enable_mtls = false turns it off, and turning it off leaves the identity as it is. |
a_client_edit_takes_effect_without_dropping_connections |
Setting rule_list_path on newV2board builds a new client: new flows to the listed name are refused, while a live connection keeps relaying. |
The integration tests under tests/integration/ run the real katana binary against tests/support/mod.rs → FakePanel, a newV2board panel that serves one config body and one user list and records every push. The bodies come from v2ray_config_body, trojan_config_body, hysteria_config_body and users_body. tests/support/mod.rs also fixes the panel-side values every test shares: NODE_ID = 1, UID = 1001, and one fixed UUID constant for the user.
| Test file | What it drives through the panel client |
|---|---|
tests/integration/xray_interop.rs |
Nodes described by the panel, against a real Xray client: vmess_tcp_plain, vmess_ws_plain, vmess_grpc_plain, vmess_tcp_tls, vless_ws_tls, vless_grpc_tls, trojan_tcp_tls, and the mux cells vmess_tcp_plain_mux, vless_ws_tls_mux, trojan_tcp_tls_mux. Each cell relays a payload and then waits for the panel to receive traffic for uid 1001. |
tests/integration/hysteria_interop.rs |
a_real_client_proxies_through_a_katana_hysteria_node: users from the panel, the listener from [node.hysteria], and the upstream Hysteria client. |
Each test builds its client with go from the reference trees in the sibling Etemenanki checkout, and skips itself when go or the tree is missing.
No test checks that a panel request error leaves the key out; the runtime tests above cover only display_id and the shared-WireGuard warning. A change to error_for_status, to the contexts in the clients’ get, in report_user_traffic or in helium’s report, or to how the node manager renders panel errors needs a test that does.