Files
ykxmz/_build/fix_selfcheck_report.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

131 lines
4.9 KiB
Python

# -*- coding: utf-8 -*-
"""补上 _selfcheck_report 定义,并让它 return 结论。
上一版补丁有顺序 bug:先把调用插进去了,导致后面"函数还没定义"的判断
失效,函数体没插进去 —— 运行时会 NameError。
另外回调必须 **return** 结论,DiscoveryResponder 才会把它随 ACK 回传给手表。
"""
from __future__ import annotations
import sys
from pathlib import Path
SERVER = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\windows"
r"\lanremote\server.py")
HELPER = ''' def _selfcheck_report(self, from_ip: str) -> str:
"""生成一段给手表看的诊断结论(不弹任何窗口)。
用户要的是「电脑上什么都不出现」,所以结论直接回传给手表显示。
"""
try:
from .diagnostics import collect, verdict
data = collect(self, self.store)
_level, text = verdict(data)
ips = data.get("ips") or []
port = self.port
blocked = (data.get("firewall") or {}).get("blocked_count", 0)
lines = [
f"电脑:{data.get('name') or '被控端'}",
f"本机地址:{', '.join(ips[:2]) if ips else '读不到'}",
f"监听端口:{port}",
f"收到过的连接:{data.get('tcp_connections', 0)} 次",
f"阻止规则:{blocked} 条",
"",
f"结论:{text}",
]
return "\\n".join(lines)
except Exception as exc: # noqa: BLE001
return f"电脑端诊断失败:{exc}"
'''
def main() -> int:
text = SERVER.read_text(encoding="utf-8")
if "_selfcheck_report(self" in text:
print(" 已经定义过了")
else:
anchor = " def _on_selfcheck_request(self, from_ip: str) -> None:"
if anchor not in text:
print(" [失败] 找不到 _on_selfcheck_request")
return 1
text = text.replace(anchor, HELPER + anchor, 1)
print(" server / _selfcheck_report 定义: OK")
# 让回调把结论 return 出去,并且不再往界面上弹窗口
old = ''' def _on_selfcheck_request(self, from_ip: str) -> None:
"""手表说「我连不上」,就在电脑上把网络自检打开。
走 UDP 是有意的:连不上的典型原因就是 TCP 被防火墙拦了,
而 UDP 广播往往还通(那正是"能搜到但连不上"的原因)。
"""'''
new = ''' def _on_selfcheck_request(self, from_ip: str) -> str:
"""手表说「我连不上」→ 生成诊断结论,随 ACK 回给手表。
走 UDP 是有意的:连不上的典型原因就是 TCP 被防火墙拦了,
而 UDP 广播往往还通(那正是"能搜到但连不上"的原因)。
注意:**不往电脑上弹窗口**。结论直接回传给手表,
用户看的就是手表,电脑上保持干净。
"""
return self._selfcheck_report(from_ip)
def _open_selfcheck_window(self, from_ip: str) -> None:
"""有窗口的模式下才用得上(静默模式不会走到这里)。"""'''
if old in text:
text = text.replace(old, new, 1)
print(" server / 回调改成 return 结论: OK")
# 删掉原来那两段弹窗口的逻辑(现在不需要了)
old_launch = ''' self._log(f"[自检] 收到来自 {from_ip} 的请求,正在生成诊断结论")
note = self._selfcheck_report(from_ip)
def launch() -> None:
'''
new_launch = ''' self._log(f"[自检] 收到来自 {from_ip} 的请求,已生成诊断结论")
def launch() -> None:
'''
if old_launch in text:
text = text.replace(old_launch, new_launch, 1)
print(" server / 去掉重复的结论生成: OK")
# _open_selfcheck_window 需要 from_ip 参数在 launch 里可见
old_sig = ''' def launch() -> None:
import os
import subprocess
target = getattr(self, "ui", None)'''
new_sig = ''' def launch() -> None:
target = getattr(self, "ui", None)'''
if old_sig in text:
text = text.replace(old_sig, new_sig, 1)
print(" server / 清理无用的 import: OK")
SERVER.write_text(text, encoding="utf-8")
import ast
try:
ast.parse(SERVER.read_text(encoding="utf-8"))
print(" server.py: 语法 OK")
except SyntaxError as exc:
print(f" server.py: 语法错误 {exc}")
return 1
# 打印改后的样子确认
print()
lines = SERVER.read_text(encoding="utf-8").splitlines()
for i, line in enumerate(lines):
if "_on_selfcheck_request" in line and "def " in line:
for j in range(i, min(len(lines), i + 30)):
print(f" {j + 1}: {lines[j]}")
break
return 0
if __name__ == "__main__":
sys.exit(main())