|
| 1 | +// Импортируем для обратной совместимости |
| 2 | +import 'config.dart'; |
| 3 | + |
| 4 | +/// Опции для настройки TUN интерфейса |
| 5 | +class TunOptions { |
| 6 | + /// MTU (Maximum Transmission Unit) |
| 7 | + final int mtu; |
| 8 | + |
| 9 | + /// Имя TUN устройства |
| 10 | + final String tunName; |
| 11 | + |
| 12 | + /// IPv4 адрес TUN устройства (например, "10.0.0.2") |
| 13 | + final String? ipv4Address; |
| 14 | + |
| 15 | + /// IPv4 маска сети (например, "255.255.255.0") |
| 16 | + final String? ipv4Netmask; |
| 17 | + |
| 18 | + /// IPv4 шлюз (например, "10.0.0.1") |
| 19 | + final String? ipv4Gateway; |
| 20 | + |
| 21 | + /// IPv6 адрес (например, "2001:db8::1") |
| 22 | + final String? ipv6Address; |
| 23 | + |
| 24 | + /// IPv6 префикс (например, 64) |
| 25 | + final int? ipv6Prefix; |
| 26 | + |
| 27 | + /// DNS сервер (IPv4) |
| 28 | + final String? dnsServer; |
| 29 | + |
| 30 | + /// DNS серверы (список) |
| 31 | + final List<String>? dnsServers; |
| 32 | + |
| 33 | + /// Автоматическая маршрутизация |
| 34 | + final bool autoRoute; |
| 35 | + |
| 36 | + /// Строгая маршрутизация |
| 37 | + final bool strictRoute; |
| 38 | + |
| 39 | + /// Включить IPv6 |
| 40 | + final bool enableIPv6; |
| 41 | + |
| 42 | + /// Включить per-app proxy (Android) |
| 43 | + final bool enablePerAppProxy; |
| 44 | + |
| 45 | + /// Список приложений для включения в per-app proxy (Android) |
| 46 | + final List<String>? includePackages; |
| 47 | + |
| 48 | + /// Список приложений для исключения из per-app proxy (Android) |
| 49 | + final List<String>? excludePackages; |
| 50 | + |
| 51 | + const TunOptions({ |
| 52 | + this.mtu = 1500, |
| 53 | + this.tunName = 'tun0', |
| 54 | + this.ipv4Address, |
| 55 | + this.ipv4Netmask, |
| 56 | + this.ipv4Gateway, |
| 57 | + this.ipv6Address, |
| 58 | + this.ipv6Prefix, |
| 59 | + this.dnsServer, |
| 60 | + this.dnsServers, |
| 61 | + this.autoRoute = true, |
| 62 | + this.strictRoute = false, |
| 63 | + this.enableIPv6 = false, |
| 64 | + this.enablePerAppProxy = false, |
| 65 | + this.includePackages, |
| 66 | + this.excludePackages, |
| 67 | + }); |
| 68 | + |
| 69 | + /// Создание из DriverConfig (для обратной совместимости) |
| 70 | + factory TunOptions.fromDriverConfig(DriverConfig config) { |
| 71 | + return TunOptions( |
| 72 | + mtu: config.mtu, |
| 73 | + tunName: config.tunName, |
| 74 | + ipv4Address: config.tunAddress, |
| 75 | + ipv4Netmask: config.tunNetmask, |
| 76 | + ipv4Gateway: config.tunGateway, |
| 77 | + dnsServer: config.dnsServer, |
| 78 | + autoRoute: true, |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + /// Преобразование в Map |
| 83 | + Map<String, dynamic> toMap() { |
| 84 | + return { |
| 85 | + 'mtu': mtu, |
| 86 | + 'tunName': tunName, |
| 87 | + 'ipv4Address': ipv4Address, |
| 88 | + 'ipv4Netmask': ipv4Netmask, |
| 89 | + 'ipv4Gateway': ipv4Gateway, |
| 90 | + 'ipv6Address': ipv6Address, |
| 91 | + 'ipv6Prefix': ipv6Prefix, |
| 92 | + 'dnsServer': dnsServer, |
| 93 | + 'dnsServers': dnsServers, |
| 94 | + 'autoRoute': autoRoute, |
| 95 | + 'strictRoute': strictRoute, |
| 96 | + 'enableIPv6': enableIPv6, |
| 97 | + 'enablePerAppProxy': enablePerAppProxy, |
| 98 | + 'includePackages': includePackages, |
| 99 | + 'excludePackages': excludePackages, |
| 100 | + }; |
| 101 | + } |
| 102 | + |
| 103 | + /// Создание из Map |
| 104 | + factory TunOptions.fromMap(Map<String, dynamic> map) { |
| 105 | + return TunOptions( |
| 106 | + mtu: map['mtu'] as int? ?? 1500, |
| 107 | + tunName: map['tunName'] as String? ?? 'tun0', |
| 108 | + ipv4Address: map['ipv4Address'] as String?, |
| 109 | + ipv4Netmask: map['ipv4Netmask'] as String?, |
| 110 | + ipv4Gateway: map['ipv4Gateway'] as String?, |
| 111 | + ipv6Address: map['ipv6Address'] as String?, |
| 112 | + ipv6Prefix: map['ipv6Prefix'] as int?, |
| 113 | + dnsServer: map['dnsServer'] as String?, |
| 114 | + dnsServers: map['dnsServers'] != null |
| 115 | + ? List<String>.from(map['dnsServers'] as List) |
| 116 | + : null, |
| 117 | + autoRoute: map['autoRoute'] as bool? ?? true, |
| 118 | + strictRoute: map['strictRoute'] as bool? ?? false, |
| 119 | + enableIPv6: map['enableIPv6'] as bool? ?? false, |
| 120 | + enablePerAppProxy: map['enablePerAppProxy'] as bool? ?? false, |
| 121 | + includePackages: map['includePackages'] != null |
| 122 | + ? List<String>.from(map['includePackages'] as List) |
| 123 | + : null, |
| 124 | + excludePackages: map['excludePackages'] != null |
| 125 | + ? List<String>.from(map['excludePackages'] as List) |
| 126 | + : null, |
| 127 | + ); |
| 128 | + } |
| 129 | +} |
| 130 | + |
0 commit comments