Files
ykxmz/_build/fix_selfcheck_report.py
T
xmz7891 b705216e4a ykxmz 1.5.0锛氫慨澶嶆墜琛ㄧ TLS 璇佷功鏍¢獙 + MTU 淇缃戠粶绋冲畾鎬?
琚帶绔?- 淇 MTU 闂锛氬す MSS + 璺緞 MTU 鎺㈡祴锛堝叕缃戝彲鐢ㄧ巼 48% -> 100%锛?- 澶嶇敤 HTTP 杩炴帴锛堝厤鎺夋瘡娆℃柊寤?TLS 鐨?30% 鎻℃墜澶辫触锛?- 姣忓垎閽熷洖澶存壘灞€鍩熺綉锛岃嚜鍔ㄥ垏鍥炲揩 400 鍊嶇殑璺緞
- 鐢婚潰蹇冭烦甯э細闈欐鏃剁渷娴侀噺锛屽鎴风浠嶇煡閬撴祦鏄椿鐨?- 閿佸睆鏃剁粰鍑哄彲鎿嶄綔鐨勬彁绀?
鎵嬭〃绔?- 鍐呯疆 GTS Root R4 / GlobalSign Root CA锛屼慨 SSLHandshakeException
- 杩炴帴閿欒缈昏瘧鎴愪汉璇濓紙璇佷功/鏃堕棿/瑙f瀽/瓒呮椂鍒嗗埆鎻愮ず锛?- 缁忎腑杞繛涓婂悗鐢ㄦ湇鍔″櫒鎶ョ殑鍦板潃鍒锋柊宸查厤瀵硅褰?- 鏂板灞€鍩熺綉杩炴帴椤甸潰銆佹湇鍔″櫒寤惰繜妫€娴?
鏈嶅姟鍣ㄧ
- 鏀寔 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())