Add netquality 1.1.2 client and node behavior.

Show the address actually probed, keep address-selection misses out of formal loss, and add session metrics, a stop summary, pinned chart points, and in-app metric and release-history screens. Client version is 1.1.2+5. Attribution remains 言灸 under AGPL-3.0-only.

Co-authored-by: yanjiu0721 <yanjiu0721@users.noreply.github.com>
This commit is contained in:
Cursor Agentandyanjiu0721 committed 2026-11-19 23:20:50 +00:00
1 parent 8ca2185c01
commit aeb08ec049
40 files changed
+3827 -545

No files matched your search

+125
View File
@@ -0,0 +1,125 @@
// Copyright (C) 2026 言灸
// SPDX-License-Identifier: AGPL-3.0-only
import 'dart:io';
class ResolvedAddress {
const ResolvedAddress({required this.address, required this.family});
final String address;
final String family;
}
String addressFamily(InternetAddress address) {
return address.type == InternetAddressType.IPv6 ? 'IPv6' : 'IPv4';
}
String familyOfAddress(String address) {
final parsed = InternetAddress.tryParse(address);
if (parsed == null) {
return '';
}
return addressFamily(parsed);
}
class AddressLines {
const AddressLines({
this.used,
this.trying,
this.resolved,
this.fallback,
this.unreported,
this.fake = false,
});
final String? used;
final String? trying;
final String? resolved;
final String? fallback;
final String? unreported;
final bool fake;
}
/// [used] is an address a probe actually connected to or sent to.
/// [resolved] is only the lookup result and is never labeled as the address
/// in use. A remote sample that omits the address stays unreported.
AddressLines describeAddress({
required List<ResolvedAddress> resolved,
String? usedAddress,
String? usedFamily,
String? tryingAddress,
String? tryingFamily,
String fallbackText = '',
bool addressUnreported = false,
bool usedIsFake = false,
}) {
final hasUsed = usedAddress != null && usedAddress.isNotEmpty;
String? used;
if (hasUsed) {
final family = (usedFamily == null || usedFamily.isEmpty)
? familyOfAddress(usedAddress)
: usedFamily;
used = family.isEmpty ? '实际地址 $usedAddress' : '实际地址 $usedAddress($family)';
}
String? trying;
if (!hasUsed && tryingAddress != null && tryingAddress.isNotEmpty) {
final family = (tryingFamily == null || tryingFamily.isEmpty)
? ''
: '($tryingFamily)';
trying = '正在尝试 $tryingAddress$family,还没有正式结果';
}
String? resolvedLine;
if (resolved.isNotEmpty) {
final sameSingle =
resolved.length == 1 &&
hasUsed &&
resolved.single.address == usedAddress;
if (!sameSingle) {
final text = resolved
.map((item) {
final family = item.family.isEmpty ? '' : '(${item.family})';
return '${item.address}$family';
})
.join('、');
resolvedLine = '解析到 $text';
}
}
return AddressLines(
used: used,
trying: trying,
resolved: resolvedLine,
fallback: fallbackText.isEmpty ? null : fallbackText,
unreported: addressUnreported && !hasUsed ? '节点没有报告实际使用的地址' : null,
fake: usedIsFake && hasUsed,
);
}
List<ResolvedAddress> readResolvedList(Object? parsed) {
if (parsed is! Map) {
return const [];
}
final raw = parsed['resolved'];
if (raw is! List) {
return const [];
}
final out = <ResolvedAddress>[];
for (final item in raw) {
if (item is! Map) {
continue;
}
final address = item['address'];
if (address is! String || address.isEmpty) {
continue;
}
final family = item['family'];
out.add(
ResolvedAddress(
address: address,
family: family is String && family.isNotEmpty
? family
: familyOfAddress(address),
),
);
}
return out;
}
+50
View File
@@ -0,0 +1,50 @@
// Copyright (C) 2026 言灸
// SPDX-License-Identifier: AGPL-3.0-only
const chartPinEpsilon = 0.0001;
class ChartSelection {
const ChartSelection({required this.sec, required this.sessionId});
final double sec;
final int sessionId;
}
/// A tap chooses the nearest sample and keeps it after the pointer is
/// released. A new session, an empty series, or a point that has scrolled
/// off the front of the window clears the pin instead of jumping to another
/// sample. [tappedSec] null means "keep the current pin if it is still valid".
ChartSelection? nextChartSelection({
required ChartSelection? current,
required int sessionId,
required List<double> sampleSecs,
double? tappedSec,
}) {
if (tappedSec != null) {
double? nearest;
var best = double.infinity;
for (final sec in sampleSecs) {
final distance = (sec - tappedSec).abs();
if (distance < best) {
best = distance;
nearest = sec;
}
}
if (nearest == null) {
return null;
}
return ChartSelection(sec: nearest, sessionId: sessionId);
}
if (current == null || current.sessionId != sessionId || sampleSecs.isEmpty) {
return null;
}
if (current.sec + chartPinEpsilon < sampleSecs.first) {
return null;
}
for (final sec in sampleSecs) {
if ((sec - current.sec).abs() <= chartPinEpsilon) {
return current;
}
}
return null;
}
+90
View File
@@ -0,0 +1,90 @@
// Copyright (C) 2026 言灸
// SPDX-License-Identifier: AGPL-3.0-only
import 'package:flutter/material.dart';
import '../content/release_history.dart';
import '../version.dart';
import 'quality_charts.dart';
class HistoryPage extends StatelessWidget {
const HistoryPage({super.key});
@override
Widget build(BuildContext context) {
final wide = MediaQuery.sizeOf(context).width >= 720;
return Scaffold(
appBar: AppBar(
title: const Text('更新历史'),
backgroundColor: const Color(0xFFF3F1EC),
),
body: SafeArea(
child: Align(
alignment: Alignment.topCenter,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 760),
child: ListView(
padding: EdgeInsets.fromLTRB(
wide ? 24 : 12,
8,
wide ? 24 : 12,
28,
),
children: [
Text(
'当前版本 $appVersion(构建 $appBuild) · 署名 $appAttribution · $appLicense',
style: const TextStyle(
color: ink,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 8),
const Text(
releaseHistoryNote,
style: TextStyle(color: muted, height: 1.4),
),
const SizedBox(height: 12),
for (final entry in releaseHistory) _entry(entry),
],
),
),
),
),
);
}
Widget _entry(ReleaseEntry entry) {
return Card(
margin: const EdgeInsets.only(bottom: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: const BorderSide(color: line),
),
child: Padding(
padding: const EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
entry.title,
style: const TextStyle(fontWeight: FontWeight.w700, color: ink),
),
const SizedBox(height: 6),
Text(
entry.published == null
? entry.source
: '${entry.published} · ${entry.source}',
style: const TextStyle(color: muted, fontSize: 13, height: 1.4),
),
const SizedBox(height: 8),
for (final point in entry.points)
Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Text('· $point', style: const TextStyle(height: 1.4)),
),
],
),
),
);
}
}
+269 -46
View File
@@ -2,6 +2,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import '../models/node_edit.dart';
import '../models/port_field.dart';
import '../models/probe_profile.dart';
import '../models/session_config.dart';
import '../probe/endpoint_picker.dart';
@@ -9,7 +11,11 @@ import '../probe/probe_controller.dart';
import '../probe/remote_client.dart';
import '../storage/app_store.dart';
import '../storage/token_vault.dart';
import 'address_text.dart';
import 'format.dart';
import 'history_page.dart';
import 'metric_guide_page.dart';
import 'metrics_panel.dart';
import 'quality_charts.dart';
class HomePage extends StatefulWidget {
@@ -134,7 +140,11 @@ class _HomePageState extends State<HomePage> {
final nodeToken = config.node == null
? ''
: (await _vault.read(nodeTokenKey(config.node!.id)) ?? '');
await _controller.start(config, nodeToken: nodeToken, echoToken: _echo.text);
await _controller.start(
config,
nodeToken: nodeToken,
echoToken: _echo.text,
);
}
void _changeProfile(String? id) {
@@ -144,9 +154,11 @@ class _HomePageState extends State<HomePage> {
final previous = ProbeProfile.byId(_profileId);
final next = ProbeProfile.byId(id);
setState(() {
if (_port.text.trim() == '${previous.port}') {
_port.text = '${next.port}';
}
_port.text = portAfterProfileChange(
current: _port.text,
previousDefault: previous.port,
nextDefault: next.port,
);
_profileId = id;
});
}
@@ -160,6 +172,22 @@ class _HomePageState extends State<HomePage> {
appBar: AppBar(
title: const Text('网络质量探测'),
backgroundColor: const Color(0xFFF3F1EC),
actions: [
PopupMenuButton<String>(
tooltip: '说明',
onSelected: (value) {
final page = value == 'history'
? const HistoryPage()
: const MetricGuidePage();
Navigator.of(context)
.push(MaterialPageRoute<void>(builder: (_) => page));
},
itemBuilder: (context) => const [
PopupMenuItem(value: 'metrics', child: Text('指标说明')),
PopupMenuItem(value: 'history', child: Text('更新历史')),
],
),
],
),
body: SafeArea(
child: Align(
@@ -167,12 +195,14 @@ class _HomePageState extends State<HomePage> {
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 880),
child: ListView(
padding: EdgeInsets.fromLTRB(wide ? 24 : 12, 8, wide ? 24 : 12, 28),
padding: EdgeInsets.fromLTRB(
wide ? 24 : 12,
8,
wide ? 24 : 12,
28,
),
children: [
_card(
title: '探测来源',
child: _source(view, wide),
),
_card(title: '探测来源', child: _source(view, wide)),
_card(
title: '目标',
child: Column(
@@ -181,7 +211,13 @@ class _HomePageState extends State<HomePage> {
_pair(
wide,
_field(_host, '目标地址', '域名或 IP'),
_field(_port, '端口', '1–65535'),
_field(
_port,
'端口',
portHint(profile),
fieldKey: const Key('port-field'),
helper: portHelperText,
),
),
const SizedBox(height: 12),
DropdownButtonFormField<String>(
@@ -190,12 +226,18 @@ class _HomePageState extends State<HomePage> {
decoration: const InputDecoration(labelText: '探测类型'),
items: [
for (final item in ProbeProfile.all)
DropdownMenuItem(value: item.id, child: Text(item.label)),
DropdownMenuItem(
value: item.id,
child: Text(item.label),
),
],
onChanged: view.running ? null : _changeProfile,
),
const SizedBox(height: 8),
Text(profile.blurb, style: const TextStyle(color: muted, fontSize: 13)),
Text(
profile.blurb,
style: const TextStyle(color: muted, fontSize: 13),
),
],
),
),
@@ -206,7 +248,11 @@ class _HomePageState extends State<HomePage> {
children: [
_pair(
wide,
_field(_interval, '间隔(毫秒)', _remote ? '至少 200' : '至少 100'),
_field(
_interval,
'间隔(毫秒)',
_remote ? '至少 200' : '至少 100',
),
_field(_timeout, '超时(毫秒)', '100–15000'),
),
if (profile.needsPacketSize) ...[
@@ -252,11 +298,44 @@ class _HomePageState extends State<HomePage> {
_banner(view.banner!),
],
const SizedBox(height: 12),
_card(title: '结果', child: _result(view)),
_card(
title: '结果',
child: _result(
view,
view.profileId.isEmpty ? profile.id : view.profileId,
),
),
if (view.report != null)
SessionSummaryCard(
report: view.report!,
profileId: view.report!.profileId,
),
QualityCharts(
samples: view.samples,
rateLabel: view.rateLabel,
running: view.running,
sessionId: view.sessionId,
),
Wrap(
spacing: 8,
children: [
TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const MetricGuidePage(),
),
),
child: const Text('指标说明'),
),
TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const HistoryPage(),
),
),
child: const Text('更新历史'),
),
],
),
const Text(
'延迟用发包一侧的单调时钟计算。远程探测时,这个时间在节点上量好再传回来,不包含手机到节点的控制通道耗时。TCP 超时不是物理丢包。没有协议应答的 UDP 记为无应答/未知,不会在探测完成前显示 100%。',
@@ -271,17 +350,25 @@ class _HomePageState extends State<HomePage> {
}
Widget _source(ProbeView view, bool wide) {
final selected = _nodes.cast<RemoteNode?>().followedBy(const [null]).firstWhere(
(node) => node?.id == _nodeId,
orElse: () => null,
);
final selected = _nodes
.cast<RemoteNode?>()
.followedBy(const [null])
.firstWhere((node) => node?.id == _nodeId, orElse: () => null);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SegmentedButton<bool>(
segments: const [
ButtonSegment(value: false, label: Text('本机'), icon: Icon(Icons.phone_android)),
ButtonSegment(value: true, label: Text('远程节点'), icon: Icon(Icons.dns_outlined)),
ButtonSegment(
value: false,
label: Text('本机'),
icon: Icon(Icons.phone_android),
),
ButtonSegment(
value: true,
label: Text('远程节点'),
icon: Icon(Icons.dns_outlined),
),
],
selected: {_remote},
onSelectionChanged: view.running
@@ -290,9 +377,7 @@ class _HomePageState extends State<HomePage> {
),
const SizedBox(height: 8),
Text(
_remote
? '由选中的节点向目标发包,这台设备只负责控制和显示。'
: '由这台设备直接向目标发包。可以探测本机上的反射器。',
_remote ? '由选中的节点向目标发包,这台设备只负责控制和显示。' : '由这台设备直接向目标发包。可以探测本机上的反射器。',
style: const TextStyle(color: muted, fontSize: 13),
),
if (_remote) ...[
@@ -338,13 +423,18 @@ class _HomePageState extends State<HomePage> {
return '${node.name} · $vis';
}
Widget _result(ProbeView view) {
Widget _result(ProbeView view, String profileId) {
final summary = view.summary;
final rate = view.rateLabel == '探测无应答'
? summary.probeLossPct
: view.rateLabel == '失败率'
? summary.failurePct
: summary.unknownPct;
final address = describeAddress(
resolved: view.resolved,
usedAddress: view.usedAddress,
usedFamily: view.usedFamily,
tryingAddress: view.tryingAddress,
tryingFamily: view.tryingFamily,
fallbackText: view.fallbackText,
addressUnreported: view.addressUnreported,
usedIsFake: view.usedIsFake,
);
final motd = view.detail['motd'];
final version = view.detail['version'];
final players = view.detail['players'];
@@ -357,13 +447,42 @@ class _HomePageState extends State<HomePage> {
children: [
_chip(view.phase),
_chip('来源 ${view.sourceLabel}'),
if (view.targetAddress != null) _chip('发往 ${view.targetAddress}'),
_chip('延迟 ${formatMs(summary.rttMs)}'),
_chip('抖动 ${formatMs(summary.jitterMs)}'),
_chip('${view.rateLabel} ${formatPct(rate)}'),
if (view.targetHost.isNotEmpty) _chip(view.targetHost),
],
),
if (view.targetIsFake) ...[
const SizedBox(height: 8),
MetricsPanel(
summary: summary,
profileId: profileId,
elapsed: view.elapsed,
),
if (address.trying != null) ...[
const SizedBox(height: 8),
Text(address.trying!, style: const TextStyle(color: ink)),
],
if (address.used != null) ...[
const SizedBox(height: 8),
Text(address.used!, style: const TextStyle(color: ink)),
],
if (address.resolved != null) ...[
const SizedBox(height: 8),
Text(
address.resolved!,
style: const TextStyle(color: muted, fontSize: 13),
),
],
if (address.unreported != null) ...[
const SizedBox(height: 8),
Text(
address.unreported!,
style: const TextStyle(color: Color(0xFF9A3412)),
),
],
if (address.fallback != null) ...[
const SizedBox(height: 8),
Text(address.fallback!, style: const TextStyle(color: ink)),
],
if (address.fake) ...[
const SizedBox(height: 8),
const Text(
clashFakeIpNote,
@@ -386,7 +505,10 @@ class _HomePageState extends State<HomePage> {
),
],
const SizedBox(height: 8),
Text(summaryLine(summary), style: const TextStyle(color: muted, fontSize: 13)),
Text(
summaryLine(summary),
style: const TextStyle(color: muted, fontSize: 13),
),
],
);
}
@@ -434,6 +556,7 @@ class _NodeDialogState extends State<_NodeDialog> {
final _name = TextEditingController();
final _url = TextEditingController();
final _token = TextEditingController();
String? _editingId;
String? _hint;
@override
@@ -450,6 +573,41 @@ class _NodeDialogState extends State<_NodeDialog> {
setState(() => _hint = '请填写名称,以及不带口令的 http 或 https 地址');
return;
}
final editing = _editingId;
if (editing != null) {
RemoteNode? previous;
for (final node in _nodes) {
if (node.id == editing) {
previous = node;
}
}
if (previous == null) {
return;
}
final next = applyNodeEdit(
previous,
name: _name.text.trim(),
baseUrl: url,
);
final replaced = await saveEditedNodeToken(
widget.vault,
editing,
_token.text,
);
setState(() {
_nodes = [
for (final node in _nodes)
if (node.id == editing) next else node,
];
_editingId = null;
_hint = replaced ? '已更新,口令已替换,仍只留在本机。' : '已更新。口令留空,原来的口令未改。';
_name.clear();
_url.clear();
_token.clear();
});
widget.onChanged(_nodes, editing);
return;
}
final id = DateTime.now().microsecondsSinceEpoch.toString();
final node = RemoteNode(id: id, name: _name.text.trim(), baseUrl: url);
await widget.vault.write(nodeTokenKey(id), _token.text.trim());
@@ -463,6 +621,26 @@ class _NodeDialogState extends State<_NodeDialog> {
widget.onChanged(_nodes, id);
}
void _beginEdit(RemoteNode node) {
setState(() {
_editingId = node.id;
_name.text = node.name;
_url.text = node.baseUrl;
_token.clear();
_hint = '正在修改「${node.name}」。口令留空则保留已保存的口令,不会显示原口令。';
});
}
void _cancelEdit() {
setState(() {
_editingId = null;
_name.clear();
_url.clear();
_token.clear();
_hint = null;
});
}
Future<void> _check(RemoteNode node) async {
try {
final info = await fetchNodeInfo(node.baseUrl);
@@ -487,7 +665,10 @@ class _NodeDialogState extends State<_NodeDialog> {
Future<void> _delete(RemoteNode node) async {
await widget.vault.delete(nodeTokenKey(node.id));
final next = [for (final item in _nodes) if (item.id != node.id) item];
final next = [
for (final item in _nodes)
if (item.id != node.id) item,
];
setState(() => _nodes = next);
widget.onChanged(next, null);
}
@@ -510,22 +691,41 @@ class _NodeDialogState extends State<_NodeDialog> {
for (final node in _nodes)
ListTile(
contentPadding: EdgeInsets.zero,
title: Text(_nodes.isEmpty ? '' : '${node.name} · ${visibilityLabel(node.visibility)}'),
subtitle: Text(node.baseUrl, maxLines: 1, overflow: TextOverflow.ellipsis),
title: Text(
'${node.name} · ${visibilityLabel(node.visibility)}',
),
subtitle: Text(
node.baseUrl,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
trailing: Wrap(
spacing: 4,
children: [
TextButton(onPressed: () => _check(node), child: const Text('检查')),
TextButton(onPressed: () => _delete(node), child: const Text('删除')),
TextButton(
key: Key('edit-node-${node.id}'),
onPressed: () => _beginEdit(node),
child: const Text('编辑'),
),
TextButton(
onPressed: () => _check(node),
child: const Text('检查'),
),
TextButton(
onPressed: () => _delete(node),
child: const Text('删除'),
),
],
),
),
TextField(
key: const Key('node-name'),
controller: _name,
decoration: const InputDecoration(labelText: '名称'),
),
const SizedBox(height: 8),
TextField(
key: const Key('node-url'),
controller: _url,
decoration: const InputDecoration(
labelText: '节点地址',
@@ -534,10 +734,14 @@ class _NodeDialogState extends State<_NodeDialog> {
),
const SizedBox(height: 8),
TextField(
key: const Key('node-token'),
controller: _token,
obscureText: true,
decoration: const InputDecoration(
labelText: '节点口令(公开节点留空)',
decoration: InputDecoration(
labelText: _editingId == null ? '节点口令(公开节点留空)' : '新口令(留空则保留)',
helperText: _editingId == null
? null
: '留空则保留已保存的口令,不会显示原口令。',
),
),
if (_hint != null) ...[
@@ -549,8 +753,17 @@ class _NodeDialogState extends State<_NodeDialog> {
),
),
actions: [
TextButton(onPressed: _save, child: const Text('添加节点')),
TextButton(onPressed: () => Navigator.pop(context), child: const Text('完成')),
if (_editingId != null)
TextButton(onPressed: _cancelEdit, child: const Text('取消编辑')),
TextButton(
key: const Key('node-save'),
onPressed: _save,
child: Text(_editingId == null ? '添加节点' : '保存修改'),
),
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('完成'),
),
],
);
}
@@ -568,7 +781,10 @@ Widget _card({required String title, required Widget child}) {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(title, style: const TextStyle(fontWeight: FontWeight.w700, color: ink)),
Text(
title,
style: const TextStyle(fontWeight: FontWeight.w700, color: ink),
),
const SizedBox(height: 10),
child,
],
@@ -582,11 +798,18 @@ Widget _field(
String label,
String hint, {
bool secret = false,
Key? fieldKey,
String? helper,
}) {
return TextField(
key: fieldKey,
controller: controller,
obscureText: secret,
decoration: InputDecoration(labelText: label, hintText: hint),
decoration: InputDecoration(
labelText: label,
hintText: hint,
helperText: helper,
),
);
}
+103
View File
@@ -0,0 +1,103 @@
// Copyright (C) 2026 言灸
// SPDX-License-Identifier: AGPL-3.0-only
import 'package:flutter/material.dart';
import 'quality_charts.dart';
class MetricGuidePage extends StatelessWidget {
const MetricGuidePage({super.key});
@override
Widget build(BuildContext context) {
final wide = MediaQuery.sizeOf(context).width >= 720;
return Scaffold(
appBar: AppBar(
title: const Text('指标说明'),
backgroundColor: const Color(0xFFF3F1EC),
),
body: SafeArea(
child: Align(
alignment: Alignment.topCenter,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 760),
child: ListView(
padding: EdgeInsets.fromLTRB(
wide ? 24 : 12,
8,
wide ? 24 : 12,
28,
),
children: const [
_Section(
title: '这些数字从哪来',
body: '曲线和百分比只来自已经完成、并且计入正式结果的探测。还在途中的请求不会画成 100%,停止时被取消的请求也不算丢包。没有内置样本。',
),
_Section(
title: '已发送、已收到、超时',
body: '已发送是计入正式结果的次数。已收到是其中成功的次数:合作反射收到了对上序号的回显,普通 TCP 是连上了,其他类型是收到了符合协议的应答。\n\n合作反射的「超时」只计已经把探测帧写出去、但超时前没有对上序号的次数。还没连上、连接被拒绝,不算进这个超时,也不算进探测无应答。\n\n普通 UDP、DNS、自定义 UDP 和基岩版如果根本没有协议应答,记为「无应答」,超时这一项显示不适用。收到了包但内容不对,记为协议错误。UDP 沉默不能当成已经证实的丢包:对端可以合法地不回答。',
),
_Section(
title: '探测无应答、失败率、无应答',
body: '合作反射 TCP / UDP:探测无应答 = 超时 ÷(超时 + 成功)× 100%。分母只含已经写出的回显尝试。分母为 0 时显示 —,而不是 0%。TCP 会重传,所以这不是网卡上的物理丢包。\n\n普通 TCP 和 Minecraft Java:失败率 = 未成功的正式尝试 ÷ 已完成的正式尝试 × 100%。这里没有丢包百分比。\n\n其余 UDP 类探测:无应答 = 无应答次数 ÷ 已完成次数 × 100%。它回答的是「没有看到协议应答」,不是「丢了多少包」。',
),
_Section(
title: '延迟、中位数、P95 和抖动',
body: '延迟只来自成功的样本,单位是毫秒。当前延迟是最近一次成功的往返时间。最小、平均、最大都是这些成功样本的最小、算术平均和最大。\n\n中位数:把成功样本从小到大排列。奇数个取中间那个;偶数个取中间两个的平均。\n\nP95 用最近秩:秩 = ceil(0.95 × 次数),用整数 (95 × 次数 + 99) / 100 计算,从 1 开始,取排序后这个位置的值。次数为 1 时,P95 就是那一次。\n\n抖动按 RFC 3550:D 是相邻两次成功往返时间之差,J = J + (|D| − J) / 16。第一次成功时 J 为 0;没有成功时显示 —。远程探测的往返时间在节点上用单调时钟量好再传回来,不包含手机到节点的控制通道耗时。\n\n旧版本节点不会上报最小、平均、中位、P95 和最大。这时这些格子显示「节点未提供」,当前延迟和抖动仍用它原来上报的值。',
),
_Section(
title: '用时',
body: '用时是这次会话从按下开始到停止(或到当前)的墙钟时间。它不是各次往返时间相加,也不包括节点在创建任务之前花掉的时间。',
),
_Section(
title: '选址失败和正式丢包',
body: '一个域名可能同时有 IPv6 和 IPv4。程序会先试一个地址。还没有任何地址应答时,连不上或没有应答会换下一个。这种只为挑选地址而失败的尝试,如果后面有地址成功,就不计入已发送、超时和丢包,界面单独写明回退了哪个地址。\n\n一旦某个地址已经应答,之后对它的超时或失败都算正式结果,不会因为后来又换地址而被抹掉。只有一个地址时,失败从一开始就算正式结果。\n\n如果每一个候选都失败,这些失败会计入正式结果。界面显示失败或 100% 的无应答/失败率,不会显示 0% 成功。\n\n1.1.1 的远程节点还不会做这层区分,它的统计可能仍把第一次选址失败算进去。要分开看,节点也需要 1.1.2。',
),
_Section(
title: '实际地址和 IPv6 回退',
body: '「实际地址」是这次真正连通或真正发包的 IP,并注明 IPv4 或 IPv6。「解析到」只是域名解析的结果,不会被说成已经在用的地址。\n\n正在尝试、还没有正式结果时,会标明正在尝试,而不是写成已经发往。远程节点如果没有在结果里带上地址(旧版本就是这样),界面写「节点没有报告实际使用的地址」,不会在手机上另做一次解析来冒充。\n\n地址落在 198.18.0.0/15 时,会提示这是 VPN 假地址,只有这个 VPN 开着时才能用。',
),
_Section(
title: '停止以后',
body: '点停止会保留曲线,并给出开始、结束、用时、目标、类型、来源、实际地址和同一套最终指标。正在进行、因为停止而被取消的请求不计入丢包。重新开始会换一次新的会话,旧曲线不会混进来。\n\n点曲线上的一点可以钉住该时刻的延迟和比率,松手后仍然留着。再点另一点会换。新会话或这个点滚出窗口后,选择会被清掉,不会跳到别的点上。',
),
],
),
),
),
),
);
}
}
class _Section extends StatelessWidget {
const _Section({required this.title, required this.body});
final String title;
final String body;
@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.only(bottom: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: const BorderSide(color: line),
),
child: Padding(
padding: const EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
title,
style: const TextStyle(fontWeight: FontWeight.w700, color: ink),
),
const SizedBox(height: 8),
Text(body, style: const TextStyle(height: 1.45, color: ink)),
],
),
),
);
}
}
+271
View File
@@ -0,0 +1,271 @@
// Copyright (C) 2026 言灸
// SPDX-License-Identifier: AGPL-3.0-only
import 'package:flutter/material.dart';
import '../metrics/sample_book.dart';
import '../probe/endpoint_picker.dart';
import '../probe/probe_controller.dart';
import 'address_text.dart';
import 'format.dart';
import 'quality_charts.dart';
class MetricLine {
const MetricLine(this.label, this.value, {this.detail});
final String label;
final String value;
final String? detail;
}
/// Rows use the same summary the live view and the stopped session share.
/// A metric that this profile does not measure is marked unsupported instead
/// of being shown as zero.
List<MetricLine> metricLines({
required ProbeSummary summary,
required String profileId,
required Duration elapsed,
}) {
final lines = <MetricLine>[
MetricLine(
'已发送',
'${summary.sent}',
detail: summary.selectionSkipped > 0
? '正式结果 ${summary.sent} 次。另有 ${summary.selectionSkipped} 次选址失败未计入。'
: '只计已经计入正式结果的次数,不含还在途中的探测。',
),
MetricLine('已收到', '${summary.ok}', detail: '成功收到应答,或成功连通的次数。'),
_timeoutLine(summary, profileId),
_rateLine(summary, profileId),
_latency('当前延迟', summary.rttMs, summary, recent: true),
_latency('最小延迟', summary.minRttMs, summary),
_latency('平均延迟', summary.meanRttMs, summary),
_latency('中位延迟', summary.medianRttMs, summary),
_latency('P95 延迟', summary.p95RttMs, summary),
_latency('最大延迟', summary.maxRttMs, summary),
MetricLine(
'抖动',
summary.jitterMs == null ? '—' : formatMs(summary.jitterMs),
detail: 'RFC 3550:J = J + (|D| − J) / 16。D 是相邻两次成功往返时间之差。只有一次成功时 J 为 0。',
),
MetricLine(
'用时',
formatDuration(elapsed),
detail: '从这次探测开始到现在或到停止的墙钟时间,不是往返时间相加。',
),
];
return lines;
}
MetricLine _timeoutLine(ProbeSummary summary, String profileId) {
switch (profileId) {
case 'nq-tcp':
case 'nq-udp':
return MetricLine(
'超时',
'${summary.timeout}',
detail: '已经写出回显帧、在超时前没有对上序号的次数。连接失败另计,不在这里。',
);
case 'tcp-connect':
case 'minecraft-java':
return const MetricLine('超时', '不适用', detail: '这种探测把连不上记为失败,不单独叫探测超时。');
default:
return MetricLine(
'超时',
'不适用',
detail: '没有协议应答时记为无应答 ${summary.unknown} 次,不能据此断定丢包。',
);
}
}
MetricLine _rateLine(ProbeSummary summary, String profileId) {
switch (profileId) {
case 'nq-tcp':
case 'nq-udp':
final denom = summary.timeout + summary.ok;
return MetricLine(
'探测无应答',
formatPct(summary.probeLossPct),
detail: denom == 0
? '还没有完成的回显尝试,所以不显示 0%。'
: '超时 ÷(超时 + 成功)= ${summary.timeout} ÷ $denom。连接失败不在分母里。',
);
case 'tcp-connect':
case 'minecraft-java':
return MetricLine(
'失败率',
formatPct(summary.failurePct),
detail: '未成功的正式尝试 ÷ 已完成的正式尝试。这不是物理丢包。',
);
default:
return MetricLine(
'无应答(未知)',
formatPct(summary.unknownPct),
detail: '无应答 ÷ 已完成。沉默不是丢包;明确的协议错误、拒绝和域名失败另看失败次数。',
);
}
}
MetricLine _latency(
String label,
double? value,
ProbeSummary summary, {
bool recent = false,
}) {
if (!summary.latencyStats && summary.ok > 0 && !recent) {
return MetricLine(label, '节点未提供', detail: '这份结果来自没有上报延迟分布的节点。当前延迟仍然可用。');
}
return MetricLine(
label,
formatMs(value),
detail: recent ? '最近一次成功的往返时间。没有成功时为 —。' : '只统计成功样本。没有成功时为 —。',
);
}
String formatDuration(Duration duration) {
final ms = duration.inMilliseconds;
if (ms < 0) {
return '—';
}
if (ms < 1000) {
return '$ms 毫秒';
}
final seconds = ms / 1000;
if (seconds < 60) {
return '${seconds.toStringAsFixed(1)} 秒';
}
final minutes = duration.inMinutes;
final rest = duration.inSeconds % 60;
return '$minutes 分 $rest 秒';
}
String formatClock(DateTime time) {
final local = time.toLocal();
String two(int value) => value.toString().padLeft(2, '0');
return '${local.year}-${two(local.month)}-${two(local.day)} ${two(local.hour)}:${two(local.minute)}:${two(local.second)}';
}
class MetricsPanel extends StatelessWidget {
const MetricsPanel({
super.key,
required this.summary,
required this.profileId,
required this.elapsed,
});
final ProbeSummary summary;
final String profileId;
final Duration elapsed;
@override
Widget build(BuildContext context) {
final lines = metricLines(
summary: summary,
profileId: profileId,
elapsed: elapsed,
);
return Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (final line in lines)
Tooltip(
message: line.detail ?? '',
child: _chip('${line.label} ${line.value}'),
),
],
);
}
}
class SessionSummaryCard extends StatelessWidget {
const SessionSummaryCard({
super.key,
required this.report,
required this.profileId,
});
final SessionReport report;
final String profileId;
@override
Widget build(BuildContext context) {
final address = describeAddress(
resolved: report.resolved,
usedAddress: report.usedAddress,
usedFamily: report.usedFamily,
fallbackText: report.fallbackText,
addressUnreported: report.addressUnreported,
usedIsFake: report.usedIsFake,
);
return _panel(
title: '本次结果',
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text('开始 ${formatClock(report.startedAt)}'),
Text('结束 ${formatClock(report.endedAt)}'),
Text('用时 ${formatDuration(report.elapsed)}'),
Text('目标 ${report.target}'),
Text('类型 ${report.profileLabel}'),
Text('来源 ${report.sourceLabel}'),
if (address.used != null) Text(address.used!),
if (address.resolved != null) Text(address.resolved!),
if (address.unreported != null) Text(address.unreported!),
if (address.fallback != null) Text(address.fallback!),
if (address.fake)
const Text(
clashFakeIpNote,
style: TextStyle(color: Color(0xFF9A3412)),
),
const SizedBox(height: 8),
MetricsPanel(
summary: report.summary,
profileId: profileId,
elapsed: report.elapsed,
),
const SizedBox(height: 8),
Text(
summaryLine(report.summary),
style: const TextStyle(color: muted, fontSize: 13),
),
],
),
);
}
}
Widget _panel({required String title, required Widget child}) {
return Card(
margin: const EdgeInsets.only(bottom: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: const BorderSide(color: line),
),
child: Padding(
padding: const EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
title,
style: const TextStyle(fontWeight: FontWeight.w700, color: ink),
),
const SizedBox(height: 10),
child,
],
),
),
);
}
Widget _chip(String text) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: const Color(0xFFE7EEF5),
borderRadius: BorderRadius.circular(99),
),
child: Text(text, style: const TextStyle(fontSize: 12, color: ink)),
);
}
+126 -16
View File
@@ -2,6 +2,8 @@ import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import '../probe/probe_controller.dart';
import 'chart_selection.dart';
import 'format.dart';
const rttColor = Color(0xFF1F4E79);
const rateColor = Color(0xFF9A3412);
@@ -9,20 +11,67 @@ const ink = Color(0xFF1C2430);
const muted = Color(0xFF5E6872);
const line = Color(0xFFE4DFD4);
class QualityCharts extends StatelessWidget {
class QualityCharts extends StatefulWidget {
const QualityCharts({
super.key,
required this.samples,
required this.rateLabel,
required this.running,
required this.sessionId,
});
final List<ChartSample> samples;
final String rateLabel;
final bool running;
final int sessionId;
@override
State<QualityCharts> createState() => _QualityChartsState();
}
class _QualityChartsState extends State<QualityCharts> {
ChartSelection? _pin;
@override
void didUpdateWidget(QualityCharts oldWidget) {
super.didUpdateWidget(oldWidget);
final kept = nextChartSelection(
current: _pin,
sessionId: widget.sessionId,
sampleSecs: [for (final sample in widget.samples) sample.sec],
);
if (kept?.sec != _pin?.sec || kept?.sessionId != _pin?.sessionId) {
_pin = kept;
}
}
void _pinAt(double sec) {
setState(() {
_pin = nextChartSelection(
current: _pin,
sessionId: widget.sessionId,
sampleSecs: [for (final sample in widget.samples) sample.sec],
tappedSec: sec,
);
});
}
ChartSample? get _pinnedSample {
final pin = _pin;
if (pin == null || pin.sessionId != widget.sessionId) {
return null;
}
for (final sample in widget.samples) {
if ((sample.sec - pin.sec).abs() <= chartPinEpsilon) {
return sample;
}
}
return null;
}
@override
Widget build(BuildContext context) {
final pinned = _pinnedSample;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@@ -34,29 +83,51 @@ class QualityCharts extends StatelessWidget {
],
),
const SizedBox(height: 8),
Text(
pinned == null
? '点曲线上的一点可以钉住该时刻,松手后仍会保留。再点另一点会更换。'
: pinnedReadout(pinned, widget.rateLabel),
key: const Key('chart-pin'),
style: const TextStyle(color: ink, fontSize: 13, height: 1.4),
),
const SizedBox(height: 8),
_ChartCard(
title: '延迟',
unit: 'ms',
samples: samples,
samples: widget.samples,
read: (sample) => sample.rttMs,
color: rttColor,
floor: 1,
running: running,
running: widget.running,
pinnedSec: pinned?.sec,
onPin: _pinAt,
),
_ChartCard(
title: rateLabel,
title: widget.rateLabel,
unit: '%',
samples: samples,
samples: widget.samples,
read: (sample) => sample.ratePct,
color: rateColor,
floor: 10,
running: running,
running: widget.running,
pinnedSec: pinned?.sec,
onPin: _pinAt,
),
],
);
}
}
String pinnedReadout(ChartSample sample, String rateLabel) {
final latency = sample.rttMs == null
? '这一刻没有延迟'
: '延迟 ${formatMs(sample.rttMs)}';
final rate = sample.ratePct == null
? '$rateLabel —'
: '$rateLabel ${formatPct(sample.ratePct)}';
return '已选 ${sample.sec.toStringAsFixed(1)} 秒 · $latency · $rate';
}
class _Swatch extends StatelessWidget {
const _Swatch({required this.color, required this.label});
@@ -92,6 +163,8 @@ class _ChartCard extends StatelessWidget {
required this.color,
required this.floor,
required this.running,
required this.pinnedSec,
required this.onPin,
});
final String title;
@@ -101,6 +174,8 @@ class _ChartCard extends StatelessWidget {
final Color color;
final double floor;
final bool running;
final double? pinnedSec;
final void Function(double sec) onPin;
@override
Widget build(BuildContext context) {
@@ -132,9 +207,7 @@ class _ChartCard extends StatelessWidget {
? _lineChart(spots)
: Center(
child: Text(
running
? '正在等待第一次完成的探测。未完成的不会画成 100%。'
: '暂无已完成的探测',
running ? '正在等待第一次完成的探测。未完成的不会画成 100%。' : '暂无已完成的探测',
style: const TextStyle(color: muted),
textAlign: TextAlign.center,
),
@@ -190,7 +263,8 @@ class _ChartCard extends StatelessWidget {
show: true,
drawVerticalLine: false,
horizontalInterval: yInterval,
getDrawingHorizontalLine: (_) => const FlLine(color: line, strokeWidth: 1),
getDrawingHorizontalLine: (_) =>
const FlLine(color: line, strokeWidth: 1),
),
borderData: FlBorderData(
show: true,
@@ -200,14 +274,19 @@ class _ChartCard extends StatelessWidget {
),
),
titlesData: FlTitlesData(
topTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
rightTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
topTitles: const AxisTitles(
sideTitles: SideTitles(showTitles: false),
),
rightTitles: const AxisTitles(
sideTitles: SideTitles(showTitles: false),
),
leftTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
reservedSize: 40,
interval: yInterval,
getTitlesWidget: (value, meta) => _axisLabel(_formatTick(value, maxY)),
getTitlesWidget: (value, meta) =>
_axisLabel(_formatTick(value, maxY)),
),
),
bottomTitles: AxisTitles(
@@ -220,15 +299,46 @@ class _ChartCard extends StatelessWidget {
),
),
),
lineTouchData: const LineTouchData(handleBuiltInTouches: true),
extraLinesData: ExtraLinesData(
verticalLines: [
if (pinnedSec != null)
VerticalLine(
x: pinnedSec!,
color: color.withValues(alpha: 0.85),
strokeWidth: 1.5,
),
],
),
lineTouchData: LineTouchData(
handleBuiltInTouches: false,
touchSpotThreshold: 18,
touchCallback: (event, response) {
if (event is! FlTapUpEvent) {
return;
}
final spots = response?.lineBarSpots;
if (spots == null || spots.isEmpty) {
return;
}
onPin(spots.first.x);
},
),
lineBarsData: [
LineChartBarData(
spots: spots,
isCurved: false,
color: color,
barWidth: 2,
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: true, color: color.withValues(alpha: 0.10)),
dotData: FlDotData(
show: pinnedSec != null,
checkToShowDot: (spot, _) =>
pinnedSec != null &&
(spot.x - pinnedSec!).abs() <= chartPinEpsilon,
),
belowBarData: BarAreaData(
show: true,
color: color.withValues(alpha: 0.10),
),
),
],
),