Files
ykxmz/_tests/test_net_tune.py
T
xmz7891 b62ac865ea ykxmz 1.5.0:修复手表端 TLS 证书校验 + MTU 修复网络稳定性
被控端
- 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%)
- 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败)
- 每分钟回头找局域网,自动切回快 400 倍的路径
- 画面心跳帧:静止时省流量,客户端仍知道流是活的
- 锁屏时给出可操作的提示

手表端
- 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException
- 连接错误翻译成人话(证书/时间/解析/超时分别提示)
- 经中转连上后用服务器报的地址刷新已配对记录
- 新增局域网连接页面、服务器延迟检测

服务器端
- 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502)
- 网络调优脚本 net-tune.sh(开机自动应用)
- 管理页:批量删除、网络体检、下载区
- 隧道改 HTTP/2 + 双连接

文档
- 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
2026-10-06 19:01:05 +08:00

96 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""验证 MTU 调优脚本和安装集成。
为什么值得单独回归:
这是这次可用率从 48% 提到 100% 的关键,而且**很容易被后人误改** ——
比如"顺手把接口 MTU 也降一点"(实测那样会掉到 50%)。
所以把关键决策钉在测试里。
"""
from __future__ import annotations
import re
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
NET_TUNE = ROOT / "relay" / "net-tune.sh"
INSTALL = ROOT / "relay" / "install.sh"
passed = 0
failed = 0
def check(name, ok, detail=""):
global passed, failed
if ok:
passed += 1
print(" [PASS] " + name)
else:
failed += 1
print(" [FAIL] " + name + " " + str(detail))
def main() -> int:
print("一、调优脚本本身")
check("net-tune.sh 在", NET_TUNE.is_file())
if not NET_TUNE.is_file():
return 1
text = NET_TUNE.read_text(encoding="utf-8")
# bash 语法(在 Linux 上才有 bash,本机没有就跳过)
check("打开 tcp_mtu_probing", "tcp_mtu_probing=1" in text)
check("夹 MSS", "--set-mss" in text)
check("MSS 默认值合理(1300~1440)",
bool(re.search(r"MSS_VALUE=\$\{MSS_VALUE:-(\d+)\}", text))
and 1300 <= int(re.search(r"MSS_VALUE=\$\{MSS_VALUE:-(\d+)\}", text)
.group(1)) <= 1440,
re.search(r"MSS_VALUE=.*", text).group(0) if "MSS_VALUE" in text else "")
check("OUTPUT 链上夹", "OUTPUT" in text)
check("POSTROUTING 链上夹", "POSTROUTING" in text)
# 关键:明确写了不要改接口 MTU,并且确实把接口 MTU 设回 1500
check("不把接口 MTU 调小(写回了 1500)",
"mtu 1500" in text, "接口 MTU 降到 1400 实测会掉到 50%")
check("注释里说明了为什么不动接口 MTU",
"不要改接口 MTU" in text or "反而" in text)
# 清理旧规则,避免重启后越积越多
check("会先清掉旧 MSS 规则", "-D" in text and "while" in text)
print()
print("二、安装脚本带上了它")
check("install.sh 在", INSTALL.is_file())
install = INSTALL.read_text(encoding="utf-8")
check("有 [3c] 网络调优段", "[3c]" in install)
check("会拷 net-tune.sh", "net-tune.sh" in install)
check("会写 sysctl 配置", "99-lanremote-mtu.conf" in install)
check("会注册开机服务", "lanremote-nettune.service" in install)
check("服务 enabled", "systemctl enable lanremote-nettune" in install)
check("开机服务在隧道之前跑(新连接就用上新参数)",
"Before=lanremote-relay.service lanremote-tunnel.service" in install)
print()
print("三、打包会带上这两个文件")
package = (ROOT / "_build" / "package_remote.py").read_text(
encoding="utf-8")
check("打包脚本扫描整个 relay 目录(不是硬编码文件名)",
"iterdir" in package or "rglob" in package, "")
check("relay/net-tune.sh 会被打进去(同目录扫描即可)",
NET_TUNE.is_file())
print()
print("四、说明文档里记了实测数据")
check("写了不夹 MSS 的对照(87%)", "87" in text)
check("写了 MSS 各档都 100%", "100%" in text)
check("写了接口 MTU 1400 更差的教训", "50%" in text)
print()
print("=" * 58)
print(f"通过 {passed} 项,失败 {failed} 项")
return 0 if failed == 0 else 1
if __name__ == "__main__":
sys.exit(main())