From b16295bee525d7add68c2a322fb169f7ecc0ccf2 Mon Sep 17 00:00:00 2001 From: Hiddify Date: Wed, 21 Feb 2024 20:03:20 +0100 Subject: [PATCH] new: add warp fake packet delay, add warp detour, add new ipinfo api --- .github/workflows/build.yml | 3 +- assets/translations/strings_en.i18n.json | 3 +- lib/core/http_client/dio_http_client.dart | 8 +++- .../model/config_option_entity.dart | 8 +++- .../overview/warp_options_widgets.dart | 19 +++++++++ lib/features/proxy/data/proxy_repository.dart | 2 + lib/features/proxy/model/ip_info_entity.dart | 42 +++++++++++++++++++ lib/singbox/model/singbox_config_option.dart | 1 + libcore | 2 +- 9 files changed, 83 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85a7d8b2..ba2a05e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,7 +75,8 @@ jobs: targets: dmg,pkg runs-on: ${{ matrix.os }} - if: matrix.platform!='android-aab' || ${{ inputs.upload-artifact && inputs.tag-name != 'draft' }} + if: matrix.platform != 'android-aab' || ${{ inputs.upload-artifact && inputs.tag-name != 'draft' }} + steps: - name: checkout uses: actions/checkout@v3 diff --git a/assets/translations/strings_en.i18n.json b/assets/translations/strings_en.i18n.json index 6e408ba1..464fe4f0 100644 --- a/assets/translations/strings_en.i18n.json +++ b/assets/translations/strings_en.i18n.json @@ -291,7 +291,8 @@ "warpLicenseKey": "License Key", "warpCleanIp": "Clean IP", "warpPort": "Port", - "warpNoise": "Noise" + "warpNoise": "Noise Count", + "warpNoiseDelay": "Noise Delay" }, "geoAssets": { "pageTitle": "Routing Assets", diff --git a/lib/core/http_client/dio_http_client.dart b/lib/core/http_client/dio_http_client.dart index 533ec17b..9e633523 100644 --- a/lib/core/http_client/dio_http_client.dart +++ b/lib/core/http_client/dio_http_client.dart @@ -77,7 +77,11 @@ class DioHttpClient with InfraLogger { url, path, cancelToken: cancelToken, - options: _options(url, userAgent: userAgent, credentials: credentials), + options: _options( + url, + userAgent: userAgent, + credentials: credentials, + ), ); } @@ -104,6 +108,8 @@ class DioHttpClient with InfraLogger { headers: { if (userAgent != null) "User-Agent": userAgent, if (basicAuth != null) "authorization": basicAuth, + // "Accept": "application/json", + // "Content-Type": "application/json", }, ); } diff --git a/lib/features/config_option/model/config_option_entity.dart b/lib/features/config_option/model/config_option_entity.dart index 3432983e..2df83309 100644 --- a/lib/features/config_option/model/config_option_entity.dart +++ b/lib/features/config_option/model/config_option_entity.dart @@ -66,8 +66,11 @@ class ConfigOptionEntity with _$ConfigOptionEntity { @Default("auto") String warpCleanIp, @Default(0) int warpPort, @OptionalRangeJsonConverter() - @Default(OptionalRange()) + @Default(OptionalRange(min: 5, max: 10)) OptionalRange warpNoise, + @OptionalRangeJsonConverter() + @Default(OptionalRange(min: 20, max: 200)) + OptionalRange warpNoiseDelay, @Default("") String warpWireguardConfig, }) = _ConfigOptionEntity; @@ -141,6 +144,7 @@ class ConfigOptionEntity with _$ConfigOptionEntity { warpCleanIp: patch.warpCleanIp ?? warpCleanIp, warpPort: patch.warpPort ?? warpPort, warpNoise: patch.warpNoise ?? warpNoise, + warpNoiseDelay: patch.warpNoiseDelay ?? warpNoiseDelay, warpWireguardConfig: patch.warpWireguardConfig ?? warpWireguardConfig, ); } @@ -198,6 +202,7 @@ class ConfigOptionEntity with _$ConfigOptionEntity { cleanIp: warpCleanIp, cleanPort: warpPort, warpNoise: warpNoise, + warpNoiseDelay: warpNoiseDelay, wireguardConfig: warpWireguardConfig, ), ); @@ -253,6 +258,7 @@ class ConfigOptionPatch with _$ConfigOptionPatch { String? warpCleanIp, int? warpPort, @OptionalRangeJsonConverter() OptionalRange? warpNoise, + @OptionalRangeJsonConverter() OptionalRange? warpNoiseDelay, String? warpWireguardConfig, }) = _ConfigOptionPatch; diff --git a/lib/features/config_option/overview/warp_options_widgets.dart b/lib/features/config_option/overview/warp_options_widgets.dart index 12bcc1e8..e767ad4d 100644 --- a/lib/features/config_option/overview/warp_options_widgets.dart +++ b/lib/features/config_option/overview/warp_options_widgets.dart @@ -172,6 +172,25 @@ class WarpOptionsTiles extends HookConsumerWidget { ); }, ), + ListTile( + title: Text(t.settings.config.warpNoiseDelay), + subtitle: Text(options.warpNoiseDelay.present(t)), + enabled: canChangeOptions, + onTap: () async { + final warpNoiseDelay = await SettingsInputDialog( + title: t.settings.config.warpNoiseDelay, + initialValue: options.warpNoiseDelay.format(), + resetValue: defaultOptions.warpNoiseDelay.format(), + ).show(context); + if (warpNoiseDelay == null) return; + await onChange( + ConfigOptionPatch( + warpNoise: + OptionalRange.tryParse(warpNoiseDelay, allowEmpty: true), + ), + ); + }, + ) ], ); } diff --git a/lib/features/proxy/data/proxy_repository.dart b/lib/features/proxy/data/proxy_repository.dart index 53c66f27..89c193f9 100644 --- a/lib/features/proxy/data/proxy_repository.dart +++ b/lib/features/proxy/data/proxy_repository.dart @@ -121,6 +121,8 @@ class ProxyRepositoryImpl final Map response)> _ipInfoSources = { + // "https://geolocation-db.com/json/": IpInfo.fromGeolocationDbComJson, + "https://api.ip.sb/geoip/": IpInfo.fromIpSbJson, "https://ipapi.co/json/": IpInfo.fromIpApiCoJson, "https://ipinfo.io/json/": IpInfo.fromIpInfoIoJson, }; diff --git a/lib/features/proxy/model/ip_info_entity.dart b/lib/features/proxy/model/ip_info_entity.dart index 6a5536d5..1a5fb8dd 100644 --- a/lib/features/proxy/model/ip_info_entity.dart +++ b/lib/features/proxy/model/ip_info_entity.dart @@ -67,4 +67,46 @@ class IpInfo with IpInfoMappable { _ => throw const FormatException("invalid json"), }; } + + static IpInfo fromIpSbJson(Map json) { + return switch (json) { + { + "ip": final String ip, + "country_code": final String countryCode, + "region": final String region, + "city": final String city, + "timezone": final String timezone, + "asn": final int asn, + "asn_organization": final String org, + } => + IpInfo( + ip: ip, + countryCode: countryCode, + region: region, + city: city, + timezone: timezone, + asn: '$asn', + org: org, + ), + _ => throw const FormatException("invalid json"), + }; + } + + static IpInfo fromGeolocationDbComJson(Map json) { + return switch (json) { + { + "ip": final String ip, + "country_code": final String countryCode, + "state": final String region, + "city": final String city + } => + IpInfo( + ip: ip, + countryCode: countryCode, + region: region, + city: city, + ), + _ => throw const FormatException("invalid json"), + }; + } } diff --git a/lib/singbox/model/singbox_config_option.dart b/lib/singbox/model/singbox_config_option.dart index 408f6528..6b107aba 100644 --- a/lib/singbox/model/singbox_config_option.dart +++ b/lib/singbox/model/singbox_config_option.dart @@ -78,6 +78,7 @@ class SingboxWarpOption with _$SingboxWarpOption { required String cleanIp, required int cleanPort, @OptionalRangeJsonConverter() required OptionalRange warpNoise, + @OptionalRangeJsonConverter() required OptionalRange warpNoiseDelay, }) = _SingboxWarpOption; factory SingboxWarpOption.fromJson(Map json) => diff --git a/libcore b/libcore index 298ca9b1..70157d1a 160000 --- a/libcore +++ b/libcore @@ -1 +1 @@ -Subproject commit 298ca9b1b830a142eeab03c22ce7501ee4746e34 +Subproject commit 70157d1ac6f25ff58e9d6cb17d9cc87e122e8780