Files
umbrix/lib/features/config_option/model/config_option_entity.dart

126 lines
5.2 KiB
Dart
Raw Normal View History

2023-12-01 12:56:24 +03:30
import 'dart:convert';
import 'package:freezed_annotation/freezed_annotation.dart';
2023-12-04 17:36:02 +03:30
import 'package:hiddify/core/model/range.dart';
2023-12-01 12:56:24 +03:30
import 'package:hiddify/core/utils/json_converters.dart';
import 'package:hiddify/features/config_option/model/config_option_patch.dart';
import 'package:hiddify/features/log/model/log_level.dart';
import 'package:hiddify/singbox/model/singbox_config_enum.dart';
2023-12-31 10:28:52 +03:30
import 'package:hiddify/utils/platform_utils.dart';
2023-12-01 12:56:24 +03:30
part 'config_option_entity.freezed.dart';
part 'config_option_entity.g.dart';
@freezed
class ConfigOptionEntity with _$ConfigOptionEntity {
const ConfigOptionEntity._();
@JsonSerializable(fieldRename: FieldRename.kebab)
const factory ConfigOptionEntity({
required ServiceMode serviceMode,
@Default(LogLevel.warn) LogLevel logLevel,
@Default(false) bool resolveDestination,
@Default(IPv6Mode.disable) IPv6Mode ipv6Mode,
2024-01-26 00:24:54 +01:00
@Default("udp://1.1.1.1") String remoteDnsAddress,
2023-12-01 12:56:24 +03:30
@Default(DomainStrategy.auto) DomainStrategy remoteDnsDomainStrategy,
2024-01-26 00:24:54 +01:00
@Default("1.1.1.1") String directDnsAddress,
2023-12-01 12:56:24 +03:30
@Default(DomainStrategy.auto) DomainStrategy directDnsDomainStrategy,
@Default(2334) int mixedPort,
@Default(6450) int localDnsPort,
@Default(TunImplementation.mixed) TunImplementation tunImplementation,
@Default(9000) int mtu,
@Default(true) bool strictRoute,
2024-01-25 23:27:39 +01:00
@Default("http://cp.cloudflare.com/") String connectionTestUrl,
2023-12-01 12:56:24 +03:30
@IntervalInSecondsConverter()
@Default(Duration(minutes: 10))
Duration urlTestInterval,
@Default(true) bool enableClashApi,
@Default(6756) int clashApiPort,
@Default(false) bool bypassLan,
2024-01-01 19:14:28 +03:30
@Default(false) bool allowConnectionFromLan,
2023-12-01 12:56:24 +03:30
@Default(false) bool enableFakeDns,
2024-01-01 19:01:36 +03:30
@Default(true) bool enableDnsRouting,
2023-12-01 12:56:24 +03:30
@Default(true) bool independentDnsCache,
2023-12-04 17:36:02 +03:30
@Default(false) bool enableTlsFragment,
@RangeWithOptionalCeilJsonConverter()
@Default(RangeWithOptionalCeil(min: 10, max: 100))
RangeWithOptionalCeil tlsFragmentSize,
@RangeWithOptionalCeilJsonConverter()
@Default(RangeWithOptionalCeil(min: 50, max: 200))
RangeWithOptionalCeil tlsFragmentSleep,
@Default(false) bool enableTlsMixedSniCase,
@Default(false) bool enableTlsPadding,
@RangeWithOptionalCeilJsonConverter()
@Default(RangeWithOptionalCeil(min: 100, max: 200))
RangeWithOptionalCeil tlsPaddingSize,
2024-01-19 22:26:23 +03:30
@Default(false) bool enableMux,
@Default(false) bool muxPadding,
@Default(8) int muxMaxStreams,
@Default(MuxProtocol.h2mux) MuxProtocol muxProtocol,
2023-12-01 12:56:24 +03:30
}) = _ConfigOptionEntity;
static ConfigOptionEntity initial = ConfigOptionEntity(
serviceMode: ServiceMode.defaultMode,
);
2023-12-31 10:28:52 +03:30
bool hasExperimentalOptions() {
if (PlatformUtils.isDesktop && serviceMode == ServiceMode.tun) {
return true;
}
if (enableTlsFragment || enableTlsMixedSniCase || enableTlsPadding||enableMux) {
2023-12-31 10:28:52 +03:30
return true;
}
return false;
}
2023-12-01 12:56:24 +03:30
String format() {
const encoder = JsonEncoder.withIndent(' ');
return encoder.convert(toJson());
}
ConfigOptionEntity patch(ConfigOptionPatch patch) {
return copyWith(
serviceMode: patch.serviceMode ?? serviceMode,
logLevel: patch.logLevel ?? logLevel,
resolveDestination: patch.resolveDestination ?? resolveDestination,
ipv6Mode: patch.ipv6Mode ?? ipv6Mode,
remoteDnsAddress: patch.remoteDnsAddress ?? remoteDnsAddress,
remoteDnsDomainStrategy:
patch.remoteDnsDomainStrategy ?? remoteDnsDomainStrategy,
directDnsAddress: patch.directDnsAddress ?? directDnsAddress,
directDnsDomainStrategy:
patch.directDnsDomainStrategy ?? directDnsDomainStrategy,
mixedPort: patch.mixedPort ?? mixedPort,
localDnsPort: patch.localDnsPort ?? localDnsPort,
tunImplementation: patch.tunImplementation ?? tunImplementation,
mtu: patch.mtu ?? mtu,
strictRoute: patch.strictRoute ?? strictRoute,
connectionTestUrl: patch.connectionTestUrl ?? connectionTestUrl,
urlTestInterval: patch.urlTestInterval ?? urlTestInterval,
enableClashApi: patch.enableClashApi ?? enableClashApi,
clashApiPort: patch.clashApiPort ?? clashApiPort,
bypassLan: patch.bypassLan ?? bypassLan,
2024-01-01 19:14:28 +03:30
allowConnectionFromLan:
patch.allowConnectionFromLan ?? allowConnectionFromLan,
2023-12-01 12:56:24 +03:30
enableFakeDns: patch.enableFakeDns ?? enableFakeDns,
2024-01-01 19:01:36 +03:30
enableDnsRouting: patch.enableDnsRouting ?? enableDnsRouting,
2023-12-01 12:56:24 +03:30
independentDnsCache: patch.independentDnsCache ?? independentDnsCache,
2023-12-04 17:36:02 +03:30
enableTlsFragment: patch.enableTlsFragment ?? enableTlsFragment,
tlsFragmentSize: patch.tlsFragmentSize ?? tlsFragmentSize,
tlsFragmentSleep: patch.tlsFragmentSleep ?? tlsFragmentSleep,
enableTlsMixedSniCase:
patch.enableTlsMixedSniCase ?? enableTlsMixedSniCase,
enableTlsPadding: patch.enableTlsPadding ?? enableTlsPadding,
tlsPaddingSize: patch.tlsPaddingSize ?? tlsPaddingSize,
2024-01-19 22:26:23 +03:30
enableMux: patch.enableMux ?? enableMux,
muxPadding: patch.muxPadding ?? muxPadding,
muxMaxStreams: patch.muxMaxStreams ?? muxMaxStreams,
muxProtocol: patch.muxProtocol ?? muxProtocol,
2023-12-01 12:56:24 +03:30
);
}
factory ConfigOptionEntity.fromJson(Map<String, dynamic> json) =>
_$ConfigOptionEntityFromJson(json);
}