Skip to content

Commit 9e03bec

Browse files
committed
更新1.2.3
1 parent 356748a commit 9e03bec

File tree

10 files changed

+281
-30
lines changed

10 files changed

+281
-30
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ android {
99
ndk {
1010
abiFilters 'arm64-v8a', 'x86_64'
1111
}
12+
versionName "1.2.3"
1213
}
1314

1415
buildTypes {

app/libs/arm64-v8a/libvnt_jni.so

663 KB
Binary file not shown.

app/libs/x86_64/libvnt_jni.so

340 KB
Binary file not shown.

app/src/main/java/top/wherewego/vnt/AddActivity.java

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import top.wherewego.vnt.app.AppActivity;
1414
import top.wherewego.vnt.app.AppApplication;
15+
import top.wherewego.vnt.util.IpRouteUtils;
1516
import top.wherewego.vnt.util.SPUtils;
1617
import top.wherewego.vnt.jni.ConfigurationInfoBean;
1718

@@ -23,6 +24,8 @@ public class AddActivity extends AppActivity {
2324
private EditText mPassword;
2425
private EditText mServer;
2526
private EditText mStun;
27+
private EditText mInIps;
28+
private EditText mOutIps;
2629
private Spinner mCipherModel;
2730
private Spinner mConnectType;
2831
private Spinner mFinger;
@@ -60,6 +63,8 @@ public void onRightClick(TitleBar titleBar) {
6063
mPassword = findViewById(R.id.et_add_password_value);
6164
mServer = findViewById(R.id.et_add_server_value);
6265
mStun = findViewById(R.id.et_add_stun_value);
66+
mInIps = findViewById(R.id.et_add_in_ip_value);
67+
mOutIps = findViewById(R.id.et_add_out_ip_value);
6368
mCipherModel = findViewById(R.id.et_add_cipher_model_value);
6469
mConnectType = findViewById(R.id.et_add_connect_type_value);
6570
mFinger = findViewById(R.id.et_add_finger_value);
@@ -91,14 +96,38 @@ private void save() {
9196
Toast.makeText(this, "stun不能为空", Toast.LENGTH_SHORT).show();
9297
return;
9398
}
99+
String token = mToken.getText().toString().trim();
100+
String name = mName.getText().toString().trim();
101+
String deviceId = mDeviceId.getText().toString().trim();
102+
String password = mPassword.getText().toString().trim();
103+
String server = mServer.getText().toString().trim();
104+
105+
String stun = mStun.getText().toString().trim();
94106
String cipherModel = mCipherModel.getSelectedItem().toString().trim();
95107
String connectType = mConnectType.getSelectedItem().toString().trim();
96108
String finger = mFinger.getSelectedItem().toString().trim();
109+
String inIps = mInIps.getText().toString().trim();
110+
if (inIps.isEmpty()) {
111+
inIps = null;
112+
}
113+
String outIps = mOutIps.getText().toString().trim();
114+
if (outIps.isEmpty()) {
115+
outIps = null;
116+
}
97117
ConfigurationInfoBean configurationInfoBean = new ConfigurationInfoBean(
98-
mToken.getText().toString().trim(), mName.getText().toString().trim(), mDeviceId.getText().toString().trim(),
99-
mPassword.getText().toString().trim(), mServer.getText().toString().trim(), mStun.getText().toString().trim(),
100-
cipherModel, "TCP".equalsIgnoreCase(connectType),"OPEN".equalsIgnoreCase(finger)
118+
token, name, deviceId, password, server, stun,
119+
cipherModel, "TCP".equalsIgnoreCase(connectType), "OPEN".equalsIgnoreCase(finger), inIps, outIps
101120
);
121+
try {
122+
String err = check(configurationInfoBean);
123+
if (err != null) {
124+
Toast.makeText(this, err, Toast.LENGTH_SHORT).show();
125+
return;
126+
}
127+
} catch (Exception e) {
128+
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
129+
return;
130+
}
102131

103132
String keyset = SPUtils.getString(getApplicationContext(), "keyset", "0");
104133
if (keyset.equals("0")) {
@@ -111,4 +140,32 @@ private void save() {
111140
finish();
112141
}
113142

143+
String check(ConfigurationInfoBean configurationInfoBean) {
144+
String[] parts = configurationInfoBean.getServer().split(":");
145+
146+
if (parts.length != 2) {
147+
return "服务器地址错误";
148+
}
149+
int port = 0;
150+
try {
151+
port = Integer.parseInt(parts[1]);
152+
} catch (Exception ignored) {
153+
}
154+
if (port <= 0 || port >= 65536) {
155+
return "服务端口错误";
156+
}
157+
String err;
158+
err = IpRouteUtils.checkInIps(configurationInfoBean.getInIps());
159+
if (err != null) {
160+
return "inIps错误:" + err;
161+
162+
}
163+
err = IpRouteUtils.checkOutIps(configurationInfoBean.getOutIps());
164+
if (err != null) {
165+
return "outIps错误:" + err;
166+
167+
}
168+
return null;
169+
}
170+
114171
}

app/src/main/java/top/wherewego/vnt/ConnectActivity.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ private void startMyVpnService() {
8787
String name = selectConfigurationInfoBean.getName().trim();
8888
String server = selectConfigurationInfoBean.getServer().trim();
8989
String stun = selectConfigurationInfoBean.getStun().trim();
90-
String password = selectConfigurationInfoBean.getPassword().trim();
9190
String cipherModel = selectConfigurationInfoBean.getCipherModel().trim();
92-
boolean tcp = selectConfigurationInfoBean.isTcp();
93-
boolean finger = selectConfigurationInfoBean.isFinger();
9491
if (token.isEmpty()) {
9592
Toast.makeText(this, "Token不能为空", Toast.LENGTH_SHORT).show();
9693
return;
@@ -131,15 +128,8 @@ private void startMyVpnService() {
131128
}
132129
Intent serviceIntent = new Intent(this, MyVpnService.class);
133130
serviceIntent.setAction("start");
134-
serviceIntent.putExtra("token", token);
135-
serviceIntent.putExtra("deviceId", deviceId);
136-
serviceIntent.putExtra("name", name);
137-
serviceIntent.putExtra("server", server);
138-
serviceIntent.putExtra("stunServer", stun);
139-
serviceIntent.putExtra("password",password);
140-
serviceIntent.putExtra("cipherModel",cipherModel);
141-
serviceIntent.putExtra("tcp",tcp);
142-
serviceIntent.putExtra("finger",finger);
131+
serviceIntent.putExtra("config",selectConfigurationInfoBean);
132+
143133
startService(serviceIntent);
144134
}
145135

app/src/main/java/top/wherewego/vnt/MyVpnService.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import java.net.InetSocketAddress;
1616
import java.util.ArrayList;
1717
import java.util.List;
18+
import java.util.Objects;
1819

1920
import top.wherewego.vnt.jni.Config;
21+
import top.wherewego.vnt.jni.ConfigurationInfoBean;
2022
import top.wherewego.vnt.jni.DeviceBean;
2123
import top.wherewego.vnt.jni.IpUtils;
2224
import top.wherewego.vnt.jni.PeerDeviceInfo;
@@ -26,6 +28,7 @@
2628
import top.wherewego.vnt.jni.exception.AddressExhaustedException;
2729
import top.wherewego.vnt.jni.exception.TimeoutException;
2830
import top.wherewego.vnt.jni.exception.TokenErrorException;
31+
import top.wherewego.vnt.util.IpRouteUtils;
2932

3033
public class MyVpnService extends VpnService implements Runnable {
3134
private static MyVpnService myVpnService;
@@ -67,16 +70,20 @@ public synchronized int onStartCommand(Intent intent, int flags, int startId) {
6770
switch (intent.getAction()) {
6871
case "start": {
6972
isRun = true;
70-
String token = intent.getStringExtra("token");
71-
String deviceId = intent.getStringExtra("deviceId");
72-
String name = intent.getStringExtra("name");
73-
String password = intent.getStringExtra("password");
74-
String server = intent.getStringExtra("server");
75-
String stunServer = intent.getStringExtra("stunServer");
76-
String cipherModel = intent.getStringExtra("cipherModel");
77-
boolean tcp = intent.getBooleanExtra("tcp", false);
78-
boolean finger = intent.getBooleanExtra("finger", false);
79-
config = new Config(token, name, deviceId, server, stunServer, password.isEmpty() ? null : password, cipherModel, tcp,finger);
73+
ConfigurationInfoBean selectConfigurationInfoBean = (ConfigurationInfoBean) intent.getSerializableExtra("config");
74+
String token = selectConfigurationInfoBean.getToken();
75+
String deviceId = selectConfigurationInfoBean.getDeviceId();
76+
String name = selectConfigurationInfoBean.getName();
77+
String password = selectConfigurationInfoBean.getPassword();
78+
String server = selectConfigurationInfoBean.getServer();
79+
String stunServer = selectConfigurationInfoBean.getStun();
80+
String cipherModel = selectConfigurationInfoBean.getCipherModel();
81+
boolean tcp = selectConfigurationInfoBean.isTcp();
82+
boolean finger = selectConfigurationInfoBean.isFinger();
83+
String inIps = selectConfigurationInfoBean.getInIps();
84+
String outIps = selectConfigurationInfoBean.getOutIps();
85+
config = new Config(token, name, deviceId, server, stunServer, password.isEmpty() ? null : password,
86+
cipherModel, tcp, finger,inIps,outIps);
8087
if (mThread == null) {
8188
mThread = new Thread(this, "VntVPN");
8289
mThread.start();
@@ -103,7 +110,7 @@ public void run() {
103110
run0();
104111
} catch (Throwable e) {
105112
Handler handler = new Handler(Looper.getMainLooper());
106-
handler.post(() -> Toast.makeText(getApplicationContext(), "启动失败", Toast.LENGTH_LONG).show());
113+
handler.post(() -> Toast.makeText(getApplicationContext(), "启动失败:"+e.getMessage(), Toast.LENGTH_LONG).show());
107114
}
108115
Handler handler = new Handler(Looper.getMainLooper());
109116
handler.post(() -> {
@@ -183,12 +190,16 @@ private void run0() {
183190
Builder builder = new Builder();
184191
int prefixLength = IpUtils.subnetMaskToPrefixLength(connect.getVirtualNetmask());
185192
String ipRoute = IpUtils.intToIpAddress(connect.getVirtualGateway() & connect.getVirtualNetmask());
193+
List<IpRouteUtils.RouteItem> routeItems = IpRouteUtils.inIp(config.getInIps());
186194
builder.setSession("VntVPN")
187195
.setBlocking(true)
188-
.setMtu(1420)
196+
.setMtu(1410)
189197
.addAddress(ip, prefixLength)
190-
// .addDnsServer("8.8.8.8")
198+
.addDnsServer("8.8.8.8")
191199
.addRoute(ipRoute, prefixLength);
200+
for (IpRouteUtils.RouteItem routeItem : routeItems) {
201+
builder.addAddress(routeItem.address,routeItem.prefixLength);
202+
}
192203
builder.allowFamily(OsConstants.AF_INET);
193204
mInterface = builder.establish();
194205
int fd = mInterface.getFd();

app/src/main/java/top/wherewego/vnt/jni/Config.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ public class Config {
1010
private String cipherModel;
1111
private boolean tcp;
1212
private boolean finger;
13+
private String inIps;
14+
private String outIps;
1315

1416

15-
public Config(String token, String name, String deviceId, String server, String stunServer, String password, String cipherModel, boolean tcp,boolean finger) {
17+
public Config(String token, String name, String deviceId, String server,
18+
String stunServer, String password, String cipherModel, boolean tcp,boolean finger,
19+
String inIps,String outIps) {
1620
this.token = token;
1721
this.name = name;
1822
this.deviceId = deviceId;
@@ -22,6 +26,8 @@ public Config(String token, String name, String deviceId, String server, String
2226
this.cipherModel = cipherModel;
2327
this.tcp = tcp;
2428
this.finger = finger;
29+
this.inIps = inIps;
30+
this.outIps = outIps;
2531
}
2632

2733
public String getToken() {
@@ -95,4 +101,20 @@ public boolean isFinger() {
95101
public void setFinger(boolean finger) {
96102
this.finger = finger;
97103
}
104+
105+
public String getInIps() {
106+
return inIps;
107+
}
108+
109+
public void setInIps(String inIps) {
110+
this.inIps = inIps;
111+
}
112+
113+
public String getOutIps() {
114+
return outIps;
115+
}
116+
117+
public void setOutIps(String outIps) {
118+
this.outIps = outIps;
119+
}
98120
}

app/src/main/java/top/wherewego/vnt/jni/ConfigurationInfoBean.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ public class ConfigurationInfoBean implements Serializable {
1313
private String cipherModel;
1414
private boolean tcp;
1515
private boolean finger;
16+
private String inIps;
17+
private String outIps;
1618

17-
public ConfigurationInfoBean(String token, String name, String deviceId, String password, String server, String stun, String cipherModel, boolean tcp, boolean finger) {
19+
public ConfigurationInfoBean(String token, String name, String deviceId, String password,
20+
String server, String stun, String cipherModel, boolean tcp, boolean finger,
21+
String inIps, String outIps) {
1822
this.key = String.valueOf(System.currentTimeMillis());
1923
this.token = token;
2024
this.name = name;
@@ -25,6 +29,8 @@ public ConfigurationInfoBean(String token, String name, String deviceId, String
2529
this.cipherModel = cipherModel;
2630
this.tcp = tcp;
2731
this.finger = finger;
32+
this.inIps = inIps;
33+
this.outIps = outIps;
2834
}
2935

3036
public String getKey() {
@@ -102,4 +108,20 @@ public boolean isFinger() {
102108
public void setFinger(boolean finger) {
103109
this.finger = finger;
104110
}
111+
112+
public String getInIps() {
113+
return inIps;
114+
}
115+
116+
public void setInIps(String inIps) {
117+
this.inIps = inIps;
118+
}
119+
120+
public String getOutIps() {
121+
return outIps;
122+
}
123+
124+
public void setOutIps(String outIps) {
125+
this.outIps = outIps;
126+
}
105127
}

0 commit comments

Comments
 (0)