Skip to content

Commit 4e7356d

Browse files
committed
支持WG、支持全局路由
1 parent 18d9536 commit 4e7356d

File tree

15 files changed

+242
-103
lines changed

15 files changed

+242
-103
lines changed

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ android {
4545
ndk {
4646
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
4747
}
48-
versionName "1.2.11"
48+
versionName "1.2.13"
4949
}
5050

5151
buildTypes {

android/app/src/main/java/top/wherewego/vnt_app/vpn/MyVpnService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Intent;
44
import android.content.IntentFilter;
5+
import android.content.pm.PackageManager;
56
import android.net.ConnectivityManager;
67
import android.net.VpnService;
78
import android.os.Build;
@@ -64,7 +65,7 @@ public static void stopVpn() {
6465
}
6566
}
6667

67-
private int startVpn(DeviceConfig config) {
68+
private int startVpn(DeviceConfig config) throws PackageManager.NameNotFoundException {
6869
Builder builder = new Builder();
6970
String ip = IpUtils.intToIpAddress(config.virtualIp);
7071
int prefixLength = IpUtils.subnetMaskToPrefixLength(config.virtualNetmask);
@@ -74,6 +75,8 @@ private int startVpn(DeviceConfig config) {
7475
.setBlocking(false)
7576
.setMtu(config.mtu)
7677
.addAddress(ip, prefixLength)
78+
// 自己的流量不走网卡
79+
.addDisallowedApplication("top.wherewego.vnt_app")
7780
.addRoute(ipRoute, prefixLength);
7881
if (config.externalRoute != null) {
7982
for (DeviceConfig.Route routeItem : config.externalRoute) {
87.3 KB
Binary file not shown.
51.1 KB
Binary file not shown.
66 KB
Binary file not shown.
84.6 KB
Binary file not shown.

lib/network_config.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class NetworkConfig {
2626
String punchModel;
2727
String useChannelType;
2828
String compressor;
29+
bool allowWg;
30+
String localIpv4;
2931

3032
NetworkConfig({
3133
required this.itemKey,
@@ -55,6 +57,8 @@ class NetworkConfig {
5557
required this.punchModel,
5658
required this.useChannelType,
5759
required this.compressor,
60+
required this.allowWg,
61+
required this.localIpv4,
5862
});
5963
Map<String, dynamic> toJson() {
6064
return {
@@ -85,6 +89,8 @@ class NetworkConfig {
8589
'punch_model': punchModel,
8690
'use_channel': useChannelType,
8791
'compressor': compressor,
92+
'allow_wire_guard': allowWg,
93+
'local_ipv4': localIpv4,
8894
};
8995
}
9096

@@ -117,6 +123,8 @@ class NetworkConfig {
117123
if (punchModel.isNotEmpty) 'punch_model': punchModel,
118124
if (useChannelType.isNotEmpty) 'use_channel': useChannelType,
119125
if (compressor.isNotEmpty) 'compressor': compressor,
126+
if (allowWg) 'allow_wire_guard': allowWg,
127+
if (localIpv4.isNotEmpty) 'local_ipv4': localIpv4,
120128
};
121129
}
122130

@@ -134,7 +142,7 @@ class NetworkConfig {
134142
portMappings: List<String>.from(json['mapping']),
135143
groupPassword: json['password'],
136144
isServerEncrypted: json['server_encrypt'],
137-
protocol: json['protocol']??'UDP',
145+
protocol: json['protocol'] ?? 'UDP',
138146
dataFingerprintVerification: json['finger'],
139147
encryptionAlgorithm: json['cipher_model'],
140148
deviceID: json['device_id'],
@@ -149,6 +157,8 @@ class NetworkConfig {
149157
punchModel: json['punch_model'],
150158
useChannelType: json['use_channel'],
151159
compressor: json['compressor'] ?? 'none',
160+
allowWg: json['allow_wire_guard'] ?? false,
161+
localIpv4: json['local_ipv4'] ?? '',
152162
);
153163
}
154164
}

lib/network_config_input_page.dart

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
1919
final _nameController = TextEditingController();
2020
final _groupNumberController = TextEditingController();
2121
final _deviceNameController = TextEditingController(
22-
text: Platform.localHostname.length > 32
23-
? Platform.localHostname.substring(0, 32)
24-
: Platform.localHostname);
22+
text: Platform.operatingSystemVersion.length > 16
23+
? Platform.operatingSystemVersion.substring(0, 16)
24+
: Platform.operatingSystemVersion);
2525
final _virtualIPv4Controller = TextEditingController();
26+
final _localIPv4Controller = TextEditingController();
2627
final _serverAddressController = TextEditingController();
2728
final _stunServers = <TextEditingController>[];
2829
final _inIps = <TextEditingController>[];
@@ -49,6 +50,7 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
4950
bool _ipv6Selected = true;
5051
bool _relaySelected = true;
5152
bool _p2pSelected = true;
53+
String _allowWg = 'FALSE';
5254

5355
String _compressionMethod = 'none'; // 默认不压缩
5456
int _compressionLevel = 3; // 默认压缩级别
@@ -147,6 +149,8 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
147149
_compressionLevel = int.tryParse(arr[1]) ?? 3;
148150
}
149151
}
152+
_allowWg = config.allowWg ? 'FALSE' : 'TRUE';
153+
_localIPv4Controller.text = config.localIpv4;
150154
setState(() {
151155
_routingMode = config.firstLatency ? 'LOW_LATENCY' : 'P2P';
152156
_builtInIpProxy = config.noInIpProxy ? 'CLOSE' : 'OPEN';
@@ -226,6 +230,8 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
226230
: (_p2pSelected ? 'p2p' : 'relay'),
227231
compressor:
228232
'$_compressionMethod${_compressionMethod == 'zstd' ? ',$_compressionLevel' : ''}',
233+
allowWg: _allowWg == 'FALSE' ? false : true,
234+
localIpv4: _localIPv4Controller.text,
229235
);
230236
Navigator.pop(context, config);
231237
} else {
@@ -386,8 +392,7 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
386392
} else {
387393
final match = addressPortRegex.firstMatch(value);
388394
if (match != null) {
389-
final domainRegex =
390-
RegExp(r'^[a-zA-Z0-9.-]');
395+
final domainRegex = RegExp(r'^[a-zA-Z0-9.-]');
391396
if (!domainRegex.hasMatch(match.group(1)!)) {
392397
return '地址格式错误';
393398
}
@@ -451,6 +456,16 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
451456
});
452457
},
453458
),
459+
_buildRadioGroup(
460+
'允许WireGuard流量',
461+
[('允许', 'TRUE'), ('不允许', 'FALSE')],
462+
_allowWg,
463+
(value) {
464+
setState(() {
465+
_allowWg = value!;
466+
});
467+
},
468+
),
454469
_buildSectionTitle('子网代理&端口映射'),
455470
_buildDynamicTooltipFields(
456471
'in-ip',
@@ -565,6 +580,23 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
565580
null,
566581
false,
567582
),
583+
CustomTooltipTextField(
584+
controller: _localIPv4Controller,
585+
labelText: '本地IPv4',
586+
tooltipMessage: '(不输入则自动获取)',
587+
maxLength: 15,
588+
validator: (value) {
589+
final regex = RegExp(
590+
r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$',
591+
);
592+
if (value != null &&
593+
value.isNotEmpty &&
594+
!regex.hasMatch(value)) {
595+
return '请输入有效的 IPv4 地址';
596+
}
597+
return null;
598+
},
599+
),
568600
_buildTextFormField(
569601
_virtualNetworkCardNameController,
570602
'虚拟网卡名称',

lib/src/rust/api/vnt_api.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ class VntConfig {
395395
final int packetDelay;
396396
final List<String> portMappingList;
397397
final String compressor;
398+
final bool allowWireGuard;
399+
final String? localIpv4;
398400

399401
const VntConfig({
400402
required this.tap,
@@ -422,6 +424,8 @@ class VntConfig {
422424
required this.packetDelay,
423425
required this.portMappingList,
424426
required this.compressor,
427+
required this.allowWireGuard,
428+
this.localIpv4,
425429
});
426430

427431
@override
@@ -450,7 +454,9 @@ class VntConfig {
450454
packetLossRate.hashCode ^
451455
packetDelay.hashCode ^
452456
portMappingList.hashCode ^
453-
compressor.hashCode;
457+
compressor.hashCode ^
458+
allowWireGuard.hashCode ^
459+
localIpv4.hashCode;
454460

455461
@override
456462
bool operator ==(Object other) =>
@@ -481,5 +487,7 @@ class VntConfig {
481487
packetLossRate == other.packetLossRate &&
482488
packetDelay == other.packetDelay &&
483489
portMappingList == other.portMappingList &&
484-
compressor == other.compressor;
490+
compressor == other.compressor &&
491+
allowWireGuard == other.allowWireGuard &&
492+
localIpv4 == other.localIpv4;
485493
}

lib/src/rust/frb_generated.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
15361536
VntConfig dco_decode_vnt_config(dynamic raw) {
15371537
// Codec=Dco (DartCObject based), see doc to use other codecs
15381538
final arr = raw as List<dynamic>;
1539-
if (arr.length != 25)
1540-
throw Exception('unexpected arr length: expect 25 but see ${arr.length}');
1539+
if (arr.length != 27)
1540+
throw Exception('unexpected arr length: expect 27 but see ${arr.length}');
15411541
return VntConfig(
15421542
tap: dco_decode_bool(arr[0]),
15431543
token: dco_decode_String(arr[1]),
@@ -1564,6 +1564,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
15641564
packetDelay: dco_decode_u_32(arr[22]),
15651565
portMappingList: dco_decode_list_String(arr[23]),
15661566
compressor: dco_decode_String(arr[24]),
1567+
allowWireGuard: dco_decode_bool(arr[25]),
1568+
localIpv4: dco_decode_opt_String(arr[26]),
15671569
);
15681570
}
15691571

@@ -2118,6 +2120,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
21182120
var var_packetDelay = sse_decode_u_32(deserializer);
21192121
var var_portMappingList = sse_decode_list_String(deserializer);
21202122
var var_compressor = sse_decode_String(deserializer);
2123+
var var_allowWireGuard = sse_decode_bool(deserializer);
2124+
var var_localIpv4 = sse_decode_opt_String(deserializer);
21212125
return VntConfig(
21222126
tap: var_tap,
21232127
token: var_token,
@@ -2143,7 +2147,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
21432147
packetLossRate: var_packetLossRate,
21442148
packetDelay: var_packetDelay,
21452149
portMappingList: var_portMappingList,
2146-
compressor: var_compressor);
2150+
compressor: var_compressor,
2151+
allowWireGuard: var_allowWireGuard,
2152+
localIpv4: var_localIpv4);
21472153
}
21482154

21492155
@protected
@@ -2723,6 +2729,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
27232729
sse_encode_u_32(self.packetDelay, serializer);
27242730
sse_encode_list_String(self.portMappingList, serializer);
27252731
sse_encode_String(self.compressor, serializer);
2732+
sse_encode_bool(self.allowWireGuard, serializer);
2733+
sse_encode_opt_String(self.localIpv4, serializer);
27262734
}
27272735
}
27282736

0 commit comments

Comments
 (0)