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

159 lines
6.0 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 -*-
"""把联调跑一遍并把被控端日志打出来,定位"第二次会话"的问题。
被控端的日志写在 windows/data/silent.log(静默模式的日志文件)。
中转这边的日志也一起打。
"""
from __future__ import annotations
import os
import shutil
import subprocess
import sys
import tempfile
import time
import urllib.request
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
WINDOWS = ROOT / "windows"
TOOLCHAIN = Path(r"C:\Users\shu\Desktop\deepseekagent\starklink\toolchain")
JAVAC = TOOLCHAIN / "jdk17" / "bin" / "javac.exe"
RELAY_PORT = 8092
AGENT_PORT = 8897
RELAY_URL = f"http://127.0.0.1:{RELAY_PORT}"
PAIR_CODE = "135791"
def main() -> int:
real_data = WINDOWS / "data"
backup = WINDOWS / "data_bk_dbg"
if backup.exists():
shutil.rmtree(backup, ignore_errors=True)
had_data = real_data.exists()
if had_data:
shutil.move(str(real_data), str(backup))
work = Path(tempfile.mkdtemp(prefix="dbgrelay_"))
relay_proc = agent_proc = None
try:
real_data.mkdir(parents=True, exist_ok=True)
sys.path.insert(0, str(WINDOWS))
from lanremote.config import Store
store = Store(real_data)
store.set_pairing_code(PAIR_CODE)
store.set("setup_done", True)
store.set("allow_new_pairing", True)
store.set("close_pair_after_first", False)
store.set("server_name", "调试电脑")
store.set("relay_url", RELAY_URL)
store.set("port", AGENT_PORT)
env = dict(os.environ)
env.update({
"RELAY_PORT": str(RELAY_PORT), "RELAY_BIND": "127.0.0.1",
"RELAY_DATA": str(work / "relaydata"), "RELAY_POLL": "8",
"PYTHONIOENCODING": "utf-8", "PYTHONUNBUFFERED": "1",
})
(work / "relaydata").mkdir(parents=True, exist_ok=True)
relay_proc = subprocess.Popen(
[sys.executable, "-u", str(ROOT / "relay" / "relay.py")],
env=env, stdout=open(work / "relay.log", "wb"),
stderr=subprocess.STDOUT)
for _ in range(40):
time.sleep(0.5)
try:
with urllib.request.urlopen(RELAY_URL + "/v1/health",
timeout=2) as r:
if r.status == 200:
break
except Exception: # noqa: BLE001
continue
agent_proc = subprocess.Popen(
[sys.executable, "-u", str(WINDOWS / "run_agent.py"),
"--silent", "--port", str(AGENT_PORT)],
cwd=str(WINDOWS), stdout=open(work / "agent.out", "wb"),
stderr=subprocess.STDOUT)
for _ in range(60):
time.sleep(1.0)
try:
with urllib.request.urlopen(RELAY_URL + "/v1/health",
timeout=3) as r:
import json
if any(d.get("online") for d in
json.loads(r.read()).get("devices", [])):
break
except Exception: # noqa: BLE001
continue
print("被控端已在线,开始跑 Java 客户端…\n")
classes = work / "classes"
classes.mkdir(parents=True, exist_ok=True)
sources = [ROOT / "android" / "src" / "com" / "lanremote" / "watch" / n
for n in ("Json.java", "B64.java", "Transport.java",
"RelayTransport.java", "RemoteClient.java",
"DiscoveryCore.java")]
sources.append(ROOT / "_tests" / "java" / "JavaRelayTest.java")
compile_result = subprocess.run(
[str(JAVAC), "--release", "8", "-encoding", "UTF-8",
"-d", str(classes)] + [str(s) for s in sources],
capture_output=True, text=True, encoding="utf-8", errors="replace")
if compile_result.returncode != 0:
print(compile_result.stderr[:1500])
return 1
result = subprocess.run(
[str(TOOLCHAIN / "jdk17" / "bin" / "java.exe"),
"-Dfile.encoding=UTF-8", "-cp", str(classes),
"JavaRelayTest", RELAY_URL, PAIR_CODE],
capture_output=True, text=True, encoding="utf-8", errors="replace")
print("---- Java stdout ----")
print(result.stdout[-2500:])
print("---- Java stderr(含 [dbg] 打点)----")
print(result.stderr[-4000:])
print()
print("=" * 70)
print("被控端日志(silent.log)")
print("=" * 70)
silent = real_data / "silent.log"
if silent.is_file():
text = silent.read_text(encoding="utf-8", errors="replace")
print(text[-3000:])
else:
print(" (没有 silent.log)")
print()
print("=" * 70)
print("中转日志(relay.log)")
print("=" * 70)
relay_log = work / "relaydata" / "relay.log"
if relay_log.is_file():
print(relay_log.read_text(encoding="utf-8",
errors="replace")[-2000:])
return 0
finally:
for process in (agent_proc, relay_proc):
if process is not None:
try:
process.terminate()
process.wait(timeout=8)
except Exception: # noqa: BLE001
try:
process.kill()
except Exception: # noqa: BLE001
pass
time.sleep(1)
if real_data.exists():
shutil.rmtree(real_data, ignore_errors=True)
if had_data and backup.exists():
shutil.move(str(backup), str(real_data))
shutil.rmtree(work, ignore_errors=True)
if __name__ == "__main__":
sys.exit(main())