网络质量探测 1.1.3:自更新、HTTP/3 与中心节点
版本名 1.1.3,构建号 6。应用标识和签名未改。包含自动更新、覆盖安装、目标历史、IPv4/IPv6 开关、HTTP(含 HTTP/3)以及中心服务端一键添加节点。
This commit is contained in:
1 parent
943259774f
commit
8cdc0f436f
66 files changed
+5489
-78
No files matched your search
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2026 言灸
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
/// Host used for an address-family check. HTTP targets may be a full URL.
|
||||
String probeHost(String raw) {
|
||||
final text = raw.trim();
|
||||
if (text.isEmpty) {
|
||||
return '';
|
||||
}
|
||||
if (text.contains('://')) {
|
||||
return Uri.tryParse(text)?.host ?? '';
|
||||
}
|
||||
final slash = text.indexOf('/');
|
||||
final host = slash >= 0 ? text.substring(0, slash) : text;
|
||||
return host.replaceAll('[', '').replaceAll(']', '');
|
||||
}
|
||||
|
||||
/// Returns a message when the probe must not start. Null means the families allow it.
|
||||
String? familyRefusal(
|
||||
String raw, {
|
||||
required bool v4,
|
||||
required bool v6,
|
||||
}) {
|
||||
if (!v4 && !v6) {
|
||||
return 'IPv4 和 IPv6 都已关闭,无法开始探测。请在设置里至少打开一个。';
|
||||
}
|
||||
final host = probeHost(raw);
|
||||
final parsed = InternetAddress.tryParse(host);
|
||||
if (parsed == null) {
|
||||
return null;
|
||||
}
|
||||
if (parsed.type == InternetAddressType.IPv4 && !v4) {
|
||||
return '目标是 IPv4 地址,但设置里的 IPv4 已关闭。';
|
||||
}
|
||||
if (parsed.type == InternetAddressType.IPv6 && !v6) {
|
||||
return '目标是 IPv6 地址,但设置里的 IPv6 已关闭。';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
List<InternetAddress> filterAddresses(
|
||||
List<InternetAddress> addresses, {
|
||||
required bool v4,
|
||||
required bool v6,
|
||||
}) {
|
||||
return [
|
||||
for (final address in addresses)
|
||||
if ((address.type == InternetAddressType.IPv4 && v4) ||
|
||||
(address.type == InternetAddressType.IPv6 && v6))
|
||||
address,
|
||||
];
|
||||
}
|
||||
@@ -23,10 +23,21 @@ String portHint(ProbeProfile profile) {
|
||||
return '合作反射 TCP 默认 19090';
|
||||
case 'nq-udp':
|
||||
return '合作反射 UDP 默认 19091';
|
||||
case 'http':
|
||||
return 'HTTP 默认 443(https)或 80(http)';
|
||||
default:
|
||||
return '${profile.label} 默认 ${profile.port}';
|
||||
}
|
||||
}
|
||||
|
||||
/// Default port for an HTTP target. A full http:// URL uses 80. Anything else uses 443.
|
||||
int httpDefaultPort(String target) {
|
||||
final text = target.trim().toLowerCase();
|
||||
if (text.startsWith('http://')) {
|
||||
return 80;
|
||||
}
|
||||
return 443;
|
||||
}
|
||||
|
||||
const portHelperText =
|
||||
'合作反射 TCP 默认 19090,UDP 默认 19091。只有当前端口仍是上一种类型的默认值或为空时,切换类型才会自动更换。';
|
||||
@@ -64,6 +64,14 @@ class ProbeProfile {
|
||||
blurb: '发送 RakNet Unconnected Ping,校验 magic 和原时间戳。',
|
||||
rateLabel: '无应答(未知)',
|
||||
);
|
||||
static const http = ProbeProfile(
|
||||
id: 'http',
|
||||
label: 'HTTP',
|
||||
port: 443,
|
||||
blurb:
|
||||
'按 HTTP 请求测量。默认优先 HTTP/2,服务器不支持时降到 HTTP/1.1。强制的版本不支持就失败,不会偷偷降级。4xx 和 5xx 会显示状态码,不算丢包。',
|
||||
rateLabel: '失败率',
|
||||
);
|
||||
static const customUdp = ProbeProfile(
|
||||
id: 'custom-udp',
|
||||
label: '自定义 UDP',
|
||||
@@ -81,6 +89,7 @@ class ProbeProfile {
|
||||
minecraftJava,
|
||||
minecraftBedrock,
|
||||
customUdp,
|
||||
http,
|
||||
];
|
||||
|
||||
static ProbeProfile byId(String id) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../protocol/probe_packet.dart';
|
||||
import 'ip_family.dart';
|
||||
import 'probe_profile.dart';
|
||||
|
||||
class RemoteNode {
|
||||
@@ -9,35 +10,95 @@ class RemoteNode {
|
||||
required this.name,
|
||||
required this.baseUrl,
|
||||
this.visibility = '',
|
||||
this.fromCenter = false,
|
||||
this.confidential = false,
|
||||
this.centerLinkId = '',
|
||||
this.serverId = '',
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String name;
|
||||
final String baseUrl;
|
||||
final String visibility;
|
||||
final bool fromCenter;
|
||||
final bool confidential;
|
||||
final String centerLinkId;
|
||||
final String serverId;
|
||||
|
||||
RemoteNode copyWith({String? name, String? baseUrl, String? visibility}) {
|
||||
RemoteNode copyWith({
|
||||
String? name,
|
||||
String? baseUrl,
|
||||
String? visibility,
|
||||
bool? fromCenter,
|
||||
bool? confidential,
|
||||
String? centerLinkId,
|
||||
String? serverId,
|
||||
}) {
|
||||
final hidden = confidential ?? this.confidential;
|
||||
return RemoteNode(
|
||||
id: id,
|
||||
name: name ?? this.name,
|
||||
baseUrl: baseUrl ?? this.baseUrl,
|
||||
baseUrl: hidden ? '' : (baseUrl ?? this.baseUrl),
|
||||
visibility: visibility ?? this.visibility,
|
||||
fromCenter: fromCenter ?? this.fromCenter,
|
||||
confidential: hidden,
|
||||
centerLinkId: centerLinkId ?? this.centerLinkId,
|
||||
serverId: serverId ?? this.serverId,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, Object?> toJson() => {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'baseUrl': baseUrl,
|
||||
'baseUrl': confidential ? '' : baseUrl,
|
||||
'visibility': visibility,
|
||||
'fromCenter': fromCenter,
|
||||
'confidential': confidential,
|
||||
'centerLinkId': centerLinkId,
|
||||
'serverId': serverId,
|
||||
};
|
||||
|
||||
factory RemoteNode.fromJson(Map<String, dynamic> json) {
|
||||
final confidential = json['confidential'] == true;
|
||||
return RemoteNode(
|
||||
id: json['id'] is String ? json['id'] as String : '',
|
||||
name: json['name'] is String ? json['name'] as String : '未命名节点',
|
||||
baseUrl: json['baseUrl'] is String ? json['baseUrl'] as String : '',
|
||||
baseUrl: confidential
|
||||
? ''
|
||||
: (json['baseUrl'] is String ? json['baseUrl'] as String : ''),
|
||||
visibility: json['visibility'] is String ? json['visibility'] as String : '',
|
||||
fromCenter: json['fromCenter'] == true,
|
||||
confidential: confidential,
|
||||
centerLinkId: json['centerLinkId'] is String
|
||||
? json['centerLinkId'] as String
|
||||
: '',
|
||||
serverId: json['serverId'] is String ? json['serverId'] as String : '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CenterLink {
|
||||
const CenterLink({
|
||||
required this.id,
|
||||
required this.url,
|
||||
required this.account,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String url;
|
||||
final String account;
|
||||
|
||||
Map<String, Object?> toJson() => {
|
||||
'id': id,
|
||||
'url': url,
|
||||
'account': account,
|
||||
};
|
||||
|
||||
factory CenterLink.fromJson(Map<String, dynamic> json) {
|
||||
return CenterLink(
|
||||
id: json['id'] is String ? json['id'] as String : '',
|
||||
url: json['url'] is String ? json['url'] as String : '',
|
||||
account: json['account'] is String ? json['account'] as String : '',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +118,18 @@ class SessionConfig {
|
||||
required this.dnsName,
|
||||
required this.payloadHex,
|
||||
required this.expectHex,
|
||||
this.allowIPv4 = true,
|
||||
this.allowIPv6 = true,
|
||||
this.autoUpdate = true,
|
||||
this.httpVersion = 'auto',
|
||||
this.httpResolve = '',
|
||||
this.httpMethod = 'GET',
|
||||
this.httpBody = '',
|
||||
this.httpReferer = '',
|
||||
this.httpUserAgent = '',
|
||||
this.httpCookies = '',
|
||||
this.httpMaxRedirects = 5,
|
||||
this.centers = const [],
|
||||
});
|
||||
|
||||
static const defaults = SessionConfig(
|
||||
@@ -88,6 +161,27 @@ class SessionConfig {
|
||||
final String dnsName;
|
||||
final String payloadHex;
|
||||
final String expectHex;
|
||||
final bool allowIPv4;
|
||||
final bool allowIPv6;
|
||||
final bool autoUpdate;
|
||||
final String httpVersion;
|
||||
final String httpResolve;
|
||||
final String httpMethod;
|
||||
final String httpBody;
|
||||
final String httpReferer;
|
||||
final String httpUserAgent;
|
||||
final String httpCookies;
|
||||
final int httpMaxRedirects;
|
||||
final List<CenterLink> centers;
|
||||
|
||||
CenterLink? centerLink(String id) {
|
||||
for (final link in centers) {
|
||||
if (link.id == id) {
|
||||
return link;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
ProbeProfile get profile => ProbeProfile.byId(profileId);
|
||||
|
||||
@@ -101,9 +195,36 @@ class SessionConfig {
|
||||
}
|
||||
|
||||
String? validate() {
|
||||
final family = familyRefusal(host, v4: allowIPv4, v6: allowIPv6);
|
||||
if (family != null) {
|
||||
return family;
|
||||
}
|
||||
if (profileId == 'http' && httpResolve.trim().isNotEmpty) {
|
||||
final resolveFamily = familyRefusal(
|
||||
httpResolve,
|
||||
v4: allowIPv4,
|
||||
v6: allowIPv6,
|
||||
);
|
||||
if (resolveFamily != null) {
|
||||
return resolveFamily.replaceFirst('目标', '指定解析');
|
||||
}
|
||||
}
|
||||
if (host.trim().isEmpty) {
|
||||
return '请填写目标地址';
|
||||
}
|
||||
if (profileId == 'http') {
|
||||
final method = httpMethod.trim().toUpperCase();
|
||||
if (method != 'GET' && method != 'POST') {
|
||||
return 'HTTP 方法只支持 GET 和 POST';
|
||||
}
|
||||
if (httpMaxRedirects < 0 || httpMaxRedirects > 20) {
|
||||
return '跳转次数需要在 0 到 20 之间';
|
||||
}
|
||||
const versions = {'auto', '1.1', '2', '3'};
|
||||
if (!versions.contains(httpVersion)) {
|
||||
return 'HTTP 版本需要是自动、1.1、2 或 3';
|
||||
}
|
||||
}
|
||||
if (port < 1 || port > 65535) {
|
||||
return '端口需要在 1 到 65535 之间';
|
||||
}
|
||||
@@ -146,7 +267,12 @@ class SessionConfig {
|
||||
if (selected == null) {
|
||||
return '请先添加并选择一个远程节点';
|
||||
}
|
||||
if (normalizeNodeUrl(selected.baseUrl) == null) {
|
||||
if (selected.confidential) {
|
||||
final link = centerLink(selected.centerLinkId);
|
||||
if (link == null || normalizeNodeUrl(link.url) == null) {
|
||||
return '保密节点需要一个可用的中心地址';
|
||||
}
|
||||
} else if (normalizeNodeUrl(selected.baseUrl) == null) {
|
||||
return '节点地址需要是 http 或 https,且不能把口令写在地址里';
|
||||
}
|
||||
}
|
||||
@@ -167,6 +293,18 @@ class SessionConfig {
|
||||
'dnsName': dnsName,
|
||||
'payloadHex': payloadHex,
|
||||
'expectHex': expectHex,
|
||||
'allowIPv4': allowIPv4,
|
||||
'allowIPv6': allowIPv6,
|
||||
'autoUpdate': autoUpdate,
|
||||
'httpVersion': httpVersion,
|
||||
'httpResolve': httpResolve,
|
||||
'httpMethod': httpMethod,
|
||||
'httpBody': httpBody,
|
||||
'httpReferer': httpReferer,
|
||||
'httpUserAgent': httpUserAgent,
|
||||
'httpCookies': httpCookies,
|
||||
'httpMaxRedirects': httpMaxRedirects,
|
||||
'centers': centers.map((link) => link.toJson()).toList(),
|
||||
};
|
||||
|
||||
factory SessionConfig.fromJson(Map<String, dynamic> json) {
|
||||
@@ -197,9 +335,43 @@ class SessionConfig {
|
||||
: defaults.dnsName,
|
||||
payloadHex: json['payloadHex'] is String ? json['payloadHex'] as String : '',
|
||||
expectHex: json['expectHex'] is String ? json['expectHex'] as String : '',
|
||||
allowIPv4: json['allowIPv4'] is bool ? json['allowIPv4'] as bool : true,
|
||||
allowIPv6: json['allowIPv6'] is bool ? json['allowIPv6'] as bool : true,
|
||||
autoUpdate: json['autoUpdate'] is bool ? json['autoUpdate'] as bool : true,
|
||||
httpVersion: json['httpVersion'] is String
|
||||
? json['httpVersion'] as String
|
||||
: 'auto',
|
||||
httpResolve: json['httpResolve'] is String
|
||||
? json['httpResolve'] as String
|
||||
: '',
|
||||
httpMethod: json['httpMethod'] is String
|
||||
? json['httpMethod'] as String
|
||||
: 'GET',
|
||||
httpBody: json['httpBody'] is String ? json['httpBody'] as String : '',
|
||||
httpReferer: json['httpReferer'] is String
|
||||
? json['httpReferer'] as String
|
||||
: '',
|
||||
httpUserAgent: json['httpUserAgent'] is String
|
||||
? json['httpUserAgent'] as String
|
||||
: '',
|
||||
httpCookies: json['httpCookies'] is String
|
||||
? json['httpCookies'] as String
|
||||
: '',
|
||||
httpMaxRedirects: _asInt(json['httpMaxRedirects'], 5),
|
||||
centers: _centers(json['centers']),
|
||||
);
|
||||
}
|
||||
|
||||
static List<CenterLink> _centers(Object? raw) {
|
||||
if (raw is! List) {
|
||||
return const [];
|
||||
}
|
||||
return [
|
||||
for (final item in raw)
|
||||
if (item is Map) CenterLink.fromJson(Map<String, dynamic>.from(item)),
|
||||
];
|
||||
}
|
||||
|
||||
static int _asInt(Object? value, int fallback) {
|
||||
if (value is int) {
|
||||
return value;
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
// Copyright (C) 2026 言灸
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
/// A recent probe target. This list is local and never stores node tokens,
|
||||
/// center credentials, cookies, or request bodies.
|
||||
class TargetEntry {
|
||||
const TargetEntry({
|
||||
required this.host,
|
||||
required this.port,
|
||||
required this.profileId,
|
||||
this.httpUrl = '',
|
||||
this.method = '',
|
||||
required this.savedAtMs,
|
||||
});
|
||||
|
||||
final String host;
|
||||
final int port;
|
||||
final String profileId;
|
||||
final String httpUrl;
|
||||
final String method;
|
||||
final int savedAtMs;
|
||||
|
||||
String get key {
|
||||
final http = profileId == 'http';
|
||||
return [
|
||||
profileId,
|
||||
'$port',
|
||||
host.trim(),
|
||||
http ? httpUrl.trim() : '',
|
||||
http ? method.trim().toUpperCase() : '',
|
||||
].join('\u0001');
|
||||
}
|
||||
|
||||
String get label {
|
||||
final where = httpUrl.trim().isNotEmpty ? httpUrl.trim() : host.trim();
|
||||
final methodText = profileId == 'http' && method.trim().isNotEmpty
|
||||
? ' ${method.trim().toUpperCase()}'
|
||||
: '';
|
||||
return '$where:$port · $profileId$methodText';
|
||||
}
|
||||
|
||||
Map<String, Object?> toJson() => {
|
||||
'host': host,
|
||||
'port': port,
|
||||
'profileId': profileId,
|
||||
'httpUrl': httpUrl,
|
||||
'method': method,
|
||||
'savedAtMs': savedAtMs,
|
||||
};
|
||||
|
||||
factory TargetEntry.fromJson(Map<String, dynamic> json) {
|
||||
return TargetEntry(
|
||||
host: json['host'] is String ? json['host'] as String : '',
|
||||
port: json['port'] is int ? json['port'] as int : 0,
|
||||
profileId: json['profileId'] is String ? json['profileId'] as String : '',
|
||||
httpUrl: json['httpUrl'] is String ? json['httpUrl'] as String : '',
|
||||
method: json['method'] is String ? json['method'] as String : '',
|
||||
savedAtMs: json['savedAtMs'] is int ? json['savedAtMs'] as int : 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TargetHistory {
|
||||
const TargetHistory(this.entries);
|
||||
|
||||
static const maxEntries = 40;
|
||||
static const empty = TargetHistory([]);
|
||||
|
||||
final List<TargetEntry> entries;
|
||||
|
||||
TargetHistory add(TargetEntry entry) {
|
||||
final next = [
|
||||
entry,
|
||||
for (final item in entries)
|
||||
if (item.key != entry.key) item,
|
||||
];
|
||||
if (next.length > maxEntries) {
|
||||
return TargetHistory(next.sublist(0, maxEntries));
|
||||
}
|
||||
return TargetHistory(next);
|
||||
}
|
||||
|
||||
TargetHistory removeAt(int index) {
|
||||
if (index < 0 || index >= entries.length) {
|
||||
return this;
|
||||
}
|
||||
return TargetHistory([
|
||||
for (var i = 0; i < entries.length; i++)
|
||||
if (i != index) entries[i],
|
||||
]);
|
||||
}
|
||||
|
||||
TargetHistory clear() => empty;
|
||||
|
||||
String encode() => jsonEncode(entries.map((entry) => entry.toJson()).toList());
|
||||
|
||||
factory TargetHistory.decode(String raw) {
|
||||
if (raw.trim().isEmpty) {
|
||||
return empty;
|
||||
}
|
||||
final decoded = jsonDecode(raw);
|
||||
if (decoded is! List) {
|
||||
return empty;
|
||||
}
|
||||
return TargetHistory([
|
||||
for (final item in decoded)
|
||||
if (item is Map) TargetEntry.fromJson(Map<String, dynamic>.from(item)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user