把节点降为 spec
源码文件:35 个 · 核对版本 katana v6.1.0 · Etemenanki 46c12e4
katana/src/lower/mod.rskatana/src/lower/route.rskatana/src/lower/inbound.rskatana/src/lower/outbound.rskatana/src/rule.rskatana/src/api/mod.rskatana/src/api/hysteria.rskatana/src/config.rskatana/src/manager/node.rskatana/src/runtime.rskatana/src/main.rskatana/tests/unit/lower/spec.rskatana/tests/unit/lower/inbound.rskatana/tests/unit/e2e.rsEtemenanki/supervisor/src/topology/spec_plan/mod.rsEtemenanki/supervisor/src/topology/spec_plan/route.rsEtemenanki/supervisor/src/topology/spec_plan/inbound.rsEtemenanki/supervisor/src/topology/inbound/mod.rsEtemenanki/supervisor/src/topology/flow.rsEtemenanki/supervisor/src/entity/user.rsEtemenanki/supervisor/src/entity/usage.rsEtemenanki/supervisor/src/policy.rsEtemenanki/supervisor/src/guard.rsEtemenanki/supervisor/src/build/users.rsEtemenanki/supervisor/src/build/inbound.rsEtemenanki/supervisor/src/build/validate.rsEtemenanki/supervisor/src/build/route.rsEtemenanki/supervisor/src/supervisor.rsEtemenanki/supervisor/src/track/mod.rsEtemenanki/supervisor/src/track/pace.rsEtemenanki/environment/src/routing.rsEtemenanki/supervisor/tests/hot_swap.rsEtemenanki/supervisor/tests/unit/track.rsEtemenanki/supervisor/tests/unit/validate.rsEtemenanki/environment/tests/unit/routing.rs
katana 自己不运行监听器、路由器或计量器。每个 [[node]] 拥有一个 etemenanki_supervisor::Supervisor<Uid>,katana 的工作是描述这个 supervisor(监管器)应当运行什么:一份 spec(期望状态),即 Spec<Uid>,由节点的 TOML、进程级的 [[outbound]] 和 [dns]、面板对节点的描述、面板的用户列表以及面板的审计规则构建而成。这一转换称为 lowering(降为 spec),代码位于 src/lower/。本页讲 src/lower/mod.rs(整份 spec、用户、凭据、限速、策略以及 --test 用的 spec)和 src/lower/route.rs(路由表)。
本页面向需要修改“面板应答如何变成 spec”的贡献者。两个同级文件在别处讲:入站与出站的 lowering 负责 src/lower/inbound.rs 和 src/lower/outbound.rs(监听器、TLS、Hysteria 2、出站客户端和 DNS),目标审计负责 src/rule.rs。supervisor 拿到 spec 之后做什么,见 spec:期望状态、校验与应用错误和用户、principal 与会话。
lowering 负责:
- 为一个节点构建
Spec<Uid>:入站、所有节点共享的出站和 DNS、审计出站与审计路由、节点自己的路由表、用户集和策略; - 把每个面板用户变成一个
UserSpec:节点协议所读取的那一种凭据、限速,以及在enable_device_limit下面板给出的设备数限制; - 根据
[node.controller]构建策略,即 IP 封禁和 gRPC 承载连接关闭; - 对节点无法准入的用户、重复出现的 uid、以及凭据已被更早用户出示的用户,记一条
WARN并跳过,使一行坏数据不会让node_spec失败; - 在任何 spec 存在之前,按名稱拒絕 TOML 提出而核心做不到的要求。面板提出而 katana 無法提供的內容根本不會到達 lowering:契約的型別寫不出它,newV2board 客戶端也會在讀取回答時拒絕它(面板客戶端);
- 先判斷節點的真實 IP 鍵、轉交鍵和 Hysteria 2 擁塞控制,再建立一份更小的 spec,供
--test和設定重載在詢問面板之前檢查節點(test_spec); - 為
--test,以及為自己指定埠的節點(只有 newV2board 節點能這樣做),把api::hysteria::local依[node.hysteria]建立的 Hysteria 2 節點降為 spec。
lowering 不负责:
- 繫結、撥號或 spawn 任何東西。唯一的副作用是:讀取 spec 以位元組形式攜帶的憑證、私鑰和 DNS CA 檔案;為轉交 socket 的群組讀取
/etc/group;探測一次本機的 IPv6 socket 是否也接受 IPv4(inbound::dual_stack,所用的 socket 只建立一次,且從不繫結);在lower_route中用RouteFile::stat為路由指名的每個 geo 檔案打上當時位於該路徑的檔案的戳記;以及下文的日誌行。 - 載入 geo 資料。路由 spec 按路徑指明
.dat檔案並附上各自的戳記,由 supervisor 載入規則用到的集合。 - 检查引用,或检查需要解析器的内容:
.dat文件里的 geo 代码,以及以字节形式携带的 PEM。指向不存在出站的规则或default会原样传下去,由 supervisor 拒绝(校验与应用错误)。validate_admission的逐用户规则也仍归 supervisor;lower_users只是跳过会违反这些规则的用户(用户)。 - 决定 spec 何时应用、一次应用会关闭哪些连接。那是节点管理器的事。
katana 確實會自己判斷少數幾個值。lower_outbounds 拒絕重複的或保留的 [[outbound]] tag,所以 supervisor 永遠看不到衝突的 tag。Hysteria 2 節點 2 到 600 秒之外的 udp_idle_timeout、短於 4 位元組的 Salamander obfs_password,以及契約不允許的偽裝(masquerade),都在 lowering 之前被拒絕:[node.hysteria] 和 UniProxy 節點的由 api::hysteria 拒絕,helium 的由契約的 Deserialize 拒絕。lower_hysteria 會按 Hysteria 2 伺服端接受的範圍再判斷一次偽裝(inbound::masquerade_spec),supervisor 的 validate 會再判斷一次這三個值。關於偽裝,masquerade_spec 的文件註釋給出了原因:這個應答“按 supervisor 會拒絕的方式拒絕:這裡也判斷一次,好讓拒絕資訊和一直以來的一樣”。
| 文件 → 符号 | 作用 |
|---|---|
src/lower/mod.rs → node_spec |
运行中的节点所应用的 spec。 |
src/lower/mod.rs → shared_spec(私有) |
除入站和用户以外的一切:出站、审计出站、DNS、路由、策略。 |
src/lower/mod.rs → policies(私有) |
由 [node.controller] 得出的 supervisor Policies。 |
src/lower/mod.rs → lower_users(私有) |
面板用户,组成一个 BTreeMap<Uid, UserSpec>。 |
src/lower/mod.rs → identity(私有) |
判断两个用户凭据是否冲突时比较的字节。 |
src/api/hysteria.rs → local |
只由 [node.hysteria] 描述的 Node,由 test_spec 和節點管理器降為 spec(面板客戶端)。 |
src/lower/mod.rs → test_spec |
--test 和重载检查经 etemenanki_supervisor::check 运行的 spec。 |
src/lower/route.rs → lower_route |
把 [node.route] 降为 RouteSpec。 |
src/lower/inbound.rs → credentials |
一个用户针对节点入站协议的凭据。 |
src/lower/inbound.rs → lower_inbound、inbound_tag,src/lower/outbound.rs → lower_outbounds、lower_dns |
入站及其 tag、出站和 DNS(入站与出站的 lowering)。 |
src/rule.rs → audit_routes |
每个审计规则 id 对应一个 blackhole 出站和一条路由(目标审计)。 |
lowering 在哪里运行
Section titled “lowering 在哪里运行”| 调用方 | 调用 | 结果去向 |
|---|---|---|
src/manager/node.rs → NodeManager::try_bootstrap,经 NodeManager::lower_off_runtime |
node_spec,传入本次初次启动(bootstrap)尝试读到的节点和用户,以及当前的审计规则 |
Supervisor::start。这份 spec 作为已应用的 spec 保存。 |
src/manager/node.rs → NodeManager::reconcile,经 NodeManager::lower_off_runtime,来自轮询周期和 StaticUpdate::Globals |
node_spec,传入本次轮询最终采用的节点和用户;globals 更新时传入最后保存的应答 |
与已应用的 spec 比较,然后 Supervisor::apply_with(spec, ApplyOptions { allow_disruptive: true })。 |
src/manager/node.rs → NodeManager::node_info |
api::hysteria::local,條件是 [node.api].node_type 解析為 Hysteria 2 且 [node.hysteria].port 不為 0,而 helium 客戶端這兩個鍵都拒絕 |
代替面板的節點應答;不詢問面板。 |
src/runtime.rs → check_node,来自 test_config(--test)、build_node 和 apply_reload |
test_spec |
etemenanki_supervisor::check(&spec)。 |
NodeManager::lower_off_runtime 在节点配置的 mutex 下克隆节点配置,克隆 Arc<Globals>,并通过 RuleManager::rules 取得 Arc<[DetectRule]> 形式的规则集。随后 node_spec 在不持有任何锁的情况下、在阻塞线程池上运行,因为它的工作量随用户列表增长;与已应用 spec 的比较,以及 supervisor 取走的那份副本,也都在那里完成。一次轮询最终采用哪些应答、spec 何时应用、何时关闭所有连接,见节点管理器。运行时如何使用 check_node,见运行时与配置重载。
哪些由 katana 拒绝,哪些由 supervisor 拒绝
Section titled “哪些由 katana 拒绝,哪些由 supervisor 拒绝”模組註解這樣劃分:“面板的應答以契約的節點到達,其中沒有核心無法提供的內容;TOML 提出而核心做不到的要求,在這裡、在 spec 存在之前按名稱拒絕;各個有型別的部件如何拼合(tag、引用、憑據衝突)則由 supervisor 在應用 spec 時檢查。”
| 拒绝方 | 规则类型 | 示例(--test 在 configuration error: node 1: 之后打印的内容) |
|---|---|---|
katana lowering(ErrorKind::InvalidInput) |
值的语法:CIDR、端口规格、密钥、证书模式 | invalid cidr "192.0.2.1/24": host part of address was not zero、invalid port spec: "80-"、hysteria2 node requires cert.mode = "file" |
katana lowering(ErrorKind::InvalidInput) |
katana 自己的保留项 | duplicate/reserved outbound tag audit#1 |
api::hysteria(ErrorKind::InvalidInput),supervisor 的 validate 再判斷一次 |
[node.hysteria] 中 Hysteria 2 的取值範圍 |
udp_idle_timeout must be between 2 and 600 seconds、obfs_password must be at least 4 bytes for salamander |
katana lowering(ErrorKind::Unsupported) |
核心沒有實作的本機設定或出站 | node requests kernel-unsupported feature: cert.reject_unknown_sni、node requests kernel-unsupported feature: ACME cert mode "dns"、unsupported shadowsocks cipher "<name>"([[outbound]] 的) |
katana lowering(读取本身的 io::Error) |
无法读取的证书、私钥或 DNS CA 文件 | 读取失败(入站与出站的 lowering) |
supervisor validate |
引用、tag,以及入站准入的用户 | route references unknown outbound nowhere |
supervisor 构建(check 或 start) |
需要文件或解析器的内容:geo 数据、PEM | building route failed: a geosite matcher is used but no geosite file is configured、building route failed: geosite code not found: no-such-code-xyz、building inbound Hysteria2_0.0.0.0_1 failed: hysteria2: the certificate file contains no certificates |
没有调用方根据 io::ErrorKind 分支;每个调用方都用 Display 打印错误。kind 记录的只是这次拒绝落在划分的哪一侧。
面板提出而 katana 無法提供的內容在 lowering 之前、在面板客戶端讀取回答時就被拒絕,並記錄為失敗的 node_info(啟動引導時為 node 1: node_info failed: parse UniProxy config response: node requests kernel-unsupported feature: tcp header type "http"; retrying in 1s)。--test 從不詢問面板,所以從不印出這類拒絕;這些拒絕見面板客戶端。6.1.0 之前由 lowering 拒絕它們,並記錄為 lowering 錯誤。
/// 一个面板用户,按 supervisor 给用户建索引的方式表示:即其面板 id。#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]pub struct Uid(pub i64);
impl UserId for Uid { fn name(&self) -> UserName { UserName::Username(self.0.to_string().into()) }}Uid 是 katana 用到的每个 supervisor 类型的 U:Supervisor<Uid>、Spec<Uid>、UserSet<Uid>、UsageDelta<Uid>。UserId 的约束是 Clone + Eq + Ord + Hash + Debug + Send + Sync + 'static:derive 提供了 Clone + Eq + Ord + Hash + Debug,而 i64 的 newtype 自动满足 Send + Sync + 'static。它的名字是装着十进制 uid 的 UserName::Username,所以 uid 1001 的名字就是 1001。UserName“从来不是机密”,所以日志和各协议的用户标签带的都是它。
十进制 uid 是把一个流和它所属面板用户联系起来的唯一线索:
| 位置 | 携带 uid 的是什么 |
|---|---|
| 用户集 | BTreeMap<Uid, UserSpec>,所以用户集按 uid 顺序迭代。 |
| supervisor 的 principal(身份主体) | supervisor/src/build/users.rs → admit:用户仍凭当初准入时的凭据被准入时,保留其 principal;否则新建 Principal::user(keys.key(id), id.name().as_str().into()),它的标签就是十进制 uid。 |
| 协议用户表 | supervisor/src/build/inbound.rs → user_table 把 principal 的标签作为 Trojan、AnyTLS、Shadowsocks 和 Shadowsocks 2022 用户的 email,sss 的表和 Hysteria 2 认证器则把它作为每个用户的标签。VLESS 和 VMess 的表只带 UUID 和 principal,SOCKS 和 HTTP 的表带账号和 principal。 |
| 流 | FlowEntry::user_label() 返回 principal 的标签。 |
| 客戶端位址 | src/manager/node.rs → NodeManager::spawn_client_ips 把每條新開啟的流的標籤解析回 i64,在面板保留客戶端位址時,把該流的來源位址記在這個 uid 名下(流量計費與回報)。 |
| 用量 | Supervisor::take_usage() 返回 UsageDelta<Uid>,NodeManager::take_traffic 把 delta.user.0 作为面板 uid 上报(流量计费与上报)。 |
| supervisor 关于用户的错误 | validate_admission 用 id.name() 指称用户,user_table 用 principal 的标签指称用户;两者都是十进制 uid。 |
USER_SET
Section titled “USER_SET”/// 节点入站所准入的那一个用户集的 tag。pub const USER_SET: &str = "users";inbound::lower_inbound 把 InboundSpec::users 设为 Some(USER_SET.into()),node_spec 用同一个常量给它构建的用户集打 tag。每个节点有自己的 supervisor,所以这个 tag 只需在一份 spec 内唯一。
| 输入 | 类型,文件 | lowering 从中读取什么 |
|---|---|---|
| 節點設定 | NodeConfig,src/config.rs |
[node.controller]:listen_ip、disable_sniffing、disable_vmess_clock_check、cert、enable_device_limit、real_ip_header、real_ip_from、ban_max_failures、ban_window_secs、ban_secs、carrier_max_failures、handoff_dir、handoff_group。[node.api]:node_type,只用於 test_spec。[node.hysteria]:lower_hysteria 讀取 credential 和 congestion,test_spec 對每個節點讀取 congestion,並對 Hysteria 2 節點經 api::hysteria::local 讀取整個區塊;helium 節點只能設定 congestion。[node.route]。 |
| globals | Globals { outbounds: Vec<OutboundConfig>, dns: DnsConfig },src/config.rs |
每个 [[outbound]] 和 [dns]。Config::globals() 克隆它们;每个节点降为 spec 的都是同一份。 |
| 節點 | Node,即契約的 helium_node_api::config::NodeConfig,src/api/mod.rs |
它的變體、埠,以及 lower_inbound 從中讀取的內容:傳輸層、security、REALITY 的設定、flow、加密方式和金鑰、填充方案、sss 的變換鏈和資料報上限,以及 Hysteria 2 的混淆、速率、UDP 中繼和偽裝(入站與出站的 lowering)。它不含這臺主機的任何設定,也不含限速。 |
| 使用者 | &[UserInfo],src/api/mod.rs |
uid、uuid、speed_limit(位元組每秒,0 表示不限)、device_limit(0 表示不限),以及 Hysteria 2 user_pass 節點經 traffic_email(src/api/mod.rs)讀取的 email。 |
| 审计规则 | &[DetectRule],src/api/mod.rs,其中 DetectRule { id: i64, pattern: Regex } |
每条规则的 id 及其模式的源文本。 |
使用者的限速到達時已經以位元組每秒為單位。helium 的 users 應答給出一個以位元組每秒為單位的限速,由客戶端複製到每個使用者上;newV2board 客戶端用 api::mbps_to_bps 換算面板給出的 Mbps(MBPS_TO_BPS = 1_000_000.0 / 8.0,所以 1 Mbps 是每秒 125,000 位元組,0 或以下的值得 0),[node.api].speed_limit 大於 0 時會取代面板的值;見面板客戶端。
pub fn node_spec( cfg: &NodeConfig, globals: &Globals, node: &Node, users: &[UserInfo], audit: &[DetectRule],) -> io::Result<Spec<Uid>>;
pub fn test_spec(cfg: &NodeConfig, globals: &Globals) -> io::Result<Spec<Uid>>;
fn shared_spec(cfg: &NodeConfig, globals: &Globals, audit: &[DetectRule]) -> io::Result<Spec<Uid>>;fn policies(c: &ControllerConfig) -> Policies;fn lower_users( protocol: &InboundProtocolSpec, users: &[UserInfo], device_limits: bool,) -> BTreeMap<Uid, UserSpec>;fn identity(c: &Credentials) -> Vec<u8>;pub fn lower_route(route: &RouteConfig) -> io::Result<RouteSpec>;pub fn local(cfg: &HysteriaConfig, port: NonZeroU16) -> io::Result<Node>;/// `u` 向服务 `protocol` 的入站出示的凭据。无法准入某个用户时,/// 给出的原因不提及任何凭据:凭据的值是机密。pub fn credentials(protocol: &InboundProtocolSpec, u: &UserInfo) -> Result<Credentials, String>;credentials 以 String 返回原因,lower_users 记录这个原因并跳过该用户。
katana 构建的 spec
Section titled “katana 构建的 spec”node_spec 构建 Spec<Uid> 的以下字段(各类型的说明见 spec:期望状态):
Spec 字段 |
node_spec 放入的内容 |
构建者 | 来源 |
|---|---|---|---|
inbounds |
最多一個 InboundSpec,即節點的入站。tag 為 inbound::inbound_tag 給出的 <Type>_<listen_ip>_<port>,其中 <Type> 是 V2ray、Trojan、Shadowsocks、Hysteria2、AnyTLS、Socks、Http 或 Sss(例如 V2ray_0.0.0.0_443);繫結為 inbound::bind_host(listen_ip) 和節點埠上的 BindSpec::Tcp,Hysteria 2 則為 BindSpec::Udp;handoff 在設定了 handoff_dir 的 TCP 繫結上是位於 <handoff_dir>/<port>.sock(listen_ip 是單個位址時為 <handoff_dir>/<ip>-<port>.sock,見 inbound::handoff_file)、許可權 0o660、gid 取自 handoff_group 的 HandoffSpec,其他情況下為 None;sniff: !disable_sniffing;協定;users: Some("users");user_removal: None;TCP 繫結為 proxy_protocol: true,Hysteria 2 的 UDP 繫結為 false;real_ip 在設定了 real_ip_header 的 WebSocket 節點上是一個 RealIpSpec,其他情況下為 None。 |
inbound::lower_inbound |
Node、[node.controller]、[node.hysteria] |
outbounds |
direct、block、freedom、blackhole,然后按文件顺序是每个 [[outbound]],再按 id 首次出现的顺序,每个审计规则 id 一个 audit#<id> blackhole。来自本地规则列表的规则都带 id -1,所以它们共用一个 audit#-1 出站(目标审计)。每个 drain 都是 None。 |
outbound::lower_outbounds、rule::audit_routes |
Globals.outbounds、审计规则 |
balancers |
始终为空。katana 没有负载均衡器配置。 | shared_spec |
— |
route |
先是審計路由,然後按檔案順序是 [[node.route.rule]];default 取自 [node.route].default,預設為 "direct";geo 檔案路徑按原樣寫入,各自帶上該路徑當時所指檔案的戳記。 |
route::lower_route、rule::audit_routes |
[node.route]、審計規則 |
dns |
DnsSpec::Single(backend),设置了 [dns].ca_file 时带上该文件的字节。 |
outbound::lower_dns |
Globals.dns |
user_sets |
最多一個:UserSet { tag: "users", users }。supervisor 的 validate 用 validate_admission,對照以 users tag 指向它的那個入站來檢查它。 |
lower_users |
面板使用者、enable_device_limit |
policies |
user_removal: UserRemovalPolicy::Close 和 drain: DrainPolicy::Keep,即默认值;ip_ban 和 carrier_max_failures 取自 [node.controller]。 |
policies,由 shared_spec 调用 |
[node.controller] |
入站的 tag 和绑定地址都由 listen_ip 构建。tag 按原样使用它,绑定主机则要经过 bind_host:在本机 IPv6 socket 也接受 IPv4 的情况下,它把 0.0.0.0 绑定为 ::(入站与出站的 lowering)。
fn policies(c: &ControllerConfig) -> Policies { let ip_ban = NonZeroU32::new(c.ban_max_failures) .filter(|_| c.enable_device_limit) .map(|max_failures| IpBanPolicy { max_failures, window: Duration::from_secs(c.ban_window_secs), duration: Duration::from_secs(c.ban_secs), }); Policies { ip_ban, carrier_max_failures: NonZeroU32::new(c.carrier_max_failures), ..Policies::default() }}移除策略和 drain 策略是 supervisor 的默认值,没有任何东西覆盖它们:入站的 user_removal 和每个出站的 drain 都是 None。
| 策略 | 值 | 效果 |
|---|---|---|
UserRemovalPolicy |
Close |
supervisor 范围的默认值,作用于 supervisor 撤销的 principal(用户离开了用户集,或不再出示当初准入时所用的凭据)。Close 做什么见用户、principal 与会话。 |
DrainPolicy |
Keep |
supervisor 范围的默认值;它对变更或移除的出站意味着什么,见出站、UDP fan-out 与负载均衡器和规划并应用变更。 |
ip_ban |
在 enable_device_limit 下为 IpBanPolicy { max_failures: ban_max_failures, window: ban_window_secs, duration: ban_secs },默认值为 120 s 内失败 30 次即封禁 300 s;没有它,或 ban_max_failures 为 0 时为 None |
认证失败达到这个频率的客户端 IP 会被封禁(IPv6 客户端的整个 /64 作为一个 IP 计数和封禁):它的新 TCP 连接在 accept 时就被丢弃,已打开的连接则继续运行。一次成功的认证会清零它的计数。 |
carrier_max_failures |
carrier_max_failures,默认 8;为 0 时为 None |
一条 gRPC 连接上连续这么多条流认证失败时,关闭这条连接。 |
IP 封禁和设备数限制一样统计客户端地址,所以只在 enable_device_limit 表明 katana 看到的地址就是客户端自己的地址时才设置:客户端直连,前面的中转发送 PROXY protocol v2 头部,或者在 WebSocket 节点上由受信任的反向代理在 real_ip_header 中给出客户端(入站与出站的 lowering)。承载连接关闭统计的是一条连接上的流,不依赖它也照样生效。supervisor 在每次提交时接收这些策略;它如何应用这些策略,见监听器与服务循环。
需要關閉連線的地方,由 katana 自己關閉。當一次面板應答無法體現的 [[node]] 編輯需要斷開所有連線、當 [[outbound]] 或 [dns] 的變化以 StaticUpdate::Globals 到達、或當面板改變了節點中一變化就會斷開所有連線的部分(disruptive_part:除 AnyTLS 填充方案以及 Hysteria 2 節點的速率和 UDP 閒置逾時以外的全部)時,NodeManager::reconcile 會在應用(apply)提交之後呼叫 Supervisor::close(Selector::All)(節點管理器)。
为什么每个 tag 在构造上就唯一
Section titled “为什么每个 tag 在构造上就唯一”lower_outbounds拒绝这样的[[outbound]]:它的 tag 与内置出站(direct、block、freedom、blackhole)或更早的条目重复,或以AUDIT_TAG_PREFIX("audit#")开头:duplicate/reserved outbound tag <tag>。audit_routes在构建出站之前按 id 给规则分组,所以每个audit#<id>只出现一次。- 一个节点的 spec 最多只有一个入站和一个用户集。
所以对 node_spec 返回的 spec,supervisor 的 DuplicateTag 拒绝永远不会触发。引用则是另一回事:指向不存在出站的规则或 default 会原样传下去,由 supervisor 拒绝(route references unknown outbound <tag>)。
flowchart LR AR["DetectRule 列表"] --> A1["rule::audit_routes"] G["Globals"] --> A2["outbound::lower_outbounds"] G --> A3["outbound::lower_dns"] CFG["NodeConfig"] --> A4["route::lower_route"] A1 --> SS["shared_spec"] A2 --> SS A3 --> SS A4 --> SS N["Node"] --> LI["inbound::lower_inbound"] CFG --> LI LI --> LU["lower_users"] U["UserInfo 列表"] --> LU SS --> S["Uid 的 Spec"] LI --> S LU --> S S --> SUP["Supervisor::start 或 apply_with"]
node_spec 按顺序执行以下步骤,并返回遇到的第一个错误:
shared_spec(cfg, globals, audit):rule::audit_routes(audit)返回审计出站和审计路由(目标审计)。outbound::lower_outbounds(globals)?返回四个内置出站和每个[[outbound]]。- 追加审计出站。
outbound::lower_dns(&globals.dns)?在设置了ca_file时读取它,并构建后端。route::lower_route(&cfg.route)?把节点的规则降为 spec。route.rules.splice(0..0, audit_rules)把审计路由放到最前。- 组装 spec:没有入站、没有用户集、没有负载均衡器,策略为
policies(&cfg.controller)。
inbound::lower_inbound(cfg, node)?把监听器降为 spec,在 stream 节点上还包括它的转交 socket,在 WebSocket 节点上还包括它的real_ip。对 TLS stream 节点和每个 Hysteria 2 节点,它会读取证书和私钥文件;read_cert_key在读取任何文件之前,先以TLS node requires cert.cert_file and cert.key_file拒绝空的cert_file或key_file。lower_users(&inbound.protocol, users, cfg.controller.enable_device_limit)按第 2 步得到的協定把使用者降為 spec,因為協定決定每個使用者出示哪種憑據。- 至少准入了一个用户时,用第 2 步和第 3 步的结果填充
spec.inbounds和spec.user_sets,用户集的 tag 为USER_SET;一个节点 spec 中两者各自最多只有一个。没有任何人可用的节点两者都得不到,所以它不在任何地方监听;不过,内核无法服务的入站在第 2 步就已经被拒绝了。
出现多个错误时,这个顺序决定报告哪一个:坏的 [[outbound]] 先于坏的 [dns] 报告,坏的 [dns] 先于坏的 [node.route],坏的 [node.route] 又先于入站的任何问题。
各节点类型的凭据
Section titled “各节点类型的凭据”inbound::credentials(protocol, u) 只填写 Credentials 的一个字段,即 supervisor 对该协议读取的那个字段(supervisor/src/build/users.rs → credential_kind)。每个凭据都由用户的 uuid 字符串派生;面板用户不带 katana 会用到的其他任何机密。
| 節點 | 入站協定 | Credentials 欄位 |
值 |
|---|---|---|---|
Vless |
Vless |
uuid |
Uuid::parse_str(uuid):uuid crate 能解析的任何形式(帶連字元、不帶連字元、帶花括號、URN)。 |
Vmess |
Vmess |
uuid |
同 VLESS。 |
Sss |
Sss |
uuid |
同 VLESS。 |
Trojan |
Trojan |
password |
uuid 文本原样(XrayR 的约定:密码就是用户的 UUID)。 |
Anytls |
Anytls |
password |
uuid 文本原样。 |
Socks、Http |
Socks、Http |
account |
Account { user: uuid, pass: uuid }:面板的用户除了 UUID 什么也不带,所以它既是名称也是密码。 |
使用舊式加密方式(SsCipher::Legacy)的 Shadowsocks |
Shadowsocks |
password |
uuid 文字原樣。 |
使用 2022 加密方式(SsCipher::Ss2022)的 Shadowsocks |
Ss2022 |
ss2022_psk |
uuid 文字的前 method.key_len() 位元組:2022-blake3-aes-128-gcm 為 16,2022-blake3-aes-256-gcm 為 32。 |
Hysteria2,[node.hysteria].credential 为空或 "uuid" |
Hysteria2,Hysteria2UserAuth::Password |
password |
uuid 文本原样。客户端的整个 auth 字符串就是 UUID。 |
Hysteria2,credential = "user_pass" |
Hysteria2,Hysteria2UserAuth::Account |
account |
Account { user: traffic_email(u), pass: uuid }。traffic_email 是面板的 email,email 为空时是十进制 uid。客户端发送 user:pass。 |
Shadowsocks 2022 用户的密钥是其 uuid 文本的前 method.key_len() 字节。以占位 UUID 11111111-2222-3333-4444-555555555555 在 2022-blake3-aes-128-gcm 上为例,密钥是 16 个 ASCII 字节 11111111-2222-33,客户端写作 MTExMTExMTEtMjIyMi0zMw==。因为只有前缀起作用,两个 UUID 文本前 16 个字符相同的用户在 AES-128 节点上出示的是同一个密钥,面板顺序中靠后的那个会因共享凭据而被跳过。服务端密钥来自节点的 server_key(入站与出站的 lowering)。
節點是 VLESS 還是 VMess 由面板客戶端決定:newV2board 客戶端為設定了 [node.api].enable_vless 的 V2ray 節點建立 Node::Vless,否則建立 Node::Vmess,helium 的設定則自己寫明 vless 或 vmess。lowering 不讀任何 [node.api] 鍵來決定是 VLESS 還是 VMess。
在 helium 節點上,users 應答以 UUID 型別而不是自由文字攜帶每個使用者的 UUID,helium::user_infos 把它以小寫、帶連字元的形式(uuid.hyphenated())寫入 UserInfo.uuid。所以在 helium 上,表中的每個憑據都是這段 36 個字元的文字,或由它解析回來的 UUID。表中有一行在 helium 上用不到:helium 節點不能設定 [node.hysteria].credential,所以它的 Hysteria 2 使用者總是直接出示 UUID。從 helium-node-api 0.2.0 起,helium 節點可以是舊式 Shadowsocks,它的使用者以 UUID 文字作為密碼。
遍历用户列表
Section titled “遍历用户列表”lower_users 按面板顺序把面板的列表遍历一次:
flowchart TB
U["按面板顺序取下一个用户"] --> C{"credentials 成功?"}
C -- "否" --> W1["WARN: skipping user uid: reason"]
C -- "是" --> D{"该 uid 已加入集合?"}
D -- "是" --> W2["WARN: skipping user uid: listed twice"]
D -- "否" --> I{"identity 已属于更早的用户?"}
I -- "是" --> W3["WARN: skipping user uid: shares its credential with user first"]
I -- "否" --> K["记下归属者,插入 Uid 及其凭据、限速和设备数限制"]
每次跳过都在 target katana::lower 下记一条 WARN,写明 uid,然后继续下一个用户。原因来自 credentials,其中从不包含被拒绝的值:
| 日志消息 | 原因 |
|---|---|
skipping user <uid>: uuid is empty |
面板发来空的 uuid。对所有协议都最先检查。 |
skipping user <uid>: uuid is not a valid UUID |
VLESS、VMess 或 sss,且 Uuid::parse_str 失败。 |
skipping user <uid>: shadowsocks-2022 key too short (< <key_len>) |
Shadowsocks 2022,且 uuid 文本短于 16 或 32 字节。 |
skipping user <uid>: its name holds ':' |
Hysteria 2 user_pass,且用户名(email 或 uid)含冒号,user:pass 的线上格式无法承载它。 |
skipping user <uid>: the inbound admits no panel users |
入站是 TUN。katana 从不为面板节点构建这类入站,所以不会走到这个分支。 |
skipping user <uid>: listed twice |
该 uid 已在集合中。同一 uid 中凭据能成功降为 spec 的第一行胜出。 |
skipping user <uid>: shares its credential with user <first> |
面板顺序中更早的另一个用户出示了相同的凭据。 |
检查按这个顺序进行:先 credentials,再重复 uid,最后共享凭据。某个 uid 的第二行如果凭据无法降为 spec,记录的是凭据的原因,而不是 listed twice;某个 uid 的第一行被跳过时,它后面的行仍可能被准入。函数的注释给出了跳过而不是失败的原因:“一行格式错误的数据不能拖垮其他所有人。”
前兩個原因不會出現在 helium 節點上:帶空的或格式錯誤的 UUID 的 users 應答無法解析,客戶端會以 parse helium users response 讓整個應答失敗,於是節點保留已有的使用者,與任何一次失敗的取得一樣。listed twice 和 shares its credential with user <first> 在那裡仍可能出現。
什么算共享凭据
Section titled “什么算共享凭据”identity(c) 返回判断两个用户冲突时比较的字节:UUID 的 16 字节;否则为密码的字节;否则为 Shadowsocks 2022 密钥的字节;否则为用 to_ascii_lowercase 转成小写的账户用户名。credentials 只设置一个字段,所以第一个存在的字段就是唯一的那个。没有设置任何字段时,identity 返回空的 Vec(unwrap_or_default);credentials 总会设置一个,所以不会走到这种情况。lower_users 记住每个 identity 最先由哪个 uid 出示,记录在一个以 identity 字节为键、按列表大小预留容量的 HashMap 中:这次遍历在每次轮询时都会运行,处理的列表有数万个用户,所以每次检查都是一次查找,而不是一次扫描。lowering_a_large_list_is_not_quadratic 降出 200 001 个用户,其中最后一个与第一个共用 UUID,并检查最后一个仍被跳过。
这些规则与 supervisor 的 validate_admission(supervisor/src/build/validate.rs)一致,后者在两个用户出示同一凭据时拒绝整个入站:
| 凭据 | katana 比较 | validate_admission 比较 |
|---|---|---|
| UUID | 16 字节 | 16 字节 |
| 密码 | 字节 | 字节 |
| Shadowsocks 2022 密钥 | 密钥的字节 | 密钥的字节 |
| 账户(SOCKS、HTTP、Hysteria 2) | 用户名,按 ASCII 转小写;忽略密码 | 用户名,在 Hysteria 2 入站上转小写(“Hysteria 2 在线上比较用户名时不区分大小写”),在 SOCKS 和 HTTP 上按原样 |
如果 katana 把两个用户都传下去,supervisor 会以 inbound <tag>: users <a> and <b> present the same credential(或 username)拒绝整份 spec,其中 <a> 和 <b> 是十进制 uid。katana 改为保留第一个用户,这正是 lower_users 中注释所说的:“supervisor 会因一个共享凭据拒绝整个用户集,所以由第一个用户保留它。”
validate_admission 对 Hysteria 2 还有两条逐用户规则。lower_users 构建的集合从不违反它们,因为 Hysteria 2 密码就是非空的 UUID,而账户的用户名非空且不含 :,密码是非空的 UUID:
inbound <tag>: user <uid>: a hysteria2 account needs a name without ':' and a passwordinbound <tag>: user <uid>: a hysteria2 password must not be emptysupervisor 如何处理这个用户集
Section titled “supervisor 如何处理这个用户集”以下是 supervisor 一侧的简述;细节见用户、principal 与会话。
- 入站准入
users集合中持有其协议所读凭据种类的每个用户,并给每个用户一个该入站自己的 principal,标签为十进制 uid。 - 只要用户仍凭同一凭据被准入,principal 就会在多次应用之间保留。所以用户集变化时,没有变化的用户、以及只有限速或设备数限制变化的用户,都保留各自的会话。
- 用户的设备数限制在会话绑定时生效:当该用户的其他会话已经来自与限制数量相同的地址时,来自超出限制的地址的会话会被拒绝。调低的限制不关闭任何会话。
- 被替换(凭据变了)或被丢弃(用户离开了集合)的 principal 会被撤销;spec 的
UserRemovalPolicy::Close接下来做什么,见用户、principal 与会话。 - 入站按 tag 指名用户集,所以用户不属于它的
InboundSpec;supervisor 如何替换用户表,见用户、principal 与会话。
使用者自己的限速
Section titled “使用者自己的限速”lower_users 把每個使用者的 UserSpec::speed_limit 設為 NonZeroU64::new(u.speed_limit):使用者自己的速率,以位元組每秒計,0 表示不限速並變成 None。面板客戶端已經在 [node.api].speed_limit 大於 0 時用它取代了這個值(它的註解:“Already the local speed_limit where one overrides the panel’s: the panel clients read it into every user”,即在本地 speed_limit 覆蓋面板的值時,這裡已經是它,因為面板客戶端把它讀進了每個使用者),所以 lowering 自己從不讀取這個覆蓋值。單位自始至終是位元組每秒,與 supervisor 的 UserSpec::speed_limit 所期望的一致(a_user_is_held_to_their_speed_limit)。
katana 6.1.0 移除了節點層級的限速 NodeInfo.speed_limit,以及給每個使用者取節點限速和其自身限速中較小非零值的 determine_rate。沒有任何面板客戶端把節點限速設成 0 以外的值,而本地 Hysteria 2 節點的節點限速就是 [node.api].speed_limit,即它的使用者已經帶著的覆蓋值,所以每個使用者的限速都與從前相同。
从面板一直到一次被节流的读取,整条链路如下:
| 步骤 | 值 | 位置 |
|---|---|---|
面板的速率,或大于 0 的 [node.api].speed_limit |
Mbps,f64;来自 helium 的为字节每秒 |
面板应答,src/config.rs |
mbps_to_bps |
字节每秒,u64,0 表示不限 |
src/api/mod.rs,在面板客户端中(helium 自己的数值不经过它) |
UserInfo.speed_limit |
位元組每秒 | src/api/mod.rs |
NonZeroU64::new |
Option<NonZeroU64> |
src/lower/mod.rs → lower_users |
UserSpec::speed_limit |
有效载荷字节每秒,由该用户的所有流在两个方向、TCP 和 UDP 上共享,突发量为一秒的速率 | supervisor/src/entity/user.rs |
Actor::publish_limits、Tracker::change_speed_limits、Pacer::set_rate |
该用户的令牌桶 | supervisor/src/supervisor.rs、supervisor/src/track/mod.rs、supervisor/src/track/pace.rs |
例如,8 Mbps 是每秒 1,000,000 字节:e2e 测试 a_users_speed_limit_paces_their_traffic 给一个面板用户 "speed_limit":8,要求通过一条 VMess 连接搬运 3 MB 至少耗时 1.5 s。令牌桶如何进入欠额、为什么这样设计,见流跟踪、统计与限速。
改变后的限速如何到达存活的流
Section titled “改变后的限速如何到达存活的流”來自面板的新限速(newV2board 上是使用者的,helium 上是使用者應答給出的),或來自 [node.api].speed_limit 編輯的新限速,會在不關閉已開啟的流的情況下到達它們:
sequenceDiagram participant P as 面板 participant N as NodeManager participant L as node_spec participant A as Supervisor actor participant T as Tracker 的 pacer participant F as 存活的流 N->>P: 轮询周期中的 user_list P-->>N: 某个用户带着新的 speed_limit N->>L: 把节点及其用户降为 spec L-->>N: UserSpec 的 speed_limit 已变的 spec N->>A: apply_with,因为 spec 与已应用的不同 A->>A: 规划并准备,然后提交 A->>T: publish_limits,然后 change_speed_limits T->>T: 对该用户的 pacer 调用 Pacer::set_rate F->>T: 下一次读或写 poll 同一个 pacer
- 新速率是
users集合中一個UserSpec的變化,所以降出的 spec 與已應用的不同,節點管理器會應用它。節點本身沒有變,所以僅憑這一變化,節點管理器不會關閉連線。 - 用户的凭据没有变,所以其 principal 被保留,会话保持打开。
a_speed_limit_change_keeps_the_users_sessions在 supervisor 的用户更新路径(Supervisor::set_users)上覆盖了这一点,该路径与应用一样,通过同一个admit准入用户。 - 在提交(commit)时,而且只在那时,
publish_limits把变化了的限速发布给 tracker(“被拒绝的应用不能改变存活的限速”)。一个用户在多个用户集中时,取其中最小的限速;katana 的 spec 只有一个用户集。Tracker::change_speed_limits对每个限速变化了的用户的 pacer(限速器)调用Pacer::set_rate:speed_limit变为None的用户被设为不限速。同一次提交还会替换每个用户的设备数限制。 Pacer::set_rate保留“以旧速率攒下的”余额,但不超过新的突发量;刚被限速的用户从满桶开始,取消限速则清掉余额。该用户的每个存活流已经持有同一个Arc<Pacer>,所以会在下一次读或写时感受到新速率。一个正在为欠额休眠的流至少睡MIN_WAIT= 1 ms,最多MAX_WAIT= 1 s 后就会再检查,所以提高或取消的限速在一秒内生效(a_raised_or_removed_limit_is_felt_within_a_second)。
[node.api].speed_limit 的編輯會重建面板客戶端,緊接著的輪詢週期會用新值讀取使用者。由 [node.hysteria] 描述的節點也從面板取得使用者,所以同一次輪詢會給它新值。這個編輯不屬於會斷開所有連線的那類本地編輯(節點管理器)。
每个 [[node]] 运行自己的 supervisor,有自己的 tracker 和 pacer。由两个节点服务的同一个面板用户,在每个节点上分别限速。
路由的 lowering
Section titled “路由的 lowering”lower_route
Section titled “lower_route”lower_route(&cfg.route) 把 [node.route] 变成 RouteSpec,按文件顺序为每个 [[node.route.rule]] 生成一个 RouteRuleSpec:
| TOML 键 | RouteMatch |
如何降为 spec |
|---|---|---|
domain_suffix |
DomainSuffix(s) |
用 to_ascii_lowercase 转小写。 |
cidr |
Cidr(IpCidr) |
用 cidr crate 的 IpCidr 解析。裸地址表示单个主机;设置了主机位的会被拒绝。错误:invalid cidr "<s>": <e>。 |
port |
PortRange(lo, hi) |
etemenanki_environment::routing::parse_port_match:"443" 为 PortRange(443, 443),"8000-8080" 包含两端,每个数字两侧的空格会被去掉。 |
geosite |
GeoSite(code) |
原样。 |
geoip |
GeoIp(code) |
原样。 |
outbound |
RouteRuleSpec::outbound |
原样。 |
[node.route] 键 |
RouteSpec 字段 |
值 |
|---|---|---|
default |
default |
原样,缺省时为 "direct"。lower_route 的文档注释写道:“没有任何规则匹配的流从 direct 出去,除非 default 另有指定。” |
geoip |
geoip |
原樣路徑的 RouteFile::stat:路徑本身,加上路由降為 spec 時位於該路徑的檔案的戳記(Option<RouteFile>)。 |
geosite |
geosite |
同上,用於 geosite 路徑。 |
lower_route 每次把路由降為 spec 時,都為每個 geo 檔案打上戳記。它的模組註釋寫道:“Each is stamped with the file at its path when the route is lowered, so a file replaced at the same path rebuilds the route on the next apply.”,即每個檔案在路由降為 spec 時都帶上當時位於其路徑的檔案的戳記,所以在同一路徑上換掉的檔案會讓下一次應用重建路由。同一路徑上換了檔案,戳記就不同,降出的 spec 也就與已應用的不同。每次輪詢都會把節點降為 spec,並與已應用的 spec 比較(節點管理器),所以節點的下一次輪詢,或在它之前的任何一次調和,都會應用新的 spec,supervisor 隨之用新檔案重新建立路由。戳記從不讓 lowering 失敗:RouteFile::stat 回傳的是 RouteFile 而不是 Result;規則能否使用該檔案,要等 supervisor 建立路由時才判斷(supervisor 之後檢查什麼)。
一条规则的匹配条件按种类依次加入,与它们在文件中的顺序无关:先是所有 domain_suffix,然后是 cidr、port、geosite 和 geoip。supervisor 的路由表按顺序尝试规则,一条规则只要有任一匹配条件匹配就算匹配(RouteTable::pick,“第一个有任一匹配条件命中的规则胜出”),所以规则内部的顺序只改变匹配条件的求值顺序。一条同时写了 domain_suffix = ["example.com"] 和 port = ["443"] 的规则,会匹配所有去往 example.com 的流,以及所有去往 443 端口的流。没有匹配条件的规则永远不匹配;路由指南向运维人员说明了这一点。
域名后缀在这里转一次小写,是因为路由器在每次路由决策时把流请求的域名和嗅探到的域名各转一次小写,再与按原样存储的匹配条件比较;带大写字母存储的后缀永远不会匹配。模块注释给出了另一半原因:“域名在这里转一次小写,而不是在每次匹配时转。”
lower_route 返回的错误都是 ErrorKind::InvalidInput,--test 的打印如下:
configuration error: node 1: invalid cidr "10.0.0.0/33": invalid length for network: Network length 33 is too long for Ipv4 (maximum: 32)configuration error: node 1: invalid cidr "192.0.2.1/24": host part of address was not zeroconfiguration error: node 1: invalid port spec: "80-"configuration error: node 1: invalid port spec: "70000"configuration error: node 1: invalid port spec: "443-80" has a lower bound above its upper boundparse_port_match 拒绝倒置的范围,因为它会编译成一条永远无法匹配的规则,而这样的规则看起来和一条从未被命中的规则没有区别。
supervisor 之后检查什么
Section titled “supervisor 之后检查什么”lower_route 只写出 geo 文件和出站 tag 的名字,不去查看它们。supervisor 的 validate 拒绝指向不存在出站的规则或 default,supervisor/src/build/route.rs → compile_routes 只加载规则用到的 geosite 和 geoip 代码:
configuration error: node 1: route references unknown outbound nowhereconfiguration error: node 1: building route failed: a geosite matcher is used but no geosite file is configuredconfiguration error: node 1: building route failed: geosite code not found: no-such-code-xyz编译好的路由表和 plane(数据平面)如何服务流,见 plane:为每个流选路和路由模型。
审计路由在最前
Section titled “审计路由在最前”shared_spec 把審計路由拼接到節點自己的規則前面,所以被審計的域名會在任何 [[node.route.rule]] 把它送到別處之前被截住。每個審計規則 id 變成一個 RouteRuleSpec,其中只有一個覆蓋該 id 全部模式的 RouteMatch::DomainRegex,指向 blackhole 出站 audit#<id>。審計規則為 7: ^ads\.、9: tracker 和 7: ^promo\.,[node.route] 中有一條 block 規則時,路由的出站依次為 audit#7、audit#9、block(audit_rules_route_first_to_one_blackhole_per_rule_id)。匹配見目標審計。
本地 Hysteria 2 节点
Section titled “本地 Hysteria 2 节点”自己指定埠的 Hysteria 2 節點由 [node.hysteria] 而不是它的面板描述。當 NodeType::parse(&cfg.api.node_type) 為 Some(NodeType::Hysteria2)(hysteria2、hysteria 或 hy2,大小寫不限)且 [node.hysteria].port 不為 0 時,NodeManager::node_info 用 api::hysteria::local(&cfg.hysteria, port) 建立這個節點;埠為 0 時,與其他所有節點型別一樣詢問面板(Hysteria 2 指南)。helium 節點永遠不是本地描述的:它的客戶端拒絕 node_type 和 [node.hysteria].port,所以總是詢問它的面板。NodeManager::node_info 的文件註釋也這樣說:“A helium node is never local”。
local 返回一份位於該區塊埠上的 Node::Hysteria2,帶有區塊的混淆、速率(未設定時為 0,即不設上限也不設限制)、ignore_client_bandwidth(未設定時開啟)、UDP 中繼和偽裝,並在它上面執行契約的 validate;它的規則和訊息見面板客戶端。結果和任何面板給出的 Node 一樣,所以 lower_inbound 按同樣的方式降它,lower_hysteria 只從 [node.hysteria] 讀取 credential 和 congestion。這個節點的使用者仍來自面板,限速也隨使用者而來。
在 newV2board 上,同一個區塊也用來補全面板所描述的 Hysteria 2 節點:api::hysteria::uniproxy 取面板的混淆和速率、區塊對速率的覆蓋值,以及區塊的 UDP 中繼和偽裝,UniProxy 沒有欄位可寫這兩項。在 helium 上,面板描述混淆、速率、UDP 中繼、閒置逾時和偽裝;憑據種類保持預設的 uuid,congestion 是 helium 節點唯一可以設定的 [node.hysteria] 鍵(入站與出站的 lowering)。
6.1.0 之前,這是 lower::local_hysteria_node,它逐個欄位寫出一份 NodeInfo,把 [node.api].speed_limit 當作節點層級的限速,並把 UDP 中繼、偽裝和速率留給 lower_hysteria 從區塊讀取。單元測試現在以契約的值建立節點:tests/unit/lower/spec.rs 中的 vmess_node() 是一份位於埠 443、走 TCP、不帶 TLS 的 Node::Vmess。
test_spec:--test 和重载检查运行什么
Section titled “test_spec:--test 和重载检查运行什么”runtime::check_node 執行 etemenanki_supervisor::check(&lower::test_spec(cfg, globals)?)。test_spec 先對每個節點依次呼叫 inbound::real_ip(&cfg.controller)?、inbound::handoff(&cfg.controller)? 和 inbound::congestion(&cfg.hysteria)?,並丟棄結果。它的註釋給出了原因:“Local, so judged now for every node type, not only once a panel names a WebSocket node or a port, or (helium) a Hysteria 2 node.”,即這些鍵是本地設定,所以現在就對每種節點型別做出判斷,而不是等到面板給出一個 WebSocket 節點或一個埠,或者(helium)一個 Hysteria 2 節點時才判斷。因此 --test、啟動和熱重載都會拒絕只設一半或寫錯的真實 IP 設定、中轉無法使用的轉交設定,以及不是 cubic、bbr 或 reno 的擁塞控制,例如在 --test 下報 configuration error: node 1: real_ip_header needs real_ip_from: the proxies trusted to set it、configuration error: node 1: handoff_group is set without handoff_dir 或 configuration error: node 1: unknown hysteria congestion "vegas" (expected "cubic", "bbr" or "reno"),儘管會讀取它們的入站在這裡並沒有降出。擁塞控制檢查對任何型別的節點都成立,所以 [node.hysteria] 寫了未知擁塞控制的 VMess 節點同樣會被拒絕。handoff 會在 /etc/group 中查詢 handoff_group,所以在沒有這個組的主機上檢查會失敗。check 驗證 spec,針對一個空的 supervisor 做規劃,並準備它描述的一切(出站、帶 geo 資料的路由、帶憑證的 handler(處理器)、使用者表),但不繫結監聽器,也不啟動任何東西。它“拒絕啟動時會拒絕的一切,只差無法繫結的埠或裝置”(驗證與應用錯誤)。
[node.api].node_type(按 NodeType::parse 的读法) |
test_spec 返回 |
|---|---|
Hysteria 2(hysteria2、hysteria 或 hy2,大小寫不限) |
node_spec(cfg, globals, &node, &[placeholder], &[]),其中 node 是 api::hysteria::local(&cfg.hysteria, port),port 取 [node.hysteria].port,為 0 時取 1(NonZeroU16::MIN)。沒有審計規則。 |
| 其他任何值 | shared_spec(cfg, globals, &[]):没有入站、没有用户集、没有审计规则。 |
在 newV2board 上,Hysteria 2 節點自己的設定都在本地(本地 Hysteria 2 節點),所以 test_spec 根據這些設定建立節點,並把它的入站降為 spec。無論面板之後是否給出埠,api::hysteria::local 都會先判斷區塊的混淆、UDP 中繼和偽裝;它的註解說明瞭為什麼要建立這個節點:“A node whose panel names its port is judged on a placeholder one.”,即由面板給出埠的節點,就在一個佔位埠上判斷。NodeType::parse 把值轉成小寫,接受 v2ray、vmess 和 vless(V2ray)、trojan、shadowsocks、hysteria2、hysteria 和 hy2(Hysteria2)、anytls、socks 和 socks5(Socks)、http 以及 sss。對其他任何值,包括 NodeType::parse 不認識的值,test_spec 也走第二個分支;check_node 的每個呼叫方都會先建立節點的 PanelClient,而 newV2board 客戶端會拒絕這樣的值(unknown node_type "<value>")。
helium 節點不寫 node_type:它的面板描述協定,helium 客戶端會在 check_node 執行之前拒絕 node_type、enable_vless,以及 [node.hysteria] 中除 congestion 以外的任何鍵。它空的 node_type 走第二個分支,所以無論面板之後給出什麼協定,test_spec 都像判斷其他非 Hysteria 節點那樣判斷它:做上面三項本地檢查,不降出入站(a_helium_nodes_check_judges_its_congestion_control)。test_spec 的文件註釋寫道:“A helium node names no node_type (its panel describes the protocol), so it is judged as every other node is.”,即 helium 節點不寫 node_type(由面板描述協定),所以按其他所有節點的方式判斷。
test_spec 用一个占位用户把 Hysteria 2 入站降为 spec:
UserInfo 字段 |
值 |
|---|---|
uid |
0 |
email |
"placeholder" |
uuid |
"placeholder" |
speed_limit、device_limit |
0 |
credential 为空或 "uuid" 时,它降为 password: "placeholder";为 "user_pass" 时降为 account: placeholder / placeholder。端口 1 代替面板将来提供的端口,所以 port = 0 的节点按 Hysteria2_<listen_ip>_1 检查;check 不绑定任何东西,所以这个端口从不会被打开。
runtime::test_config 載入檔案,以 config defines no [[node]] entries 拒絕沒有節點的設定,這條錯誤不帶節點前綴。它記錄共享 WireGuard 警告,然後依次為每個節點建立其 PanelClient 並執行 check_node;兩者任一出錯,錯誤都會加上該節點 node_id 的前綴(node 1: …)。src/main.rs 成功時在 stdout 印出 Configuration OK,退出狀態為 0;否則在 stderr 印出 configuration error: <e>,退出狀態為 1。用 6.1.0 的二進位制捕獲的輸出:
configuration error: node 1: duplicate/reserved outbound tag audit#1configuration error: node 1: hysteria2 node requires cert.mode = "file"configuration error: node 1: unknown node_type "Hysterai"configuration error: node 1: obfs_password must be at least 4 bytes for salamanderconfiguration error: node 1: masquerade.status must not be 233, the Hysteria 2 authentication success status最後兩行來自 api::hysteria::local,它在入站降為 spec 之前執行,所以混淆密碼過短而 cert.mode = "none" 的節點報告的是密碼;偽裝那一行是契約的文字。在 lower_hysteria 內部,所有關於設定的判斷同樣都在讀取憑證之前執行,所以憑證檔案缺失的節點會先報告其他有問題的地方。一個 port = 0、憑證和私鑰有效、使用任一憑據種類的 Hysteria 2 節點會印出 Configuration OK。
在 helium 節點上,同一個二進位制列印:
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)configuration error: node 1: [node.hysteria] up_mbps 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)configuration error: node 1: unknown hysteria congestion "vegas" (expected "cubic", "bbr" or "reno")前兩行來自 PanelClient::new,它說出找到的第一個被拒絕的鍵;第三行來自 test_spec。一個不設任何協定鍵、congestion 未設定或為 bbr 的 helium 節點會列印 Configuration OK,而且不讀取憑證檔案,因為沒有降出入站。
配置重载会对每个新增或变更的节点运行同样的检查,[[outbound]] 或 [dns] 变化时则对每个节点都运行,而且都在触碰任何运行中的节点之前进行。拒绝会以 ERROR 级别记录为 reload: node <node>: <e>; keeping current config,其中 <node> 是 <panel_type>@<host>#<node_id>,<panel_type> 为小写,面板按类型查找节点时还会追加 /<node_type>(运行时与配置重载)。
与 3.x 的区别
Section titled “与 3.x 的区别”katana 3 自己构建监听器、用户表、计量器和路由器。在 katana 4 中,这些代码都已删除,本页涉及的各个概念现在所在的位置如下:
| katana 3.0.1 | katana 4 |
|---|---|
src/traffic.rs → AuthKey、UserTag(协议用户表交回的载荷) |
lower::Uid 和 supervisor 的 Principal,标签为十进制 uid(用户、principal 与会话) |
src/traffic.rs → determine_rate |
src/lower/mod.rs → determine_rate,在 katana 6.1.0 連同節點層級的限速一起移除之前一直沒有變化;使用者的限速現在就是他自己的,面板客戶端用 [node.api].speed_limit 覆蓋它 |
src/manager/proxy.rs → ProxyManager::refresh(构建并发布协议用户表) |
lower_users 构建一个 UserSet;supervisor 构建并替换用户表 |
src/connector.rs → Admission |
supervisor 的会话和 principal |
src/meter.rs(计量和按用户的令牌桶) |
supervisor 的 tracker 和 Pacer(流跟踪、统计与限速) |
src/router.rs → build_router(编译 [node.route]、加载 geo 数据) |
src/lower/route.rs → lower_route;supervisor 编译路由表并加载 geo 数据(plane:为每个流选路) |
src/inbound.rs、src/manager/transport.rs、src/outbound/* |
src/lower/inbound.rs、src/lower/outbound.rs;supervisor 的监听器和出站(入站与出站的 lowering) |
src/rule.rs → RuleManager::detect |
基于路由的审计,rule::audit_routes(目标审计) |
| 不变量 | 原因 | 由谁固定 |
|---|---|---|
相同的输入,加上相同的证书、私钥和 CA 字节,得到相等的 spec。用户是按 uid 排序的 BTreeMap;出站、路由和审计分组保持输入顺序。 |
如果同一输入的两次 lowering 得到不同的 spec,即使什么都没变,它也会被应用;节点管理器如何比较 spec 见节点管理器,supervisor 的相等性约定见 spec:期望状态。 | 没有 katana 测试;由类型保证。 |
| 凭据无法降为 spec 的用户被跳过,其他用户仍被降为 spec。 | “一行格式错误的数据不能拖垮其他所有人。” | users_without_a_usable_credential_are_skipped(not-a-uuid 和空 UUID 被跳过,有效用户被准入) |
| 一个 uid 在集合中只出现一次;该 uid 中凭据能降为 spec 的第一行胜出。 | BTreeMap 的 key 唯一;保留的是第一个成功降为 spec 的行。 |
a_shared_credential_admits_only_the_first_user(“a uid listed twice keeps its first row”) |
| 集合中没有两个用户出示同一凭据;面板顺序中的第一个保留它。Hysteria 2 账户名按小写比较。 | supervisor 会因一个共享凭据拒绝整个入站。 | a_shared_credential_admits_only_the_first_user(katana);two_users_may_not_present_the_same_credential 和 hysteria2_usernames_collide_case_insensitively(supervisor/tests/unit/validate.rs,即 katana 让自己的用户集避开的那条规则) |
| 跳过时写明 uid,从不写凭据。 | 凭据是机密(“写明用户,从不写值”)。 | 由构造保证:credentials 的原因都不包含输入。 |
使用者的限速是他自己的面板限速,設定了 [node.api].speed_limit 時則是它;0 表示不限速(None)。 |
面板客戶端套用覆蓋值;lower_users 按原樣使用該值。 |
a_user_is_held_to_their_speed_limit;the_local_speed_override_wins(tests/unit/api/helium.rs) |
| 面板限速会对用户的流量节流。 | 限速由 supervisor 的 pacer 执行。 | a_users_speed_limit_paces_their_traffic(tests/unit/e2e.rs) |
在 enable_device_limit 下,用户的面板设备数限制和 IP 封禁生效;没有它时两者都不生效,承载连接关闭则无论如何都生效。0 会关闭封禁或承载连接关闭。 |
设备数限制和封禁统计的是客户端地址,而只有 enable_device_limit 为这些地址担保。 |
enable_device_limit_holds_the_panels_limit_and_bans_ips、without_enable_device_limit_no_limit_holds_and_no_ip_is_banned、zero_turns_the_ip_ban_and_the_grpc_close_off |
| TCP 入站读取 PROXY protocol 头部;Hysteria 2 的 UDP 入站不读取。 | proxy_protocol 根据绑定类型设置。 |
without_enable_device_limit_no_limit_holds_and_no_ip_is_banned |
| 对还没有面板描述的节点,节点检查拒绝只设一半的真实 IP 设置,两个键一起设置时接受。 | test_spec 最先调用 inbound::real_ip。 |
the_node_check_refuses_a_half_real_ip_setting |
在任何面板给出端口之前,节点检查就拒绝中转无法使用的转交设置(相对路径的 handoff_dir、没有 handoff_dir 的 handoff_group),有效的一对则接受。 |
test_spec 第二个调用 inbound::handoff。 |
the_node_check_refuses_a_handoff_setting_the_relay_could_not_use |
| 在任何面板給出 Hysteria 2 節點之前,節點檢查就對每個節點(包括 helium 節點)拒絕未知的擁塞控制;helium 節點的檢查不降出入站。 | test_spec 第三個呼叫 inbound::congestion,helium 節點空的 node_type 走非 Hysteria 分支。 |
a_helium_nodes_check_judges_its_congestion_control |
| 降出大列表的耗时保持线性。 | 凭据归属者存放在 HashMap 中。 |
lowering_a_large_list_is_not_quadratic(200 001 个用户,20 s 内) |
| 限速变化时保留用户的会话,并在一秒内到达存活的流。 | 限速与用户如何被准入无关;MAX_WAIT = 1 s 限制了一次节流休眠的时长。 |
a_speed_limit_change_keeps_the_users_sessions(supervisor/tests/hot_swap.rs,经 set_users)、a_raised_or_removed_limit_is_felt_within_a_second(supervisor/tests/unit/track.rs) |
| 用户集变化时,没有变化的用户保留存活的连接。 | 凭据不变时 principal 被保留。 | unchanged_user_survives_user_refresh、repeated_user_refreshes_never_disturb_a_live_connection(tests/unit/e2e.rs) |
审计路由位于每个 [[node.route.rule]] 之前,每个规则 id 一个 audit#<id> blackhole,按首次出现的顺序排列。 |
被审计的域名必须在节点规则把它送到别处之前被截住。 | audit_rules_route_first_to_one_blackhole_per_rule_id |
沒有 [[outbound]] 的 tag 以 audit# 開頭。 |
審計出站名為 audit#<id>,所以設定的出站絕不能佔用它們的 tag。 |
an_audit_tag_is_reserved |
| 每种 Hysteria 2 凭据种类都降为它所指的认证模式。 | "" 和 "uuid" 是 Password,"user_pass" 是 Account。 |
hysteria_accepts_both_credential_kinds(tests/unit/lower/inbound.rs) |
| 下界大于上界的端口范围被拒绝;范围包含两端。 | 倒置的范围永远不会匹配。 | port_parser_rejects_an_inverted_range、port_ranges_are_inclusive(environment/tests/unit/routing.rs) |
| 在同一路徑上換掉的 geo 檔案會改變降出的 spec,所以下一次應用會重建路由。 | lower_route 用 RouteFile::stat 包裝每個 geo 路徑。 |
沒有 katana 測試。 |
| 存储的域名匹配条件是小写。 | 路由器只对流的域名做大小写折叠。 | domain_matching_is_case_insensitive(environment/tests/unit/routing.rs),覆盖路由器一侧 |
失败路径与取消
Section titled “失败路径与取消”node_spec、test_spec 和 lower_route 返回 io::Result;第一个错误就结束 lowering,不会返回部分 spec。
| 错误 | ErrorKind |
产生于 |
|---|---|---|
invalid cidr "<s>": <e> |
InvalidInput |
lower_route |
invalid port spec: "<s>"、invalid port spec: "<s>" has a lower bound above its upper bound |
InvalidInput |
parse_port_match,由 lower_route 调用 |
出站拒绝,例如 duplicate/reserved outbound tag <tag> |
InvalidInput;unsupported shadowsocks cipher "<name>" 为 Unsupported |
lower_outbounds;全部文本列在入站与出站的 lowering |
DNS 拒绝,例如 dns: unknown backend "<name>" (expected "system", "udp", "tls" or "https") |
InvalidInput |
Backend::from_spec,由 lower_dns 调用;全部文本列在入站与出站的 lowering |
node requests kernel-unsupported feature: <feature> |
Unsupported |
lower_inbound |
real_ip_from is set without real_ip_header、real_ip_header needs real_ip_from: the proxies trusted to set it、real_ip_header "<header>" is not a header name、real_ip_from "<entry>": <e> |
InvalidInput |
inbound::real_ip,由 test_spec 和 lower_inbound 调用(入站与出站的 lowering) |
handoff_group is set without handoff_dir、handoff_dir "<dir>" must be an absolute path、handoff_dir "<dir>" is too long: with "<name>" in it, a socket's path would pass the 107 bytes a Unix socket's path may have、handoff_group "<name>": reading /etc/group: <e>、handoff_group "<name>" is not a group in /etc/group |
InvalidInput |
inbound::handoff,由 test_spec 和 lower_inbound 调用(入站与出站的 lowering) |
入站拒絕,例如 TLS node requires cert.cert_file and cert.key_file、hysteria2 node requires cert.mode = "file"、unknown hysteria credential kind "<kind>" (expected "uuid" or "user_pass") 或 sss transform.up: <e> |
InvalidInput |
lower_inbound |
unknown hysteria congestion "<value>" (expected "cubic", "bbr" or "reno") |
InvalidInput |
inbound::congestion,來自對每個節點執行的 test_spec,以及 lower_hysteria |
证书、私钥或 ca_file 读取失败 |
来自 std::fs::read |
read_cert_key 和 lower_dns |
lower_users 从不失败;它记录日志,并略去无法降为 spec 的内容。
错误在哪里出现:
| 路径 | 记录或打印的内容 |
|---|---|
--test |
stderr 上的 configuration error: node <node_id>: <e>,退出状态 1。 |
| 配置重载 | ERROR 级别的 reload: node <node>: <e>; keeping current config。 |
| 初次啟動 | NodeManager::try_bootstrap 把 lowering 或啟動錯誤報告為 initial start failed: <e>,把本地 Hysteria 2 節點的 api::hysteria::local 拒絕報告為 node_info failed: <e>(節點管理器)。 |
| 消息 | 级别,target | 何时出现 |
|---|---|---|
skipping user <uid>: <reason> |
WARN,katana::lower |
lower_users 跳过一个用户;各种原因见遍历用户列表。 |
IPv6 sockets here take IPv6 alone (net.ipv6.bindv6only), so listen_ip 0.0.0.0 serves IPv4 only |
WARN,katana::lower::inbound |
每个进程一次,来自 inbound::dual_stack:在设置了 net.ipv6.bindv6only 的主机上,把值为 0.0.0.0 的 listen_ip 降为 spec 时(入站与出站的 lowering)。 |
audit rule <id> skipped: <e> |
WARN,katana::rule |
rule::audit_routes 略去一个审计规则 id 及其出站(目标审计)。 |
lowering 没有 await 点,也不 spawn task,所以取消无法让它停在半途。NodeManager::lower_off_runtime 在节点的锁下取得输入,释放锁,然后把 lowering 交给阻塞线程池;调用方已被丢弃的 lowering 仍会在那里运行到结束,其结果随后被丢弃。初次启动尝试期间发生关停时,该尝试会在下一个 await 点被丢弃(try_bootstrap 在一个针对关停 token 的 biased tokio::select! 中运行);已经降出但尚未启动的 spec 随之丢弃。check 是 async 的,因为准备 spec 要 await 各个 builder;test_spec 本身和 node_spec 一样没有 await 点。
| 限制 | 值 |
|---|---|
| 每个节点 spec 的入站 | 最多 1 个 |
| 每个节点 spec 的用户集 | 最多 1 个,tag 为 users |
| 负载均衡器 | 无;katana 没有负载均衡器配置 |
| DNS | 始终为 DnsSpec::Single,节点的所有出站共用一个后端 |
| 用户 key | Uid(i64),面板的数字用户 id |
| 憑據來源 | 面板使用者的 uuid 字串,在 helium 上總是小寫、帶連字元的 UUID |
| 设备数限制 | 面板用户的 device_limit,只在 enable_device_limit 下保留;0 表示不限 |
| IP 封禁默认值 | 在 enable_device_limit 下,120 s 内失败 30 次即封禁该地址(IPv6 客户端按其 /64)300 s |
| gRPC 承载连接关闭默认值 | 连续 8 条流失败 |
| Shadowsocks 2022 用户密钥 | uuid 文本的前 16(AES-128)或 32(AES-256、ChaCha20)字节;带连字符的 UUID 有 36 个字符 |
| 限速单位 | 字节每秒,u64;0 为不限速;突发量为一秒的速率;一次节流休眠从 MIN_WAIT = 1 ms 到 MAX_WAIT = 1 s,所以变化在 1 s 内生效 |
| Mbps 换算 | × 1,000,000 / 8:1 Mbps = 每秒 125,000 字节 |
| 端口规格 | 一个 u16,或由两个 u16 组成、包含两端的 lo-hi 范围 |
| katana 自己判斷的 Hysteria 2 值 | udp_idle_timeout 2 到 600 s;Salamander obfs_password 至少 4 位元組;契約允許的偽裝;[node.hysteria] 和 UniProxy 節點的由 api::hysteria 判斷,helium 的由契約判斷 |
test_spec 的 Hysteria 2 埠 |
[node.hysteria].port 為 0 時為 1(NonZeroU16::MIN) |
test_spec 的占位用户 |
uid 0,UUID 和 email 为 "placeholder" |
handoff_dir |
绝对路径,并且足够短,使它、一个 / 和节点在端口 65535 时的 socket 文件名放得进 Unix socket 的 107 字节路径:监听所有地址时为 96 字节,只监听一个地址时更少 |
| 测试 | 文件 | 固定的行为 |
|---|---|---|
a_user_is_held_to_their_speed_limit |
tests/unit/lower/spec.rs |
使用者每秒 2000 位元組的限速就是他的 UserSpec.speed_limit,0 為 None,即不限速。 |
users_without_a_usable_credential_are_skipped |
tests/unit/lower/spec.rs |
在 VMess 节点上,uid 1(not-a-uuid)和 uid 2(空)被跳过,uid 3 被准入。 |
a_shared_credential_admits_only_the_first_user |
tests/unit/lower/spec.rs |
行 5:A、2:A、3:B、5:B 准入 [3, 5],uid 5 保留 UUID A。 |
without_enable_device_limit_no_limit_holds_and_no_ip_is_banned |
tests/unit/lower/spec.rs |
面板设备数限制 3 被丢弃,ip_ban 为 None,carrier_max_failures 为 8,TCP 入站读取 PROXY 头部。 |
enable_device_limit_holds_the_panels_limit_and_bans_ips |
tests/unit/lower/spec.rs |
设备数限制 3 被保留,ip_ban 为 120 s 内失败 30 次即封禁 300 s,面板限制 0 为 None。 |
zero_turns_the_ip_ban_and_the_grpc_close_off |
tests/unit/lower/spec.rs |
ban_max_failures = 0 和 carrier_max_failures = 0 使两者都为 None。 |
lowering_a_large_list_is_not_quadratic |
tests/unit/lower/spec.rs |
200 000 个各不相同的用户,加上一个与第一个用户共用 UUID 的用户,在 20 s 内降为 spec,最后一个被跳过。 |
the_node_check_refuses_a_half_real_ip_setting |
tests/unit/lower/spec.rs |
只设置 real_ip_header 时 test_spec 失败,加上 real_ip_from = ["127.0.0.1/32"] 后成功。 |
the_node_check_refuses_a_handoff_setting_the_relay_could_not_use |
tests/unit/lower/spec.rs |
handoff_dir = "run/katana/handoff" 时,以及只设置 handoff_group = "root" 时,test_spec 失败;设置 /run/katana/handoff 和组 root 时成功。 |
a_helium_nodes_check_judges_its_congestion_control |
tests/unit/lower/spec.rs |
在不寫 node_type 的 helium 節點上,test_spec 不降出入站,接受 congestion = "bbr",並以 unknown hysteria congestion 拒絕 "vegas"。 |
the_nodes_hysteria_udp_and_masquerade_reach_the_spec |
tests/unit/lower/spec.rs |
給出 90 秒閒置逾時和 502 偽裝的 Hysteria 2 節點,兩者都降進 spec;給出不中繼 UDP、沒有偽裝的節點,無論 [node.hysteria] 怎麼寫,兩者都沒有;由 api::hysteria::uniproxy 建立的節點兩者都來自 [node.hysteria](60 秒,狀態碼 403)。 |
audit_rules_route_first_to_one_blackhole_per_rule_id |
tests/unit/lower/spec.rs |
路由出站为 audit#7、audit#9、block;第一条规则是一个 DomainRegex;两个审计出站都是 Blackhole。 |
an_audit_tag_is_reserved |
tests/unit/lower/spec.rs |
tag 为 audit#1 的 [[outbound]] 使 node_spec 失败,错误中含 reserved。 |
acme_cert_mode_rejected、reject_unknown_sni_is_refused_rather_than_ignored、tls_without_cert_file_errors |
tests/unit/lower/inbound.rs |
lowering 對節點仍然拒絕的是這臺主機的設定:ACME 憑證模式、reject_unknown_sni、沒有憑證檔案的 TLS 節點。面板提出而 katana 無法提供的內容在 tests/unit/api/newv2board.rs 中被拒絕(面板客戶端)。 |
anytls_socks_and_http_users_are_their_uuid、sss_users_are_their_uuid |
tests/unit/lower/inbound.rs |
AnyTLS 用户以 UUID 作为密码,SOCKS 和 HTTP 用户以 UUID 作为账号名和密码,sss 用户以 UUID 作为凭据。 |
the_new_node_kinds_pass_the_supervisors_validation |
tests/unit/lower/spec.rs |
帶 Vision 的 REALITY 節點、AnyTLS、SOCKS 和 HTTP 節點、TLS 上 WebSocket 的舊式 Shadowsocks 節點和 sss 節點、一個 Shadowsocks 2022 節點,以及按 helium 的描述構成的 Hysteria 2 節點,各自帶一個使用者經 node_spec 降出 spec,supervisor 的 validate 都接受。 |
ss2022_builds |
tests/unit/lower/inbound.rs |
在 2022-blake3-aes-128-gcm 上,credentials 给出的 Shadowsocks 2022 用户密钥是 UUID 文本的前 16 字节。 |
hysteria_accepts_both_credential_kinds、hysteria_refuses_an_unknown_credential_kind |
tests/unit/lower/inbound.rs |
"" 和 "uuid" 降为 Hysteria2UserAuth::Password,"user_pass" 降为 Account,未知种类以 unknown hysteria credential kind 被拒绝。 |
a_users_speed_limit_paces_their_traffic |
tests/unit/e2e.rs |
面板 speed_limit 为 8(每秒 1,000,000 字节)时,3 MB 回显流量至少耗时 1.5 s。 |
unchanged_user_survives_user_refresh |
tests/unit/e2e.rs |
添加第二个用户后,第一个用户的 VMess 连接仍在同一个 socket 上中继。 |
repeated_user_refreshes_never_disturb_a_live_connection |
tests/unit/e2e.rs |
用户集切换六次后,一条 Hysteria 2 QUIC 连接仍然存活并在中继。 |
a_speed_limit_change_keeps_the_users_sessions |
supervisor/tests/hot_swap.rs |
supervisor 一侧:通过 Supervisor::set_users 设置的新 speed_limit 保留会话 id。 |
a_raised_or_removed_limit_is_felt_within_a_second |
supervisor/tests/unit/track.rs |
supervisor 一侧:MAX_WAIT 限制了限速变化最迟多久生效。 |
two_users_may_not_present_the_same_credential、hysteria2_usernames_collide_case_insensitively |
supervisor/tests/unit/validate.rs |
lower_users 让自己的用户集避开的那条 supervisor 规则。 |
port_parser_rejects_an_inverted_range、port_ranges_are_inclusive、any_matcher_within_a_rule_matches、domain_matching_is_case_insensitive |
environment/tests/unit/routing.rs |
lower_route 所依赖的端口解析器和匹配规则。 |
lower_route 透過 audit_rules_route_first_to_one_blackhole_per_rule_id 得到覆蓋,該測試會把一個帶一條 domain_suffix 規則的 [node.route] 降為 spec,沒有 katana 測試固定 geo 檔案的戳記;test_spec 有三個 katana 單元測試 the_node_check_refuses_a_half_real_ip_setting、the_node_check_refuses_a_handoff_setting_the_relay_could_not_use 和 a_helium_nodes_check_judges_its_congestion_control,覆蓋它的真實 IP、轉交和擁塞控制檢查以及 helium 分支;沒有 katana 測試固定 credentials 填寫的正是 Hysteria 2 憑據種類所指的欄位。用 --test 檢查設定檔會走到 lower_route 和 test_spec,本頁的文字就是這樣用 6.1.0 的二進位制捕獲的。如何執行測試套件見測試。