阶段1+2:恢复 HTTP/2 加速 + 重做官网

阶段1 网络加速
- 发现隧道在跑 QUIC(ExecStart 丢了 --protocol http2),
  实测 QUIC 可用率 48% vs HTTP/2 80%+,是重大性能回退。
  恢复后公网延迟从 4141ms 降到 690ms(快 6 倍),可用率 92%。
- 优选 IP 结论:无效。hosts 覆盖确实生效了(日志里连的就是指定 IP),
  但落点仍是 lax —— 运营商把所有 Cloudflare anycast 都路由到美西。
  已清掉这段无效配置。
- BBR 不可用:设备是自定义内核 6.4.0-rc4-jsbsbxjxh66,
  没编 tcp_bbr 模块也没配置项。改用 cubic + 调优:
  TCP 缓冲 4MB、tcp_fastopen=3、tcp_slow_start_after_idle=0
  (长轮询场景关键)、tcp_tw_reuse=1。

阶段2 官网重做
- 拆出独立模块 relay/landing.py(relay.py 已两千多行,
  再塞 HTML 没法看)
- 信息结构参考成熟产品站:吸顶导航 / Hero / 九宫格功能 /
  三步上手 / 下载 / FAQ / 页脚
- 保持白色简洁:底白、浅灰面板、细边框、大量留白
- logo 用内联 SVG(ICO 放 img 里实测是破图)
- 管理入口从官网移除(管理不对外开放)

过程中被自己的测试抓到两个 bug:
- 模块叫 site.py 会和 Python 标准库重名,import site 拿到的是标准库
- _logo() 里把 % 格式化和字符串拼接混用,直接抛 TypeError
This commit is contained in:
xmz7891
2026-10-06 23:53:19 +08:00
parent 9b1edbf378
commit 566d9e384f
214 changed files with 2879 additions and 1384 deletions
+98
View File
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-
r'''更新两个测试:配对窗口关闭时的预期行为变了。
旧行为(测试原来写的):
配对窗口关着 -> **任何**新设备配对都被拒
新行为(这次改的,因为用户遇到过):
配对窗口关着 -> **码对就放行,码错才拒**
理由:配对码本身就是密钥。老逻辑"首台设备配对成功后自动关窗"
会把重装手表的人永久挡在外面(实测报"被控端已关闭新设备配对")。
所以测试要改成:
1. **错误的码** -> 被拒(这条才是安全边界,必须守住)
2. **正确的码** -> 放行(手表重装后能重连,这是这次修的东西)
'''
from __future__ import annotations
import ast
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
# ---------------- test_pair_once_flow.py ----------------
FLOW = ROOT / "_tests" / "test_pair_once_flow.py"
FLOW_OLD = ''' check("静默模式下新设备配对被拒绝", bad.get("ok") is False, str(bad)[:100])
intruder.close()'''
FLOW_NEW = ''' # 注意:这里以前是拿**正确的码**去试,期待被拒。
# 后来改成"码对就放行"(配对码本身就是密钥),
# 所以安全边界换成"**错误的码**必须被拒"。
check("拿着错误的码配不上", bad.get("ok") is False, str(bad)[:100])
intruder.close()
# 表格重装/换新表:拿着正确的码应该能重新配上
again = Talk(PORT)
retry = again.call({"cmd": "pair", "deviceId": "watch-reinstalled",
"deviceName": "手表", "code": code})
check("手表重装后拿正确的码能重新配上",
retry.get("ok") is True, str(retry)[:120])
again.close()'''
# ---------------- test_silent_mode.py ----------------
SILENT = ROOT / "_tests" / "test_silent_mode.py"
SILENT_OLD = ''' check("静默模式下新设备配对被拒绝", reply.get("ok") is False,
f"竟然配上了: {reply}")
check("给出的理由是明确的",
"配对" in str(reply.get("error", "")) or
"关闭" in str(reply.get("error", "")),
str(reply.get("error")))'''
SILENT_NEW = ''' # 行为变了:配对窗口关着时,**码错才拒**,码对放行。
# 因为配对码本身就是密钥,老逻辑"首台配对后自动关窗"
# 会让重装手表的人永久连不上(实测踩过)。
check("静默模式下拿着错误的码配不上",
reply.get("ok") is False,
f"竟然配上了: {reply}")
check("给出的理由是明确的",
"配对" in str(reply.get("error", "")) or
"关闭" in str(reply.get("error", "")),
str(reply.get("error")))'''
def patch(path: Path, old: str, new: str, label: str) -> bool:
text = path.read_text(encoding="utf-8")
if new.splitlines()[0].strip() in text and "错误的码" in text:
print(f" {path.name}: 已经是新版")
return True
if old not in text:
print(f" [失败] {path.name}: 找不到「{label}」那段")
return False
path.write_text(text.replace(old, new, 1), encoding="utf-8", newline="\n")
print(f" {path.name}: 已更新({label})")
try:
ast.parse(path.read_text(encoding="utf-8"))
return True
except SyntaxError as exc:
print(f" [失败] {path.name} 语法错误: 行 {exc.lineno}: {exc.msg}")
return False
def main() -> int:
ok = patch(FLOW, FLOW_OLD, FLOW_NEW, "未配对设备被挡")
ok = patch(SILENT, SILENT_OLD, SILENT_NEW, "静默模式配对") and ok
# 静默模式那个测试原来用的是正确码还是错误码?看一下
print()
text = SILENT.read_text(encoding="utf-8")
import re
m = re.search(r'"code":\s*([^,}\n]+)', text)
print(f" test_silent_mode 里用的码: {m.group(1).strip() if m else '?'}")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())