fix: url test issues, avoid multiple test, and change outbound on test
This commit is contained in:
@@ -40,20 +40,16 @@ class IpInfoNotifier extends _$IpInfoNotifier with AppLogger {
|
|||||||
// );
|
// );
|
||||||
if (!_forceCheck && !serviceRunning) {
|
if (!_forceCheck && !serviceRunning) {
|
||||||
throw const ServiceNotRunning();
|
throw const ServiceNotRunning();
|
||||||
} else if ((_idle && !_forceCheck) ||
|
} else if ((_idle && !_forceCheck) || (!_forceCheck && serviceRunning && !autoCheck)) {
|
||||||
(!_forceCheck && serviceRunning && !autoCheck)) {
|
|
||||||
throw const UnknownIp();
|
throw const UnknownIp();
|
||||||
}
|
}
|
||||||
|
|
||||||
_forceCheck = false;
|
_forceCheck = false;
|
||||||
final info = await ref
|
final info = await ref.watch(proxyRepositoryProvider).getCurrentIpInfo(cancelToken).getOrElse(
|
||||||
.watch(proxyRepositoryProvider)
|
|
||||||
.getCurrentIpInfo(cancelToken)
|
|
||||||
.getOrElse(
|
|
||||||
(err) {
|
(err) {
|
||||||
loggy.warning("error getting proxy ip info", err, StackTrace.current);
|
loggy.warning("error getting proxy ip info", err, StackTrace.current);
|
||||||
// throw err; //hiddify: remove exception to be logged
|
throw err; //hiddify: remove exception to be logged
|
||||||
throw const UnknownIp();
|
//throw const UnknownIp();
|
||||||
},
|
},
|
||||||
).run();
|
).run();
|
||||||
|
|
||||||
@@ -93,11 +89,7 @@ class ActiveProxyNotifier extends _$ActiveProxyNotifier with AppLogger {
|
|||||||
throw const ServiceNotRunning();
|
throw const ServiceNotRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
yield* ref
|
yield* ref.watch(proxyRepositoryProvider).watchActiveProxies().map((event) => event.getOrElse((l) => throw l)).map((event) => event.firstOrNull!.items.first);
|
||||||
.watch(proxyRepositoryProvider)
|
|
||||||
.watchActiveProxies()
|
|
||||||
.map((event) => event.getOrElse((l) => throw l))
|
|
||||||
.map((event) => event.firstOrNull!.items.first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final _urlTestThrottler = Throttler(const Duration(seconds: 2));
|
final _urlTestThrottler = Throttler(const Duration(seconds: 2));
|
||||||
@@ -106,17 +98,9 @@ class ActiveProxyNotifier extends _$ActiveProxyNotifier with AppLogger {
|
|||||||
var groupTag = groupTag_;
|
var groupTag = groupTag_;
|
||||||
_urlTestThrottler(
|
_urlTestThrottler(
|
||||||
() async {
|
() async {
|
||||||
loggy.debug("testing group: [$groupTag]");
|
|
||||||
if (!["auto", "select"].contains(groupTag)) {
|
|
||||||
loggy.warning("only proxy group can do url test");
|
|
||||||
groupTag = "select";
|
|
||||||
}
|
|
||||||
if (state case AsyncData()) {
|
if (state case AsyncData()) {
|
||||||
await ref.read(hapticServiceProvider.notifier).lightImpact();
|
await ref.read(hapticServiceProvider.notifier).lightImpact();
|
||||||
await ref
|
await ref.read(proxyRepositoryProvider).urlTest(groupTag).getOrElse((err) {
|
||||||
.read(proxyRepositoryProvider)
|
|
||||||
.urlTest(groupTag)
|
|
||||||
.getOrElse((err) {
|
|
||||||
loggy.warning("error testing group", err);
|
loggy.warning("error testing group", err);
|
||||||
throw err;
|
throw err;
|
||||||
}).run();
|
}).run();
|
||||||
|
|||||||
@@ -19,9 +19,7 @@ abstract interface class ProxyRepository {
|
|||||||
TaskEither<ProxyFailure, Unit> urlTest(String groupTag);
|
TaskEither<ProxyFailure, Unit> urlTest(String groupTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProxyRepositoryImpl
|
class ProxyRepositoryImpl with ExceptionHandler, InfraLogger implements ProxyRepository {
|
||||||
with ExceptionHandler, InfraLogger
|
|
||||||
implements ProxyRepository {
|
|
||||||
ProxyRepositoryImpl({
|
ProxyRepositoryImpl({
|
||||||
required this.singbox,
|
required this.singbox,
|
||||||
required this.client,
|
required this.client,
|
||||||
@@ -103,10 +101,7 @@ class ProxyRepositoryImpl
|
|||||||
String outboundTag,
|
String outboundTag,
|
||||||
) {
|
) {
|
||||||
return exceptionHandler(
|
return exceptionHandler(
|
||||||
() => singbox
|
() => singbox.selectOutbound(groupTag, outboundTag).mapLeft(ProxyUnexpectedFailure.new).run(),
|
||||||
.selectOutbound(groupTag, outboundTag)
|
|
||||||
.mapLeft(ProxyUnexpectedFailure.new)
|
|
||||||
.run(),
|
|
||||||
ProxyUnexpectedFailure.new,
|
ProxyUnexpectedFailure.new,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -114,18 +109,19 @@ class ProxyRepositoryImpl
|
|||||||
@override
|
@override
|
||||||
TaskEither<ProxyFailure, Unit> urlTest(String groupTag_) {
|
TaskEither<ProxyFailure, Unit> urlTest(String groupTag_) {
|
||||||
var groupTag = groupTag_;
|
var groupTag = groupTag_;
|
||||||
if (!["auto", "select"].contains(groupTag)) {
|
loggy.debug("testing group: [$groupTag]");
|
||||||
loggy.warning("only proxy group can do url test");
|
if (!["auto"].contains(groupTag)) {
|
||||||
groupTag = "select";
|
loggy.warning("only auto proxy group can do url test. Please change go code if you want");
|
||||||
}
|
}
|
||||||
|
groupTag = "auto";
|
||||||
|
|
||||||
return exceptionHandler(
|
return exceptionHandler(
|
||||||
() => singbox.urlTest(groupTag).mapLeft(ProxyUnexpectedFailure.new).run(),
|
() => singbox.urlTest(groupTag).mapLeft(ProxyUnexpectedFailure.new).run(),
|
||||||
ProxyUnexpectedFailure.new,
|
ProxyUnexpectedFailure.new,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, IpInfo Function(Map<String, dynamic> response)>
|
static final Map<String, IpInfo Function(Map<String, dynamic> response)> _ipInfoSources = {
|
||||||
_ipInfoSources = {
|
|
||||||
// "https://geolocation-db.com/json/": IpInfo.fromGeolocationDbComJson, //bug response is not json
|
// "https://geolocation-db.com/json/": IpInfo.fromGeolocationDbComJson, //bug response is not json
|
||||||
"https://ipwho.is/": IpInfo.fromIpwhoIsJson,
|
"https://ipwho.is/": IpInfo.fromIpwhoIsJson,
|
||||||
"https://api.ip.sb/geoip/": IpInfo.fromIpSbJson,
|
"https://api.ip.sb/geoip/": IpInfo.fromIpSbJson,
|
||||||
@@ -144,6 +140,7 @@ class ProxyRepositoryImpl
|
|||||||
final response = await client.get<Map<String, dynamic>>(
|
final response = await client.get<Map<String, dynamic>>(
|
||||||
source.key,
|
source.key,
|
||||||
cancelToken: cancelToken,
|
cancelToken: cancelToken,
|
||||||
|
proxyOnly: true,
|
||||||
);
|
);
|
||||||
if (response.statusCode == 200 && response.data != null) {
|
if (response.statusCode == 200 && response.data != null) {
|
||||||
return source.value(response.data!);
|
return source.value(response.data!);
|
||||||
|
|||||||
2
libcore
2
libcore
Submodule libcore updated: 5098951147...e9a3396024
Reference in New Issue
Block a user