HTTP 探测改为填写网址,缺本机引擎时立刻失败
HTTP 模式不再单独填端口。完整网址沿用其中的协议、端口和路径;只写主机名或 IP 时按 http 和 80 端口。超时默认改为 5000 毫秒。本机找不到或启动不了 netquality-reflector 时直接说明原因,并建议改用远程节点,不再记成一次全部失败。 Co-authored-by: yanjiu0721 <yanjiu0721@users.noreply.github.com>
This commit is contained in:
1 parent
846e40c023
commit
918ec8f190
20 files changed
+807
-131
No files matched your search
@@ -0,0 +1,103 @@
|
||||
// Copyright (C) 2026 言灸
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
/// An HTTP probe target. The separate port field is not used.
|
||||
class HttpTarget {
|
||||
const HttpTarget({
|
||||
required this.url,
|
||||
required this.host,
|
||||
required this.port,
|
||||
required this.scheme,
|
||||
});
|
||||
|
||||
/// Canonical absolute URL. Default ports are omitted.
|
||||
final String url;
|
||||
|
||||
/// Hostname or IP, without brackets.
|
||||
final String host;
|
||||
final int port;
|
||||
final String scheme;
|
||||
}
|
||||
|
||||
HttpTarget? parseHttpTarget(String raw) => readHttpTarget(raw).target;
|
||||
|
||||
String? httpTargetError(String raw) => readHttpTarget(raw).error;
|
||||
|
||||
({HttpTarget? target, String? error}) readHttpTarget(String raw) {
|
||||
final text = raw.trim();
|
||||
if (text.isEmpty) {
|
||||
return (target: null, error: '请填写目标地址');
|
||||
}
|
||||
if (text.contains('://')) {
|
||||
final uri = Uri.tryParse(text);
|
||||
if (uri == null) {
|
||||
return (target: null, error: _portOrUrlError(text));
|
||||
}
|
||||
if ((uri.scheme != 'http' && uri.scheme != 'https') || uri.host.isEmpty) {
|
||||
return (target: null, error: 'HTTP 目标需要是主机名或 http/https 网址');
|
||||
}
|
||||
return _fromUri(uri);
|
||||
}
|
||||
final cut = _splitCut(text);
|
||||
final hostport = cut < 0 ? text : text.substring(0, cut);
|
||||
final rest = cut < 0 ? '' : text.substring(cut);
|
||||
if (hostport.isEmpty) {
|
||||
return (target: null, error: 'HTTP 目标需要是主机名或 http/https 网址');
|
||||
}
|
||||
var bracketed = hostport;
|
||||
if (':'.allMatches(hostport).length >= 2 && !hostport.startsWith('[')) {
|
||||
bracketed = '[$hostport]';
|
||||
}
|
||||
final uri = Uri.tryParse('http://$bracketed$rest');
|
||||
if (uri == null || uri.host.isEmpty || uri.scheme != 'http') {
|
||||
return (target: null, error: _portOrUrlError(text));
|
||||
}
|
||||
return _fromUri(uri);
|
||||
}
|
||||
|
||||
({HttpTarget? target, String? error}) _fromUri(Uri uri) {
|
||||
final port = uri.hasPort ? uri.port : (uri.scheme == 'https' ? 443 : 80);
|
||||
if (port < 1 || port > 65535) {
|
||||
return (target: null, error: '端口需要在 1 到 65535 之间');
|
||||
}
|
||||
final built = Uri(
|
||||
scheme: uri.scheme,
|
||||
host: uri.host,
|
||||
port: port,
|
||||
path: uri.path.isEmpty ? '/' : uri.path,
|
||||
query: uri.hasQuery ? uri.query : null,
|
||||
fragment: uri.hasFragment ? uri.fragment : null,
|
||||
);
|
||||
return (
|
||||
target: HttpTarget(
|
||||
url: built.toString(),
|
||||
host: uri.host,
|
||||
port: port,
|
||||
scheme: uri.scheme,
|
||||
),
|
||||
error: null,
|
||||
);
|
||||
}
|
||||
|
||||
int _splitCut(String text) {
|
||||
final slash = text.indexOf('/');
|
||||
final query = text.indexOf('?');
|
||||
if (slash < 0) {
|
||||
return query;
|
||||
}
|
||||
if (query < 0) {
|
||||
return slash;
|
||||
}
|
||||
return slash < query ? slash : query;
|
||||
}
|
||||
|
||||
String _portOrUrlError(String text) {
|
||||
final match = RegExp(r':(\d+)(?=[/?#]|$)').firstMatch(text);
|
||||
if (match != null) {
|
||||
final port = int.tryParse(match.group(1)!);
|
||||
if (port == null || port < 1 || port > 65535) {
|
||||
return '端口需要在 1 到 65535 之间';
|
||||
}
|
||||
}
|
||||
return 'HTTP 目标需要是主机名或 http/https 网址';
|
||||
}
|
||||
@@ -23,20 +23,29 @@ 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;
|
||||
const nonHttpTimeoutMs = 1000;
|
||||
const httpTimeoutMs = 5000;
|
||||
|
||||
int timeoutDefaultFor(String profileId) =>
|
||||
profileId == 'http' ? httpTimeoutMs : nonHttpTimeoutMs;
|
||||
|
||||
/// An empty timeout, or one that is still the previous profile's default,
|
||||
/// follows the newly selected profile. A value the user typed stays.
|
||||
String timeoutAfterProfileChange({
|
||||
required String current,
|
||||
required int previousDefault,
|
||||
required int nextDefault,
|
||||
}) {
|
||||
final trimmed = current.trim();
|
||||
if (trimmed.isEmpty || int.tryParse(trimmed) == previousDefault) {
|
||||
return '$nextDefault';
|
||||
}
|
||||
return 443;
|
||||
return current;
|
||||
}
|
||||
|
||||
const portHelperText =
|
||||
|
||||
@@ -68,8 +68,7 @@ class ProbeProfile {
|
||||
id: 'http',
|
||||
label: 'HTTP',
|
||||
port: 443,
|
||||
blurb:
|
||||
'按 HTTP 请求测量。默认优先 HTTP/2,服务器不支持时降到 HTTP/1.1。强制的版本不支持就失败,不会偷偷降级。4xx 和 5xx 会显示状态码,不算丢包。',
|
||||
blurb: '按 HTTP 请求测量。目标填完整网址;只填主机名或 IP 时按 http,端口 80。默认优先 HTTP/2,服务器不支持时降到 HTTP/1.1。强制的版本不支持就失败,不会偷偷降级。4xx 和 5xx 会显示状态码,不算丢包。',
|
||||
rateLabel: '失败率',
|
||||
);
|
||||
static const customUdp = ProbeProfile(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../protocol/probe_packet.dart';
|
||||
import 'http_target.dart';
|
||||
import 'ip_family.dart';
|
||||
import 'probe_profile.dart';
|
||||
|
||||
@@ -66,7 +67,9 @@ class RemoteNode {
|
||||
baseUrl: confidential
|
||||
? ''
|
||||
: (json['baseUrl'] is String ? json['baseUrl'] as String : ''),
|
||||
visibility: json['visibility'] is String ? json['visibility'] as String : '',
|
||||
visibility: json['visibility'] is String
|
||||
? json['visibility'] as String
|
||||
: '',
|
||||
fromCenter: json['fromCenter'] == true,
|
||||
confidential: confidential,
|
||||
centerLinkId: json['centerLinkId'] is String
|
||||
@@ -88,11 +91,7 @@ class CenterLink {
|
||||
final String url;
|
||||
final String account;
|
||||
|
||||
Map<String, Object?> toJson() => {
|
||||
'id': id,
|
||||
'url': url,
|
||||
'account': account,
|
||||
};
|
||||
Map<String, Object?> toJson() => {'id': id, 'url': url, 'account': account};
|
||||
|
||||
factory CenterLink.fromJson(Map<String, dynamic> json) {
|
||||
return CenterLink(
|
||||
@@ -185,6 +184,10 @@ class SessionConfig {
|
||||
|
||||
ProbeProfile get profile => ProbeProfile.byId(profileId);
|
||||
|
||||
/// Parsed HTTP target. Null for other profiles, or when the text is invalid.
|
||||
HttpTarget? get httpTarget =>
|
||||
profileId == 'http' ? parseHttpTarget(host) : null;
|
||||
|
||||
RemoteNode? get node {
|
||||
for (final item in nodes) {
|
||||
if (item.id == nodeId) {
|
||||
@@ -195,7 +198,15 @@ class SessionConfig {
|
||||
}
|
||||
|
||||
String? validate() {
|
||||
final family = familyRefusal(host, v4: allowIPv4, v6: allowIPv6);
|
||||
final http = profileId == 'http' ? readHttpTarget(host) : null;
|
||||
if (http != null && http.error != null) {
|
||||
return http.error;
|
||||
}
|
||||
final family = familyRefusal(
|
||||
http?.target?.host ?? host,
|
||||
v4: allowIPv4,
|
||||
v6: allowIPv6,
|
||||
);
|
||||
if (family != null) {
|
||||
return family;
|
||||
}
|
||||
@@ -209,7 +220,7 @@ class SessionConfig {
|
||||
return resolveFamily.replaceFirst('目标', '指定解析');
|
||||
}
|
||||
}
|
||||
if (host.trim().isEmpty) {
|
||||
if (profileId != 'http' && host.trim().isEmpty) {
|
||||
return '请填写目标地址';
|
||||
}
|
||||
if (profileId == 'http') {
|
||||
@@ -224,8 +235,7 @@ class SessionConfig {
|
||||
if (!versions.contains(httpVersion)) {
|
||||
return 'HTTP 版本需要是自动、1.1、2 或 3';
|
||||
}
|
||||
}
|
||||
if (port < 1 || port > 65535) {
|
||||
} else if (port < 1 || port > 65535) {
|
||||
return '端口需要在 1 到 65535 之间';
|
||||
}
|
||||
final minInterval = remote ? 200 : 100;
|
||||
@@ -333,11 +343,15 @@ class SessionConfig {
|
||||
dnsName: json['dnsName'] is String
|
||||
? json['dnsName'] as String
|
||||
: defaults.dnsName,
|
||||
payloadHex: json['payloadHex'] is String ? json['payloadHex'] as String : '',
|
||||
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,
|
||||
autoUpdate: json['autoUpdate'] is bool
|
||||
? json['autoUpdate'] as bool
|
||||
: true,
|
||||
httpVersion: json['httpVersion'] is String
|
||||
? json['httpVersion'] as String
|
||||
: 'auto',
|
||||
|
||||
@@ -34,11 +34,14 @@ class TargetEntry {
|
||||
}
|
||||
|
||||
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';
|
||||
if (profileId == 'http') {
|
||||
final where = httpUrl.trim().isNotEmpty ? httpUrl.trim() : host.trim();
|
||||
final methodText = method.trim().isNotEmpty
|
||||
? ' ${method.trim().toUpperCase()}'
|
||||
: '';
|
||||
return '$where · HTTP$methodText';
|
||||
}
|
||||
return '${host.trim()}:$port · $profileId';
|
||||
}
|
||||
|
||||
Map<String, Object?> toJson() => {
|
||||
@@ -94,7 +97,8 @@ class TargetHistory {
|
||||
|
||||
TargetHistory clear() => empty;
|
||||
|
||||
String encode() => jsonEncode(entries.map((entry) => entry.toJson()).toList());
|
||||
String encode() =>
|
||||
jsonEncode(entries.map((entry) => entry.toJson()).toList());
|
||||
|
||||
factory TargetHistory.decode(String raw) {
|
||||
if (raw.trim().isEmpty) {
|
||||
|
||||
@@ -7,9 +7,32 @@ import 'dart:io';
|
||||
import '../metrics/sample_book.dart';
|
||||
|
||||
const helperMissingNote =
|
||||
'本机 HTTP 探测使用和节点相同的 Go 引擎。请把 netquality-reflector 放在程序旁边,或设置环境变量 NQ_PROBE_HELPER。远程节点不受影响。';
|
||||
'本机 HTTP 探测需要 Go 程序 netquality-reflector,现在没有找到,所以探测没有开始。请把探测来源改成「远程节点」。桌面端也可以把 netquality-reflector 放在程序旁边,或设置环境变量 NQ_PROBE_HELPER。';
|
||||
|
||||
const helperStartFailedNote =
|
||||
'本机 HTTP 探测找到了 netquality-reflector,但没有启动成功,所以探测没有开始。请把探测来源改成「远程节点」。桌面端也可以检查这个程序能否运行,或改用环境变量 NQ_PROBE_HELPER。';
|
||||
|
||||
/// Thrown before any sample is recorded when the local HTTP engine cannot run.
|
||||
class LocalHttpHelperException implements Exception {
|
||||
const LocalHttpHelperException(this.message);
|
||||
|
||||
final String message;
|
||||
}
|
||||
|
||||
bool isLocalHttpHelperFailure(Outcome outcome) {
|
||||
return outcome.status == Outcome.error &&
|
||||
(outcome.note == helperMissingNote ||
|
||||
outcome.note == helperStartFailedNote);
|
||||
}
|
||||
|
||||
/// Tests set this to skip the search next to the executable.
|
||||
String? Function()? locateProbeHelperOverride;
|
||||
|
||||
String? locateProbeHelper() {
|
||||
final override = locateProbeHelperOverride;
|
||||
if (override != null) {
|
||||
return override();
|
||||
}
|
||||
final env = Platform.environment['NQ_PROBE_HELPER'];
|
||||
if (env != null && env.isNotEmpty && File(env).existsSync()) {
|
||||
return env;
|
||||
@@ -27,6 +50,23 @@ String? locateProbeHelper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Null when the local Go helper can be started. Otherwise a Chinese reason
|
||||
/// that already tells the user to switch the source to a remote node.
|
||||
Future<String?> localHttpBlockedReason({String? binary}) async {
|
||||
final path = binary ?? locateProbeHelper();
|
||||
if (path == null || path.isEmpty || !File(path).existsSync()) {
|
||||
return helperMissingNote;
|
||||
}
|
||||
try {
|
||||
final process = await Process.start(path, const ['-mode', 'helper']);
|
||||
process.kill();
|
||||
process.exitCode.ignore();
|
||||
return null;
|
||||
} catch (_) {
|
||||
return helperStartFailedNote;
|
||||
}
|
||||
}
|
||||
|
||||
Outcome outcomeFromHelper(String line) {
|
||||
try {
|
||||
final decoded = jsonDecode(line);
|
||||
@@ -107,14 +147,23 @@ class HttpHelperSession {
|
||||
return null;
|
||||
}
|
||||
final path = binary ?? locateProbeHelper();
|
||||
if (path == null) {
|
||||
if (path == null || path.isEmpty || !File(path).existsSync()) {
|
||||
return const Outcome(
|
||||
status: Outcome.error,
|
||||
kind: Outcome.query,
|
||||
note: helperMissingNote,
|
||||
);
|
||||
}
|
||||
final process = await Process.start(path, const ['-mode', 'helper']);
|
||||
final Process process;
|
||||
try {
|
||||
process = await Process.start(path, const ['-mode', 'helper']);
|
||||
} catch (_) {
|
||||
return const Outcome(
|
||||
status: Outcome.error,
|
||||
kind: Outcome.query,
|
||||
note: helperStartFailedNote,
|
||||
);
|
||||
}
|
||||
_process = process;
|
||||
process.stdout
|
||||
.transform(utf8.decoder)
|
||||
|
||||
@@ -11,6 +11,7 @@ import '../models/probe_profile.dart';
|
||||
import '../models/session_config.dart';
|
||||
import '../ui/address_text.dart';
|
||||
import 'endpoint_picker.dart';
|
||||
import 'http_helper.dart';
|
||||
import 'probe_loop.dart';
|
||||
import 'remote_client.dart';
|
||||
|
||||
@@ -226,6 +227,13 @@ class ProbeController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
if (!config.remote && config.profileId == 'http') {
|
||||
final helperProblem = await localHttpBlockedReason();
|
||||
if (helperProblem != null) {
|
||||
_rejectSetup(helperProblem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
await stop();
|
||||
_nodeToken = nodeToken;
|
||||
_remoteMode = config.remote;
|
||||
@@ -237,6 +245,9 @@ class ProbeController extends ChangeNotifier {
|
||||
..start();
|
||||
final source = config.remote ? (config.node?.name ?? '远程节点') : '本机';
|
||||
final profile = ProbeProfile.byId(config.profileId);
|
||||
final httpTarget = config.httpTarget;
|
||||
final target = httpTarget?.url ?? config.host.trim();
|
||||
final port = httpTarget?.port ?? config.port;
|
||||
view = ProbeView(
|
||||
running: true,
|
||||
phase: '探测中',
|
||||
@@ -250,7 +261,7 @@ class ProbeController extends ChangeNotifier {
|
||||
sessionId: session,
|
||||
profileId: config.profileId,
|
||||
elapsed: Duration.zero,
|
||||
targetHost: '${config.host.trim()}:${config.port}',
|
||||
targetHost: httpTarget?.url ?? '$target:$port',
|
||||
profileLabel: profile.label,
|
||||
startedAt: _startedAt,
|
||||
);
|
||||
@@ -270,7 +281,9 @@ class ProbeController extends ChangeNotifier {
|
||||
baseUrl = link.url;
|
||||
token = nodeToken;
|
||||
}
|
||||
if (config.profileId == 'http' || !config.allowIPv4 || !config.allowIPv6) {
|
||||
if (config.profileId == 'http' ||
|
||||
!config.allowIPv4 ||
|
||||
!config.allowIPv6) {
|
||||
if (!selected.confidential) {
|
||||
final info = await fetchNodeInfo(baseUrl);
|
||||
final upgrade = remoteUpgradeMessage(
|
||||
@@ -290,8 +303,8 @@ class ProbeController extends ChangeNotifier {
|
||||
baseUrl: baseUrl,
|
||||
nodeToken: token,
|
||||
body: ProbeBody(
|
||||
target: config.host.trim(),
|
||||
port: config.port,
|
||||
target: target,
|
||||
port: port,
|
||||
profile: config.profileId,
|
||||
intervalMs: config.intervalMs,
|
||||
timeoutMs: config.timeoutMs,
|
||||
@@ -347,8 +360,8 @@ class ProbeController extends ChangeNotifier {
|
||||
_local = loop;
|
||||
await loop.run(
|
||||
request: ProbeRequest(
|
||||
host: config.host.trim(),
|
||||
port: config.port,
|
||||
host: target,
|
||||
port: port,
|
||||
profileId: config.profileId,
|
||||
interval: Duration(milliseconds: config.intervalMs),
|
||||
timeout: Duration(milliseconds: config.timeoutMs),
|
||||
@@ -373,6 +386,8 @@ class ProbeController extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
_finish(generation, '已停止');
|
||||
} on LocalHttpHelperException catch (error) {
|
||||
_rejectSetup(error.message, generation: generation);
|
||||
} on RemoteException catch (error) {
|
||||
_finish(generation, '出错', banner: error.message);
|
||||
} on Object {
|
||||
@@ -416,6 +431,27 @@ class ProbeController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void _rejectSetup(String message, {int? generation}) {
|
||||
if (generation != null && generation != _token) {
|
||||
return;
|
||||
}
|
||||
_clock.stop();
|
||||
_tick?.cancel();
|
||||
view = view.copyWith(
|
||||
running: false,
|
||||
phase: '无法开始',
|
||||
banner: message,
|
||||
note: '',
|
||||
detail: const {},
|
||||
summary: ProbeSummary.empty,
|
||||
samples: const [],
|
||||
elapsed: Duration.zero,
|
||||
clearReport: true,
|
||||
clearTrying: true,
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _finish(int generation, String phase, {String? banner}) {
|
||||
if (generation != _token || !view.running) {
|
||||
return;
|
||||
|
||||
@@ -119,6 +119,11 @@ class ProbeLoop {
|
||||
if (!countsAfterStop(outcome, cancelled: cancelled())) {
|
||||
break;
|
||||
}
|
||||
if (request.profileId == 'http' &&
|
||||
outcome != null &&
|
||||
isLocalHttpHelperFailure(outcome)) {
|
||||
throw LocalHttpHelperException(outcome.note);
|
||||
}
|
||||
var commit = <Outcome>[outcome!];
|
||||
if (_usesDatagram(request.profileId) && _picker != null) {
|
||||
_ledger ??= SelectionLedger(_picker!.candidates.length);
|
||||
|
||||
+119
-68
@@ -67,12 +67,13 @@ class _HomePageState extends State<HomePage> {
|
||||
var _ready = false;
|
||||
var _idSeq = 0;
|
||||
var _formEpoch = 0;
|
||||
String? _portBeforeHttp;
|
||||
String? _profileBeforeHttp;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.addListener(_rebuild);
|
||||
_host.addListener(_onHostChanged);
|
||||
_load();
|
||||
}
|
||||
|
||||
@@ -123,20 +124,6 @@ class _HomePageState extends State<HomePage> {
|
||||
}
|
||||
}
|
||||
|
||||
void _onHostChanged() {
|
||||
if (_profileId != 'http') {
|
||||
return;
|
||||
}
|
||||
final current = int.tryParse(_port.text.trim());
|
||||
if (_port.text.trim().isNotEmpty && current != 80 && current != 443) {
|
||||
return;
|
||||
}
|
||||
final next = '${httpDefaultPort(_host.text)}';
|
||||
if (_port.text != next) {
|
||||
_port.text = next;
|
||||
}
|
||||
}
|
||||
|
||||
void _rebuild() {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
@@ -148,7 +135,6 @@ class _HomePageState extends State<HomePage> {
|
||||
unawaited(_controller.stop());
|
||||
unawaited(_persist());
|
||||
_controller.removeListener(_rebuild);
|
||||
_host.removeListener(_onHostChanged);
|
||||
_controller.dispose();
|
||||
for (final field in [
|
||||
_host,
|
||||
@@ -212,12 +198,13 @@ class _HomePageState extends State<HomePage> {
|
||||
await _persist();
|
||||
final config = _config();
|
||||
if (config.validate() == null) {
|
||||
final httpTarget = config.httpTarget;
|
||||
_history = _history.add(
|
||||
TargetEntry(
|
||||
host: config.host,
|
||||
port: config.port,
|
||||
host: httpTarget?.url ?? config.host,
|
||||
port: httpTarget?.port ?? config.port,
|
||||
profileId: config.profileId,
|
||||
httpUrl: config.profileId == 'http' ? config.host : '',
|
||||
httpUrl: httpTarget?.url ?? '',
|
||||
method: config.profileId == 'http' ? config.httpMethod : '',
|
||||
savedAtMs: DateTime.now().millisecondsSinceEpoch,
|
||||
),
|
||||
@@ -241,23 +228,42 @@ class _HomePageState extends State<HomePage> {
|
||||
}
|
||||
|
||||
void _changeProfile(String? id) {
|
||||
if (id == null) {
|
||||
if (id == null || id == _profileId) {
|
||||
return;
|
||||
}
|
||||
final previous = ProbeProfile.byId(_profileId);
|
||||
final next = ProbeProfile.byId(id);
|
||||
final currentPort = int.tryParse(_port.text.trim());
|
||||
var previousDefault = previous.port;
|
||||
if (_profileId == 'http' && (currentPort == 80 || currentPort == 443)) {
|
||||
previousDefault = currentPort!;
|
||||
}
|
||||
final nextDefault = id == 'http' ? httpDefaultPort(_host.text) : next.port;
|
||||
setState(() {
|
||||
_port.text = portAfterProfileChange(
|
||||
current: _port.text,
|
||||
previousDefault: previousDefault,
|
||||
nextDefault: nextDefault,
|
||||
_timeout.text = timeoutAfterProfileChange(
|
||||
current: _timeout.text,
|
||||
previousDefault: timeoutDefaultFor(_profileId),
|
||||
nextDefault: timeoutDefaultFor(id),
|
||||
);
|
||||
if (id == 'http') {
|
||||
_portBeforeHttp = _port.text;
|
||||
_profileBeforeHttp = _profileId;
|
||||
} else if (_profileId == 'http' &&
|
||||
_portBeforeHttp != null &&
|
||||
_profileBeforeHttp != null) {
|
||||
_port.text = portAfterProfileChange(
|
||||
current: _portBeforeHttp!,
|
||||
previousDefault: ProbeProfile.byId(_profileBeforeHttp!).port,
|
||||
nextDefault: next.port,
|
||||
);
|
||||
_portBeforeHttp = null;
|
||||
_profileBeforeHttp = null;
|
||||
} else {
|
||||
final currentPort = int.tryParse(_port.text.trim());
|
||||
var previousDefault = previous.port;
|
||||
if (_profileId == 'http' && (currentPort == 80 || currentPort == 443)) {
|
||||
previousDefault = currentPort!;
|
||||
}
|
||||
_port.text = portAfterProfileChange(
|
||||
current: _port.text,
|
||||
previousDefault: previousDefault,
|
||||
nextDefault: next.port,
|
||||
);
|
||||
}
|
||||
_profileId = id;
|
||||
});
|
||||
}
|
||||
@@ -312,30 +318,26 @@ class _HomePageState extends State<HomePage> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_pair(
|
||||
wide,
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: _field(_host, '目标地址', '域名、IP,或 http(s) 地址'),
|
||||
),
|
||||
IconButton(
|
||||
key: const Key('target-history'),
|
||||
tooltip: '最近目标',
|
||||
onPressed: view.running ? null : _showHistory,
|
||||
icon: const Icon(Icons.history),
|
||||
),
|
||||
],
|
||||
if (profile.id == 'http')
|
||||
_hostRow(
|
||||
view.running,
|
||||
'https://example.com:2025/ 或 example.com',
|
||||
helper:
|
||||
'只填主机名或 IP 时按 http:// 和端口 80。完整网址使用其中的协议、端口和路径。',
|
||||
fieldKey: const Key('target-field'),
|
||||
)
|
||||
else
|
||||
_pair(
|
||||
wide,
|
||||
_hostRow(view.running, '域名、IP,或 http(s) 地址'),
|
||||
_field(
|
||||
_port,
|
||||
'端口',
|
||||
portHint(profile),
|
||||
fieldKey: const Key('port-field'),
|
||||
helper: portHelperText,
|
||||
),
|
||||
),
|
||||
_field(
|
||||
_port,
|
||||
'端口',
|
||||
portHint(profile),
|
||||
fieldKey: const Key('port-field'),
|
||||
helper: portHelperText,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
key: _formEpoch == 0
|
||||
@@ -373,7 +375,15 @@ class _HomePageState extends State<HomePage> {
|
||||
'间隔(毫秒)',
|
||||
_remote ? '至少 200' : '至少 100',
|
||||
),
|
||||
_field(_timeout, '超时(毫秒)', '100–15000'),
|
||||
_field(
|
||||
_timeout,
|
||||
'超时(毫秒)',
|
||||
'100–15000',
|
||||
fieldKey: const Key('timeout-field'),
|
||||
helper: profile.id == 'http'
|
||||
? 'HTTP 默认 5000 毫秒'
|
||||
: null,
|
||||
),
|
||||
),
|
||||
if (profile.needsPacketSize) ...[
|
||||
const SizedBox(height: 12),
|
||||
@@ -575,11 +585,7 @@ class _HomePageState extends State<HomePage> {
|
||||
: (value) => setState(() => _httpVersion = value ?? 'auto'),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_field(
|
||||
_httpResolve,
|
||||
'指定解析',
|
||||
'可选。Host 和 SNI 仍用上面的地址,连接改走这里的 IP 或主机名',
|
||||
),
|
||||
_field(_httpResolve, '指定解析', '可选。Host 和 SNI 仍用上面的地址,连接改走这里的 IP 或主机名'),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
key: ValueKey('http-method-$_httpMethod-$_formEpoch'),
|
||||
@@ -739,15 +745,48 @@ class _HomePageState extends State<HomePage> {
|
||||
void _applyHistory(TargetEntry entry) {
|
||||
setState(() {
|
||||
_formEpoch += 1;
|
||||
_portBeforeHttp = null;
|
||||
_profileBeforeHttp = null;
|
||||
_profileId = entry.profileId;
|
||||
_host.text = entry.httpUrl.isNotEmpty ? entry.httpUrl : entry.host;
|
||||
_host.text = entry.profileId == 'http' && entry.httpUrl.isNotEmpty
|
||||
? entry.httpUrl
|
||||
: entry.host;
|
||||
_port.text = '${entry.port}';
|
||||
if (entry.profileId == 'http' && entry.method.isNotEmpty) {
|
||||
_httpMethod = entry.method;
|
||||
}
|
||||
if (entry.profileId == 'http') {
|
||||
final current = int.tryParse(_timeout.text.trim());
|
||||
if (current == null || current == timeoutDefaultFor('nq-tcp')) {
|
||||
_timeout.text = '${timeoutDefaultFor('http')}';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Widget _hostRow(bool running, String hint, {String? helper, Key? fieldKey}) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: _field(
|
||||
_host,
|
||||
'目标地址',
|
||||
hint,
|
||||
helper: helper,
|
||||
fieldKey: fieldKey,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: const Key('target-history'),
|
||||
tooltip: '最近目标',
|
||||
onPressed: running ? null : _showHistory,
|
||||
icon: const Icon(Icons.history),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _newId() {
|
||||
_idSeq += 1;
|
||||
return '${DateTime.now().microsecondsSinceEpoch}-$_idSeq';
|
||||
@@ -760,13 +799,18 @@ class _HomePageState extends State<HomePage> {
|
||||
}
|
||||
var link = added.link;
|
||||
for (final existing in _centers) {
|
||||
if (existing.url == added.link.url && existing.account == added.link.account) {
|
||||
if (existing.url == added.link.url &&
|
||||
existing.account == added.link.account) {
|
||||
link = existing;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await _vault.write(centerTokenKey(link.id), added.token);
|
||||
await _applyCatalog(link, added.catalog, '已添加 ${added.catalog.servers.length} 台服务器');
|
||||
await _applyCatalog(
|
||||
link,
|
||||
added.catalog,
|
||||
'已添加 ${added.catalog.servers.length} 台服务器',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _refreshCenter(CenterLink link) async {
|
||||
@@ -789,7 +833,10 @@ class _HomePageState extends State<HomePage> {
|
||||
}
|
||||
await _vault.delete(centerTokenKey(link.id));
|
||||
setState(() {
|
||||
_centers = [for (final item in _centers) if (item.id != link.id) item];
|
||||
_centers = [
|
||||
for (final item in _centers)
|
||||
if (item.id != link.id) item,
|
||||
];
|
||||
_nodes = [
|
||||
for (final node in _nodes)
|
||||
if (node.centerLinkId != link.id) node,
|
||||
@@ -802,7 +849,11 @@ class _HomePageState extends State<HomePage> {
|
||||
await _persist();
|
||||
}
|
||||
|
||||
Future<void> _applyCatalog(CenterLink link, Catalog catalog, String hint) async {
|
||||
Future<void> _applyCatalog(
|
||||
CenterLink link,
|
||||
Catalog catalog,
|
||||
String hint,
|
||||
) async {
|
||||
final before = {
|
||||
for (final node in _nodes)
|
||||
if (node.centerLinkId == link.id) node.id,
|
||||
@@ -843,7 +894,9 @@ class _HomePageState extends State<HomePage> {
|
||||
for (final node in _nodes)
|
||||
if (node.centerLinkId == link.id) node,
|
||||
];
|
||||
final title = link.account.isEmpty ? link.url : '${link.account} · ${link.url}';
|
||||
final title = link.account.isEmpty
|
||||
? link.url
|
||||
: '${link.account} · ${link.url}';
|
||||
return ExpansionTile(
|
||||
tilePadding: EdgeInsets.zero,
|
||||
title: Text(title, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
@@ -1164,9 +1217,7 @@ class _NodeDialogState extends State<_NodeDialog> {
|
||||
'${node.name} · ${visibilityLabel(node.visibility)}',
|
||||
),
|
||||
subtitle: Text(
|
||||
node.confidential
|
||||
? '地址由中心代为连接,本机不保存。'
|
||||
: node.baseUrl,
|
||||
node.confidential ? '地址由中心代为连接,本机不保存。' : node.baseUrl,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
||||
@@ -63,7 +63,7 @@ class MetricGuidePage extends StatelessWidget {
|
||||
),
|
||||
_Section(
|
||||
title: 'HTTP',
|
||||
body: 'HTTP 探测记下 DNS、连接、TLS、首字节和总时间,以及状态码、最终地址和实际用到的 HTTP 版本(1.1、2 或 3)。曲线上的延迟是总时间。已经收到的响应算成功,4xx 和 5xx 只显示状态码,不叫丢包,也不算进失败率。连不上或强制的版本不被支持,才算失败。\n\n默认先试 HTTP/2,不行再降到 1.1。选了「仅 HTTP/1.1」「仅 HTTP/2」或「仅 HTTP/3」时,服务器不支持就失败,不会悄悄换一种。指定解析只改连接走的地址,Host 和 SNI 仍用目标网址,用来看 CDN。它不是把 1.1.1.1 当成 DNS 服务器。\n\nHTTP/3 的连接和 TLS 是同一次 QUIC 握手,这两项时间相同。本机探测和节点用的是同一个 Go 引擎。桌面端需要把 netquality-reflector 放在程序旁边,或设置 NQ_PROBE_HELPER。Android 上如果系统不允许从应用目录启动这个程序,本机 HTTP 会说明缺引擎;远程节点不受影响。',
|
||||
body: 'HTTP 探测记下 DNS、连接、TLS、首字节和总时间,以及状态码、最终地址和实际用到的 HTTP 版本(1.1、2 或 3)。曲线上的延迟是总时间。已经收到的响应算成功,4xx 和 5xx 只显示状态码,不叫丢包,也不算进失败率。连不上或强制的版本不被支持,才算失败。\n\n默认先试 HTTP/2,不行再降到 1.1。选了「仅 HTTP/1.1」「仅 HTTP/2」或「仅 HTTP/3」时,服务器不支持就失败,不会悄悄换一种。指定解析只改连接走的地址,Host 和 SNI 仍用目标网址,用来看 CDN。它不是把 1.1.1.1 当成 DNS 服务器。\n\nHTTP/3 的连接和 TLS 是同一次 QUIC 握手,这两项时间相同。目标填完整网址,例如 https://example.com:2025/path,也可以只填主机名。只填主机名或 IP 时按 http://主机/,端口是 80,不会改成 https 或 443。网址里写了端口、路径或查询,就按网址本身探测,HTTP 模式不再单独填端口。超时默认 5000 毫秒。\n\n本机探测和节点用的是同一个 Go 引擎。桌面端需要把 netquality-reflector 放在程序旁边,或设置 NQ_PROBE_HELPER。找不到或启动不了时,探测不会开始,也不会记成一次全部失败;界面会说明原因,并建议把探测来源改成远程节点。Android 安装包不带这个程序,本机 HTTP 会直接这样提示。远程节点不受影响。',
|
||||
),
|
||||
_Section(
|
||||
title: '停止以后',
|
||||
|
||||
Reference in new issue
Block a user