diag(client): _onStats/setLivePing 打点,定位延迟为何不回写 node.ping

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-30 17:26:56 +08:00
parent dbe657f997
commit d14f7a0ec5
2 changed files with 19 additions and 3 deletions
+6 -1
View File
@@ -248,12 +248,17 @@ class ConnectionController extends StateNotifier<ConnectionState> {
// 自动连接/重连到已在跑的隧道时不会走 _connect → _connectedNode 为 null;回退到
// effectiveNode(当前/智能所选),否则 urltest 实测无处回写、连接页延迟一直显示 —。
final Node node = _connectedNode ?? _ref.read(effectiveNodeProvider);
final ds = e.urltestResults.where((r) => r.delayMs > 0).map((r) => r.delayMs).toList();
logLine('Stats',
'urltest=[${e.urltestResults.map((r) => "${r.tag}:${r.delayMs}").join(",")}] '
'conn=${_connectedNode == null ? "null" : _connectedNode!.code} '
'eff=${node.code}/${node.uuid.isEmpty ? "EMPTY" : "ok"} ds=$ds');
if (node.uuid.isEmpty) return;
final ds = e.urltestResults.where((r) => r.delayMs > 0).map((r) => r.delayMs);
if (ds.isEmpty) return;
// urltest 成功:经 proxy 出站(REALITY 到节点)真实可达 → 记录时刻(供路径 A 判活)+ 回写延迟。
_lastUrltestOk = DateTime.now();
final best = ds.reduce((a, b) => a < b ? a : b);
logLine('Stats', 'setLivePing node=${node.code} = ${best}ms');
_ref.read(nodesProvider.notifier).setLivePing(node.uuid, best);
}
+13 -2
View File
@@ -14,6 +14,7 @@ import '../services/api_config.dart';
import '../services/latency_probe.dart';
import 'auth_provider.dart';
import 'connection_provider.dart';
import '../bridge/log.dart';
// ── 节点列表 AsyncNotifier ────────────────────────────────────────
@@ -86,14 +87,24 @@ class NodesNotifier extends AsyncNotifier<List<Node>> {
/// 回写某节点的实测延迟(ms)。连接态由 ConnectionController 用内核 urltest 回填连接节点,
/// 让「连接页延迟」与「节点列表延迟」同源(都读 node.ping)、显示一致。ms<=0 忽略。
void setLivePing(String uuid, int ms) {
if (ms <= 0 || _disposed) return;
if (ms <= 0 || _disposed) {
logLine('Ping', 'setLivePing SKIP ms=$ms disposed=$_disposed');
return;
}
final list = state.valueOrNull;
if (list == null) return;
if (list == null) {
logLine('Ping', 'setLivePing no-list');
return;
}
var changed = false;
final updated = [
for (final n in list)
if (n.uuid == uuid && n.ping != ms) (() { changed = true; return n.copyWith(ping: ms); })() else n
];
final match = list.any((n) => n.uuid == uuid);
logLine('Ping',
'setLivePing ms=$ms match=$match changed=$changed '
'nodes=[${list.map((n) => "${n.code}:${n.ping}").join(",")}]');
if (changed) state = AsyncData(updated);
}