mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 20:40:43 +00:00
版本号 1.7.1 -> 1.8.0(8 个文件,13 处)。
写了个 bump_180.py 统一处理 —— 版本号散落在
Python / Java manifest / PowerShell / Inno Setup / 测试里,
手动改必漏;而且 .ps1 必须保留 UTF-8 BOM。
==================== 一、隧道稳定性(用户撞上 1033/502/530)====================
1) 4G 链路会**静默断开 TCP 连接**(不发 FIN/RST,双方都以为还活着),
Linux 默认要 2 小时才发现 -> 改成 keepalive 30 秒 + 每 10 秒探测。
实测 60 秒内发现并重连。
2) 隧道连接数 2 -> 4。只剩 1 条连接时跨机房回源会失败
(实测可用率 0/12,提到 4 条后 12/12)。
3) 掉电重启后恢复慢:原来开机 2 分 10 秒公网才可用。
根因是 systemd-networkd-wait-online 等一个不归它管的网络
(wlan0 是 NetworkManager 管的),干等 2 分钟超时失败,
把 network-online.target 一起拖住。
mask 掉它之后:启动 17.3 秒,掉电重启 24 秒公网可用。
4) 看门狗两次翻车都是我造成的,都修了:
a) 我先加了"确认故障立刻重启",但隧道重建 4 条连接要 30~60 秒,
MIN_RESTART_GAP=45 导致**还没建齐就被下一次重启打断**,
死循环,每 50 秒重启一次 -> 加 150 秒宽限期
b) 宽限期又带来"链路持续差时什么都不做"的问题
-> 增加"本次重启后建齐过吗"的判断:
建齐过又垮 = 真故障,立刻重启
从没建齐 = 还在努力,继续等
5) 顺手修:看门狗状态文件里的变量在函数定义前被引用,
set -u 下报 "BUILT: 未绑定的变量"。
==================== 二、中转管理后台重做 ====================
原来的管理页是几百行内联在 relay.py 的 f-string 里,
改一处样式要在一堆转义花括号里翻。拆成独立模块 relay/admin.py。
新设计(对齐官网那套白色简洁):
吸顶顶栏 -> 公网地址(最大权重,这是用户最需要复制的)
-> 四个数字卡 -> 设备表 -> 工具卡(体检 + 下载)
空状态给图标+引导文案;窄屏表格自动变卡片。
relay.py 从 2089 行缩到 1500 行左右。
修了三个我自己引入的 bug:
a) 响应头类型写错,浏览器把整页 HTML 当纯文本显示
(用户看到的是"一屏源码")。教训:200 不等于页面能看,
当时只验了状态码和字节数。
b) 顶栏用了固定 height:62px,装不下"标题+副标题+版本信息"两行,
内容被顶出容器 -> 标题看不见、徽章压在字上。
c) do_HEAD 没处理 /download/ 路径,HEAD 一个 APK 返回
Content-Length: 0 + text/plain,下载器会误判成空文件。
同时发现 _head_info 里对 bytes 调 .encode() —— 加 _as_bytes() 兜住。
==================== 三、其它 ====================
* 设备记录只增不减:实测一天攒 75 条僵尸,/v1/health 从几 KB 涨到 20KB。
加 DEVICE_TTL(6 小时)自动清,占用的配对码一起释放
(管理页曾显示"配对码占用 131"但一台设备都没有)。
* HEAD 请求支持(原来一律 501)。
* 官网新增产品展示:手表界面预览(颜色/布局与真实手表一致)、
电脑端真实截图、两种连接方式对比图。
* 加了一份 docs/免费托管方案.md(含一个纠错:上一版推荐的
ClawCloud Run 已在 2026-05-11 关停)。
==================== 验收 ====================
全量回归 33 个阶段全部通过
安装包完整周期 20/20(静默装入 7 秒、卸载 0.6 秒、无残留)
网页响应头 12/12
公网可用率 26/30 = 86%(底层 4G 丢包 30%,是这个上限)
发布产物 安装包 14.37MB / 服务端 0.20MB / 手表 0.19MB
103 lines
3.7 KiB
Python
103 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
r'''把本地 relay 代码同步到设备并重启,然后验证。
|
||
|
||
为什么单独一个脚本:
|
||
之前用内联 python -c 配 PowerShell 的 @"..."@,
|
||
里面只要出现 $(...) / 反斜杠 / 嵌套引号就会被 PowerShell 吃掉
|
||
(这个坑今天踩了不下 10 次)。写成文件最稳。
|
||
'''
|
||
from __future__ import annotations
|
||
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
|
||
sys.path.insert(0, str(ROOT / "_build"))
|
||
|
||
from devssh import run, upload # noqa: E402
|
||
|
||
FILES = [
|
||
("relay/relay.py", "/root/lanremote-relay/relay.py", 0o755),
|
||
("relay/admin.py", "/root/lanremote-relay/admin.py", 0o644),
|
||
("relay/landing.py", "/root/lanremote-relay/landing.py", 0o644),
|
||
("relay/showcase.py", "/root/lanremote-relay/showcase.py", 0o644),
|
||
("relay/watchdog.sh", "/root/lanremote-relay/watchdog.sh", 0o755),
|
||
("relay/net-tune.sh", "/root/lanremote-relay/net-tune.sh", 0o755),
|
||
("relay/speed-up-boot.sh", "/root/lanremote-relay/speed-up-boot.sh", 0o755),
|
||
("relay/tunnel-run.sh", "/root/lanremote-relay/tunnel-run.sh", 0o755),
|
||
]
|
||
|
||
|
||
def main() -> int:
|
||
print(" 同步代码:")
|
||
for local, remote, mode in FILES:
|
||
src = ROOT / local
|
||
if not src.is_file():
|
||
print(" [跳过] %s 不存在" % local)
|
||
continue
|
||
upload(str(src), remote, mode)
|
||
print(" ✓ %-26s %d 字节" % (src.name, src.stat().st_size))
|
||
|
||
print()
|
||
print(" 重启中转:")
|
||
_c, out, _e = run("systemctl restart lanremote-relay; sleep 6; "
|
||
"systemctl is-active lanremote-relay", timeout=120)
|
||
print(" " + (out or "").strip().splitlines()[-1])
|
||
|
||
print()
|
||
print(" 验证:")
|
||
checks = [
|
||
("中转版本", "curl -s --max-time 8 http://127.0.0.1:8080/v1/health "
|
||
"| head -c 200"),
|
||
("管理页响应头", "curl -sI --max-time 10 "
|
||
"http://127.0.0.1:8080/zhongzhuanzhan "
|
||
"| grep -i '^content-type'"),
|
||
("官网响应头", "curl -sI --max-time 10 http://127.0.0.1:8080/ "
|
||
"| grep -i '^content-type'"),
|
||
("官网大小", "curl -s --max-time 10 http://127.0.0.1:8080/ | wc -c"),
|
||
("下载接口", "curl -s --max-time 10 "
|
||
"http://127.0.0.1:8080/v1/downloads"),
|
||
]
|
||
for label, cmd in checks:
|
||
_c, out, _e = run(cmd, timeout=60)
|
||
text = (out or "").strip()
|
||
if len(text) > 220:
|
||
text = text[:220] + "…"
|
||
print(" %-14s %s" % (label, text))
|
||
|
||
print()
|
||
print(" 下载链接实测(走公网):")
|
||
links = [
|
||
"/download/ykxmz-setup-1.8.0.exe",
|
||
"/download/ykxmz-server-1.8.0.zip",
|
||
"/download/ykxmz-watch-1.8.0.apk",
|
||
]
|
||
for link in links:
|
||
_c, out, _e = run(
|
||
"curl -s -o /dev/null -w '%%{http_code} %%{size_download}' "
|
||
"--max-time 60 -r 0-1023 https://relay.xxmxxs.top" + link,
|
||
timeout=120)
|
||
print(" %-34s %s" % (link, (out or "").strip()))
|
||
|
||
print()
|
||
print(" 公网首页 / 管理页:")
|
||
for path, label in (("/", "官网"), ("/zhongzhuanzhan", "管理页")):
|
||
_c, out, _e = run(
|
||
"curl -s -o /dev/null -w '%%{http_code}' --max-time 20 "
|
||
"-H 'User-Agent: LanRemote/1.8.0' https://relay.xxmxxs.top" + path,
|
||
timeout=120)
|
||
print(" %-8s HTTP %s" % (label, (out or "").strip()))
|
||
|
||
print()
|
||
print(" 中转日志最后几行:")
|
||
_c, out, _e = run("tail -6 /root/lanremote-relay/relay.log", timeout=60)
|
||
for line in (out or "").strip().splitlines():
|
||
print(" " + line)
|
||
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|