diff --git a/android/app/build.gradle b/android/app/build.gradle index b896543..16a3b53 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -45,7 +45,7 @@ android { ndk { abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64" } - versionName "1.2.11" + versionName "1.2.13" } buildTypes { diff --git a/android/app/src/main/java/top/wherewego/vnt_app/vpn/MyVpnService.java b/android/app/src/main/java/top/wherewego/vnt_app/vpn/MyVpnService.java index 9a97a29..f4c3b47 100644 --- a/android/app/src/main/java/top/wherewego/vnt_app/vpn/MyVpnService.java +++ b/android/app/src/main/java/top/wherewego/vnt_app/vpn/MyVpnService.java @@ -2,6 +2,7 @@ import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.VpnService; import android.os.Build; @@ -64,7 +65,7 @@ public static void stopVpn() { } } - private int startVpn(DeviceConfig config) { + private int startVpn(DeviceConfig config) throws PackageManager.NameNotFoundException { Builder builder = new Builder(); String ip = IpUtils.intToIpAddress(config.virtualIp); int prefixLength = IpUtils.subnetMaskToPrefixLength(config.virtualNetmask); @@ -74,6 +75,8 @@ private int startVpn(DeviceConfig config) { .setBlocking(false) .setMtu(config.mtu) .addAddress(ip, prefixLength) + // 自己的流量不走网卡 + .addDisallowedApplication("top.wherewego.vnt_app") .addRoute(ipRoute, prefixLength); if (config.externalRoute != null) { for (DeviceConfig.Route routeItem : config.externalRoute) { diff --git a/android/app/src/main/jniLibs/arm64-v8a/librust_lib_vnt_app.so b/android/app/src/main/jniLibs/arm64-v8a/librust_lib_vnt_app.so index 89a27d7..de854de 100644 Binary files a/android/app/src/main/jniLibs/arm64-v8a/librust_lib_vnt_app.so and b/android/app/src/main/jniLibs/arm64-v8a/librust_lib_vnt_app.so differ diff --git a/android/app/src/main/jniLibs/armeabi-v7a/librust_lib_vnt_app.so b/android/app/src/main/jniLibs/armeabi-v7a/librust_lib_vnt_app.so index 397d432..2ee92bd 100644 Binary files a/android/app/src/main/jniLibs/armeabi-v7a/librust_lib_vnt_app.so and b/android/app/src/main/jniLibs/armeabi-v7a/librust_lib_vnt_app.so differ diff --git a/android/app/src/main/jniLibs/x86/librust_lib_vnt_app.so b/android/app/src/main/jniLibs/x86/librust_lib_vnt_app.so index 15bd3da..ab21fca 100644 Binary files a/android/app/src/main/jniLibs/x86/librust_lib_vnt_app.so and b/android/app/src/main/jniLibs/x86/librust_lib_vnt_app.so differ diff --git a/android/app/src/main/jniLibs/x86_64/librust_lib_vnt_app.so b/android/app/src/main/jniLibs/x86_64/librust_lib_vnt_app.so index 6b0af56..a75938c 100644 Binary files a/android/app/src/main/jniLibs/x86_64/librust_lib_vnt_app.so and b/android/app/src/main/jniLibs/x86_64/librust_lib_vnt_app.so differ diff --git a/lib/network_config.dart b/lib/network_config.dart index f127011..f239373 100644 --- a/lib/network_config.dart +++ b/lib/network_config.dart @@ -26,6 +26,8 @@ class NetworkConfig { String punchModel; String useChannelType; String compressor; + bool allowWg; + String localIpv4; NetworkConfig({ required this.itemKey, @@ -55,6 +57,8 @@ class NetworkConfig { required this.punchModel, required this.useChannelType, required this.compressor, + required this.allowWg, + required this.localIpv4, }); Map toJson() { return { @@ -85,6 +89,8 @@ class NetworkConfig { 'punch_model': punchModel, 'use_channel': useChannelType, 'compressor': compressor, + 'allow_wire_guard': allowWg, + 'local_ipv4': localIpv4, }; } @@ -117,6 +123,8 @@ class NetworkConfig { if (punchModel.isNotEmpty) 'punch_model': punchModel, if (useChannelType.isNotEmpty) 'use_channel': useChannelType, if (compressor.isNotEmpty) 'compressor': compressor, + if (allowWg) 'allow_wire_guard': allowWg, + if (localIpv4.isNotEmpty) 'local_ipv4': localIpv4, }; } @@ -134,7 +142,7 @@ class NetworkConfig { portMappings: List.from(json['mapping']), groupPassword: json['password'], isServerEncrypted: json['server_encrypt'], - protocol: json['protocol']??'UDP', + protocol: json['protocol'] ?? 'UDP', dataFingerprintVerification: json['finger'], encryptionAlgorithm: json['cipher_model'], deviceID: json['device_id'], @@ -149,6 +157,8 @@ class NetworkConfig { punchModel: json['punch_model'], useChannelType: json['use_channel'], compressor: json['compressor'] ?? 'none', + allowWg: json['allow_wire_guard'] ?? false, + localIpv4: json['local_ipv4'] ?? '', ); } } diff --git a/lib/network_config_input_page.dart b/lib/network_config_input_page.dart index 515c263..afbe7de 100644 --- a/lib/network_config_input_page.dart +++ b/lib/network_config_input_page.dart @@ -19,10 +19,11 @@ class _NetworkConfigInputPageState extends State { final _nameController = TextEditingController(); final _groupNumberController = TextEditingController(); final _deviceNameController = TextEditingController( - text: Platform.localHostname.length > 32 - ? Platform.localHostname.substring(0, 32) - : Platform.localHostname); + text: Platform.operatingSystemVersion.length > 16 + ? Platform.operatingSystemVersion.substring(0, 16) + : Platform.operatingSystemVersion); final _virtualIPv4Controller = TextEditingController(); + final _localIPv4Controller = TextEditingController(); final _serverAddressController = TextEditingController(); final _stunServers = []; final _inIps = []; @@ -49,6 +50,7 @@ class _NetworkConfigInputPageState extends State { bool _ipv6Selected = true; bool _relaySelected = true; bool _p2pSelected = true; + String _allowWg = 'FALSE'; String _compressionMethod = 'none'; // 默认不压缩 int _compressionLevel = 3; // 默认压缩级别 @@ -147,6 +149,8 @@ class _NetworkConfigInputPageState extends State { _compressionLevel = int.tryParse(arr[1]) ?? 3; } } + _allowWg = config.allowWg ? 'FALSE' : 'TRUE'; + _localIPv4Controller.text = config.localIpv4; setState(() { _routingMode = config.firstLatency ? 'LOW_LATENCY' : 'P2P'; _builtInIpProxy = config.noInIpProxy ? 'CLOSE' : 'OPEN'; @@ -226,6 +230,8 @@ class _NetworkConfigInputPageState extends State { : (_p2pSelected ? 'p2p' : 'relay'), compressor: '$_compressionMethod${_compressionMethod == 'zstd' ? ',$_compressionLevel' : ''}', + allowWg: _allowWg == 'FALSE' ? false : true, + localIpv4: _localIPv4Controller.text, ); Navigator.pop(context, config); } else { @@ -386,8 +392,7 @@ class _NetworkConfigInputPageState extends State { } else { final match = addressPortRegex.firstMatch(value); if (match != null) { - final domainRegex = - RegExp(r'^[a-zA-Z0-9.-]'); + final domainRegex = RegExp(r'^[a-zA-Z0-9.-]'); if (!domainRegex.hasMatch(match.group(1)!)) { return '地址格式错误'; } @@ -451,6 +456,16 @@ class _NetworkConfigInputPageState extends State { }); }, ), + _buildRadioGroup( + '允许WireGuard流量', + [('允许', 'TRUE'), ('不允许', 'FALSE')], + _allowWg, + (value) { + setState(() { + _allowWg = value!; + }); + }, + ), _buildSectionTitle('子网代理&端口映射'), _buildDynamicTooltipFields( 'in-ip', @@ -565,6 +580,23 @@ class _NetworkConfigInputPageState extends State { null, false, ), + CustomTooltipTextField( + controller: _localIPv4Controller, + labelText: '本地IPv4', + tooltipMessage: '(不输入则自动获取)', + maxLength: 15, + validator: (value) { + final regex = RegExp( + r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', + ); + if (value != null && + value.isNotEmpty && + !regex.hasMatch(value)) { + return '请输入有效的 IPv4 地址'; + } + return null; + }, + ), _buildTextFormField( _virtualNetworkCardNameController, '虚拟网卡名称', diff --git a/lib/src/rust/api/vnt_api.dart b/lib/src/rust/api/vnt_api.dart index eabeda5..32af996 100644 --- a/lib/src/rust/api/vnt_api.dart +++ b/lib/src/rust/api/vnt_api.dart @@ -395,6 +395,8 @@ class VntConfig { final int packetDelay; final List portMappingList; final String compressor; + final bool allowWireGuard; + final String? localIpv4; const VntConfig({ required this.tap, @@ -422,6 +424,8 @@ class VntConfig { required this.packetDelay, required this.portMappingList, required this.compressor, + required this.allowWireGuard, + this.localIpv4, }); @override @@ -450,7 +454,9 @@ class VntConfig { packetLossRate.hashCode ^ packetDelay.hashCode ^ portMappingList.hashCode ^ - compressor.hashCode; + compressor.hashCode ^ + allowWireGuard.hashCode ^ + localIpv4.hashCode; @override bool operator ==(Object other) => @@ -481,5 +487,7 @@ class VntConfig { packetLossRate == other.packetLossRate && packetDelay == other.packetDelay && portMappingList == other.portMappingList && - compressor == other.compressor; + compressor == other.compressor && + allowWireGuard == other.allowWireGuard && + localIpv4 == other.localIpv4; } diff --git a/lib/src/rust/frb_generated.dart b/lib/src/rust/frb_generated.dart index b1488f6..370f07a 100644 --- a/lib/src/rust/frb_generated.dart +++ b/lib/src/rust/frb_generated.dart @@ -1536,8 +1536,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { VntConfig dco_decode_vnt_config(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 25) - throw Exception('unexpected arr length: expect 25 but see ${arr.length}'); + if (arr.length != 27) + throw Exception('unexpected arr length: expect 27 but see ${arr.length}'); return VntConfig( tap: dco_decode_bool(arr[0]), token: dco_decode_String(arr[1]), @@ -1564,6 +1564,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { packetDelay: dco_decode_u_32(arr[22]), portMappingList: dco_decode_list_String(arr[23]), compressor: dco_decode_String(arr[24]), + allowWireGuard: dco_decode_bool(arr[25]), + localIpv4: dco_decode_opt_String(arr[26]), ); } @@ -2118,6 +2120,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_packetDelay = sse_decode_u_32(deserializer); var var_portMappingList = sse_decode_list_String(deserializer); var var_compressor = sse_decode_String(deserializer); + var var_allowWireGuard = sse_decode_bool(deserializer); + var var_localIpv4 = sse_decode_opt_String(deserializer); return VntConfig( tap: var_tap, token: var_token, @@ -2143,7 +2147,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { packetLossRate: var_packetLossRate, packetDelay: var_packetDelay, portMappingList: var_portMappingList, - compressor: var_compressor); + compressor: var_compressor, + allowWireGuard: var_allowWireGuard, + localIpv4: var_localIpv4); } @protected @@ -2723,6 +2729,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_u_32(self.packetDelay, serializer); sse_encode_list_String(self.portMappingList, serializer); sse_encode_String(self.compressor, serializer); + sse_encode_bool(self.allowWireGuard, serializer); + sse_encode_opt_String(self.localIpv4, serializer); } } diff --git a/lib/vnt/vnt_manager.dart b/lib/vnt/vnt_manager.dart index 63a047e..5093b86 100644 --- a/lib/vnt/vnt_manager.dart +++ b/lib/vnt/vnt_manager.dart @@ -23,36 +23,37 @@ class VntBox { }); static Future create(NetworkConfig config, SendPort uiCall) async { var vntConfig = VntConfig( - tap: false, - token: config.token, - deviceId: config.deviceID, - name: config.deviceName, - serverAddressStr: config.serverAddress, - nameServers: config.dns, - stunServer: config.stunServers, - inIps: config.inIps.map((v) => IpUtils.parseInIpString(v)).toList(), - outIps: config.outIps.map((v) => IpUtils.parseOutIpString(v)).toList(), - password: config.groupPassword.isEmpty ? null : config.groupPassword, - mtu: config.mtu == 0 ? null : config.mtu, - ip: config.virtualIPv4.isEmpty ? null : config.virtualIPv4, - noProxy: config.noInIpProxy, - serverEncrypt: config.isServerEncrypted, - cipherModel: config.encryptionAlgorithm, - finger: config.dataFingerprintVerification, - punchModel: config.punchModel, - ports: config.ports.isEmpty ? null : Uint16List.fromList(config.ports), - firstLatency: config.firstLatency, - deviceName: config.virtualNetworkCardName.isEmpty - ? null - : config.virtualNetworkCardName, - useChannelType: config.useChannelType, - packetLossRate: config.simulatedPacketLossRate == 0 - ? null - : config.simulatedPacketLossRate, - packetDelay: config.simulatedLatency, - portMappingList: config.portMappings, - compressor: config.compressor.isEmpty ? 'none' : config.compressor, - ); + tap: false, + token: config.token, + deviceId: config.deviceID, + name: config.deviceName, + serverAddressStr: config.serverAddress, + nameServers: config.dns, + stunServer: config.stunServers, + inIps: config.inIps.map((v) => IpUtils.parseInIpString(v)).toList(), + outIps: config.outIps.map((v) => IpUtils.parseOutIpString(v)).toList(), + password: config.groupPassword.isEmpty ? null : config.groupPassword, + mtu: config.mtu == 0 ? null : config.mtu, + ip: config.virtualIPv4.isEmpty ? null : config.virtualIPv4, + noProxy: config.noInIpProxy, + serverEncrypt: config.isServerEncrypted, + cipherModel: config.encryptionAlgorithm, + finger: config.dataFingerprintVerification, + punchModel: config.punchModel, + ports: config.ports.isEmpty ? null : Uint16List.fromList(config.ports), + firstLatency: config.firstLatency, + deviceName: config.virtualNetworkCardName.isEmpty + ? null + : config.virtualNetworkCardName, + useChannelType: config.useChannelType, + packetLossRate: config.simulatedPacketLossRate == 0 + ? null + : config.simulatedPacketLossRate, + packetDelay: config.simulatedLatency, + portMappingList: config.portMappings, + compressor: config.compressor.isEmpty ? 'none' : config.compressor, + allowWireGuard: config.allowWg, + localIpv4: config.localIpv4.isEmpty ? null : config.localIpv4); var vntCall = VntApiCallback(successFn: () { uiCall.send('success'); }, createTunFn: (info) { diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 5c6fb94..1446993 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -194,9 +194,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.16.1" +version = "1.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" +checksum = "102087e286b4677862ea56cf8fc58bb2cdfa8725c40ffb80fe3a008eb7f2fc83" [[package]] name = "byteorder" @@ -206,9 +206,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" [[package]] name = "cbc" @@ -221,13 +221,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.0" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaff6f8ce506b9773fa786672d63fc7a191ffea1be33f72bbd4aeacefca9ffc8" +checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" dependencies = [ "jobserver", "libc", - "once_cell", ] [[package]] @@ -407,7 +406,7 @@ checksum = "51aac4c99b2e6775164b412ea33ae8441b2fde2dbf05a20bc0052a63d08c475b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -543,7 +542,7 @@ dependencies = [ "md-5", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -608,7 +607,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -803,9 +802,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" dependencies = [ "libc", ] @@ -836,9 +835,9 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", "windows-targets 0.52.6", @@ -853,7 +852,7 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libsm" version = "0.5.1" -source = "git+https://github.com/lbl8603/libsm#f9e1b8cf20d0829efb4934a940d0ba4f3ee0ac14" +source = "git+https://github.com/vnt-dev/libsm#f9e1b8cf20d0829efb4934a940d0ba4f3ee0ac14" dependencies = [ "byteorder", "getrandom", @@ -967,6 +966,30 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mio" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "network-interface" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "433419f898328beca4f2c6c73a1b52540658d92b0a99f0269330457e0fd998d5" +dependencies = [ + "cc", + "libc", + "thiserror", + "winapi", +] + [[package]] name = "num-bigint" version = "0.4.6" @@ -1036,9 +1059,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.1" +version = "0.36.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" +checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e" dependencies = [ "memchr", ] @@ -1084,7 +1107,7 @@ dependencies = [ [[package]] name = "packet" version = "0.1.0" -source = "git+https://github.com/lbl8603/vnt.git?branch=1.2.x#27c0f389ee5c93d84c15d9a607f1c1a3e8638ef8" +source = "git+https://github.com/vnt-dev/vnt.git?branch=1.2.x#13df028cd9e4eb178c83a966d8aa0207956c5b66" dependencies = [ "byteorder", ] @@ -1185,9 +1208,13 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "2288c0e17cc8d342c712bb43a257a80ebffce59cdb33d5000d8348f3ec02528b" +dependencies = [ + "zerocopy", + "zerocopy-derive", +] [[package]] name = "proc-macro2" @@ -1352,9 +1379,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ "bitflags", ] @@ -1458,9 +1485,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.11" +version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4828ea528154ae444e5a642dbb7d5623354030dc9822b83fd9bb79683c7399d0" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "once_cell", "ring", @@ -1501,9 +1528,9 @@ checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" -version = "0.102.5" +version = "0.102.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78" +checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" dependencies = [ "ring", "rustls-pki-types", @@ -1533,9 +1560,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "security-framework" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags", "core-foundation", @@ -1546,9 +1573,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" dependencies = [ "core-foundation-sys", "libc", @@ -1581,16 +1608,17 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -1729,9 +1757,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.70" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -1752,29 +1780,29 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] name = "thread-id" -version = "4.2.1" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0ec81c46e9eb50deaa257be2f148adf052d1fb7701cfd55ccfab2525280b70b" +checksum = "cfe8f25bbdd100db7e1d34acf7fd2dc59c4bf8f7483f505eaa7d4f12f76cc0ea" dependencies = [ "libc", "winapi", @@ -1791,32 +1819,31 @@ dependencies = [ [[package]] name = "tokio" -version = "1.38.0" +version = "1.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" dependencies = [ "backtrace", "bytes", "libc", - "mio", - "num_cpus", + "mio 1.0.1", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -1850,13 +1877,14 @@ dependencies = [ [[package]] name = "tun" version = "0.1.0" -source = "git+https://github.com/lbl8603/vnt.git?branch=1.2.x#27c0f389ee5c93d84c15d9a607f1c1a3e8638ef8" +source = "git+https://github.com/vnt-dev/vnt.git?branch=1.2.x#13df028cd9e4eb178c83a966d8aa0207956c5b66" dependencies = [ "ioctl-sys", "libc", "libloading", "log", "rand", + "sha2", "widestring", "winapi", ] @@ -1941,14 +1969,14 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "vnt" -version = "1.2.11" -source = "git+https://github.com/lbl8603/vnt.git?branch=1.2.x#27c0f389ee5c93d84c15d9a607f1c1a3e8638ef8" +version = "1.2.13" +source = "git+https://github.com/vnt-dev/vnt.git?branch=1.2.x#13df028cd9e4eb178c83a966d8aa0207956c5b66" dependencies = [ "aes", "aes-gcm", @@ -1970,7 +1998,8 @@ dependencies = [ "libsm", "log", "lz4_flex", - "mio", + "mio 0.8.11", + "network-interface", "packet", "parking_lot", "protobuf", @@ -1988,6 +2017,7 @@ dependencies = [ "tokio", "tokio-tungstenite", "tun", + "windows-sys 0.59.0", "zstd", ] @@ -2018,7 +2048,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", "wasm-bindgen-shared", ] @@ -2052,7 +2082,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2149,6 +2179,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -2279,6 +2318,27 @@ dependencies = [ "num-bigint", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "zeroize" version = "1.8.1" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 2c275ac..542c436 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["staticlib", "cdylib"] serde = { version = "1.0", features = ["derive"] } flutter_rust_bridge = "=2.1.0" -vnt = { git = "https://github.com/lbl8603/vnt.git", branch = "1.2.x", features = ["ring-cipher", "wss"] } +vnt = { git = "https://github.com/vnt-dev/vnt.git", branch = "1.2.x", features = ["ring-cipher", "wss"] } anyhow = "1.0.82" tokio = { version = "1.37.0", features = ["full"] } diff --git a/rust/src/api/vnt_api.rs b/rust/src/api/vnt_api.rs index e05ed73..7fc2e12 100644 --- a/rust/src/api/vnt_api.rs +++ b/rust/src/api/vnt_api.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use std::sync::Arc; use std::thread; -use anyhow::anyhow; +use anyhow::{anyhow, Context}; use flutter_rust_bridge::DartFnFuture; use tokio::runtime::{Handle, Runtime}; use vnt::channel::punch::{NatInfo, PunchModel}; @@ -90,6 +90,8 @@ pub struct VntConfig { // 端口映射 pub port_mapping_list: Vec, pub compressor: String, + pub allow_wire_guard:bool, + pub local_ipv4:Option, } pub struct VntApi { @@ -125,6 +127,11 @@ impl VntApi { Ok(compressor) => compressor, Err(e) => Err(anyhow!("{:?}", e))?, }; + let local_ipv4:Option = if let Some(local_ipv4) = vnt_config.local_ipv4{ + Some(local_ipv4.parse().context("localIP")?) + }else{ + None + }; let conf = Config::new( #[cfg(target_os = "windows")] vnt_config.tap, @@ -154,6 +161,8 @@ impl VntApi { vnt_config.port_mapping_list, compressor, true, + vnt_config.allow_wire_guard, + local_ipv4, )?; Ok(Self { vnt: Vnt::new(conf, call)?, diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index 0172e94..5211b45 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -1844,6 +1844,8 @@ impl SseDecode for crate::api::vnt_api::VntConfig { let mut var_packetDelay = ::sse_decode(deserializer); let mut var_portMappingList = >::sse_decode(deserializer); let mut var_compressor = ::sse_decode(deserializer); + let mut var_allowWireGuard = ::sse_decode(deserializer); + let mut var_localIpv4 = >::sse_decode(deserializer); return crate::api::vnt_api::VntConfig { tap: var_tap, token: var_token, @@ -1870,6 +1872,8 @@ impl SseDecode for crate::api::vnt_api::VntConfig { packet_delay: var_packetDelay, port_mapping_list: var_portMappingList, compressor: var_compressor, + allow_wire_guard: var_allowWireGuard, + local_ipv4: var_localIpv4, }; } } @@ -2233,6 +2237,8 @@ impl flutter_rust_bridge::IntoDart for crate::api::vnt_api::VntConfig { self.packet_delay.into_into_dart().into_dart(), self.port_mapping_list.into_into_dart().into_dart(), self.compressor.into_into_dart().into_dart(), + self.allow_wire_guard.into_into_dart().into_dart(), + self.local_ipv4.into_into_dart().into_dart(), ] .into_dart() } @@ -2731,6 +2737,8 @@ impl SseEncode for crate::api::vnt_api::VntConfig { ::sse_encode(self.packet_delay, serializer); >::sse_encode(self.port_mapping_list, serializer); ::sse_encode(self.compressor, serializer); + ::sse_encode(self.allow_wire_guard, serializer); + >::sse_encode(self.local_ipv4, serializer); } }