mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 21:50:44 +00:00
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 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""让手表的连接错误提示说人话(尤其是证书问题)。
|
||||
|
||||
现在:
|
||||
describeNetworkError(IOException) 只认 ETIMEDOUT / ECONNREFUSED /
|
||||
ENETUNREACH 三种,其它原样把英文类名吐出来 ——
|
||||
用户看到 "SSLHandshakeException: Chain validation failed" 完全不知道
|
||||
该干嘛。
|
||||
|
||||
改后:
|
||||
先交给 TlsCompat.explain()(它认得证书/时间/解析/超时等常见情况),
|
||||
再补上"确认被控端在跑""确认同一个 WiFi"这些本场景专属的提示。
|
||||
参数从 IOException 放宽到 Throwable —— 中转那边的异常可能是包过的。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
MAIN = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\android\src"
|
||||
r"\com\lanremote\watch\MainActivity.java")
|
||||
|
||||
OLD = ''' private String describeNetworkError(IOException e, String host) {
|
||||
String message = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
|
||||
if (message.contains("ETIMEDOUT") || message.contains("timed out")) {
|
||||
return "连接超时,检查电脑防火墙或 IP 是否正确";
|
||||
}
|
||||
if (message.contains("ECONNREFUSED") || message.contains("refused")) {
|
||||
return "电脑拒绝连接,确认被控端程序正在运行";
|
||||
}
|
||||
if (message.contains("ENETUNREACH") || message.contains("Network is unreachable")) {
|
||||
return "网络不可达,确认手表和电脑在同一个 WiFi";
|
||||
}
|
||||
return message;
|
||||
}'''
|
||||
|
||||
NEW = ''' /**
|
||||
* 把连接异常翻译成用户能看懂的话。
|
||||
*
|
||||
* <p>手表上原本只会显示一长串英文类名(比如
|
||||
* {@code SSLHandshakeException: Chain validation failed}),
|
||||
* 用户完全不知道该怎么办。这里按常见情况给出可操作的提示。
|
||||
*
|
||||
* <p>证书类问题交给 {@link TlsCompat#explain} 判断 ——
|
||||
* 它会区分"证书链不认识""手表时间不对""被劫持"几种情况。
|
||||
*/
|
||||
private String describeNetworkError(Throwable e, String host) {
|
||||
String raw = e == null ? ""
|
||||
: String.valueOf(e.getMessage() == null
|
||||
? e.getClass().getSimpleName() : e.getMessage());
|
||||
String lower = raw.toLowerCase();
|
||||
|
||||
// 证书 / 时间 / 解析 / 超时 等通用情况
|
||||
String friendly = TlsCompat.explain(e);
|
||||
boolean generic = friendly != null && !friendly.equals(raw)
|
||||
&& friendly.length() > 0;
|
||||
// TlsCompat 认不出来时会原样返回,那就继续往下走本场景的判断
|
||||
boolean recognized = generic && (
|
||||
friendly.contains("证书") || friendly.contains("时间")
|
||||
|| friendly.contains("超时") || friendly.contains("解析")
|
||||
|| friendly.contains("拒绝") || friendly.contains("联网")
|
||||
|| friendly.contains("中断"));
|
||||
if (recognized) {
|
||||
return friendly;
|
||||
}
|
||||
|
||||
if (lower.contains("etimedout") || lower.contains("timed out")
|
||||
|| lower.contains("timeout")) {
|
||||
return "连接超时(网络慢或被防火墙挡了)";
|
||||
}
|
||||
if (lower.contains("econnrefused") || lower.contains("refused")) {
|
||||
return "电脑拒绝连接 —— 确认电脑上 ykxmz 正在运行";
|
||||
}
|
||||
if (lower.contains("enetunreach")
|
||||
|| lower.contains("network is unreachable")) {
|
||||
return "网络不可达 —— 确认手表和电脑在同一个 WiFi";
|
||||
}
|
||||
if (lower.contains("ehostunreach") || lower.contains("no route")) {
|
||||
return "找不到电脑 —— 检查 IP,或先用「局域网连接」搜一下";
|
||||
}
|
||||
if (lower.contains("unable to resolve host")
|
||||
|| lower.contains("unknownhost")) {
|
||||
return "域名解析不了 —— 检查手表能不能上网";
|
||||
}
|
||||
// 中转那边的错误信息一般是中文的,直接透传
|
||||
if (raw.length() > 120) {
|
||||
return raw.substring(0, 120);
|
||||
}
|
||||
return raw;
|
||||
}'''
|
||||
|
||||
|
||||
def main() -> int:
|
||||
text = MAIN.read_text(encoding="utf-8")
|
||||
if "TlsCompat.explain" in text:
|
||||
print(" 已经改过")
|
||||
return 0
|
||||
if OLD not in text:
|
||||
print(" [失败] 锚点没找到")
|
||||
return 1
|
||||
|
||||
text = text.replace(OLD, NEW, 1)
|
||||
|
||||
# 把 catch 放宽到 Exception,别漏掉包过的异常
|
||||
old_catch = ''' } catch (final IOException e) {
|
||||
error = describeNetworkError(e, host);
|
||||
}'''
|
||||
new_catch = ''' } catch (final Exception e) {
|
||||
// 放宽到 Exception:中转那边的异常可能是包过的,
|
||||
// 只 catch IOException 会漏掉(甚至闪退)。
|
||||
error = describeNetworkError(e, host);
|
||||
}'''
|
||||
if old_catch in text:
|
||||
text = text.replace(old_catch, new_catch, 1)
|
||||
print(" catch 从 IOException 放宽到 Exception")
|
||||
else:
|
||||
print(" [提示] catch 锚点没找到(可能已经在别处)")
|
||||
|
||||
MAIN.write_text(text, encoding="utf-8", newline="\n")
|
||||
print(" describeNetworkError 已接上 TlsCompat.explain")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user