Skip to content

Commit

Permalink
支持指定端口和通道优先级
Browse files Browse the repository at this point in the history
  • Loading branch information
vnt-dev committed Oct 31, 2023
1 parent 8194e79 commit cae35be
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
ndk {
abiFilters 'arm64-v8a', 'x86_64'
}
versionName "1.2.4.4"
versionName "1.2.7"
}

buildTypes {
Expand Down
Binary file modified app/libs/arm64-v8a/libvnt_jni.so
Binary file not shown.
Binary file modified app/libs/x86_64/libvnt_jni.so
Binary file not shown.
23 changes: 22 additions & 1 deletion app/src/main/java/top/wherewego/vnt/AddActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class AddActivity extends AppActivity {
private Spinner mCipherModel;
private Spinner mConnectType;
private Spinner mFinger;
private Spinner mPriority;
private EditText mPort;

@Override
protected int getLayoutId() {
Expand Down Expand Up @@ -68,6 +70,8 @@ public void onRightClick(TitleBar titleBar) {
mCipherModel = findViewById(R.id.et_add_cipher_model_value);
mConnectType = findViewById(R.id.et_add_connect_type_value);
mFinger = findViewById(R.id.et_add_finger_value);
mPriority = findViewById(R.id.et_add_priority_value);
mPort = findViewById(R.id.et_add_port_value);
}

@Override
Expand Down Expand Up @@ -106,7 +110,23 @@ private void save() {
String cipherModel = mCipherModel.getSelectedItem().toString().trim();
String connectType = mConnectType.getSelectedItem().toString().trim();
String finger = mFinger.getSelectedItem().toString().trim();
String priority = mPriority.getSelectedItem().toString().trim();
String inIps = mInIps.getText().toString().trim();
String portStr = mPort.getText().toString().trim();
int port = 0;
if (!portStr.isEmpty()) {
try {
port = Integer.parseInt(portStr);
if (port < 0 || port >= 65535) {
Toast.makeText(this, "port错误", Toast.LENGTH_SHORT).show();
return;
}
} catch (Exception e) {
Toast.makeText(this, "port错误", Toast.LENGTH_SHORT).show();
return;
}
}

if (inIps.isEmpty()) {
inIps = null;
}
Expand All @@ -116,7 +136,8 @@ private void save() {
}
ConfigurationInfoBean configurationInfoBean = new ConfigurationInfoBean(
token, name, deviceId, password, server, stun,
cipherModel, "TCP".equalsIgnoreCase(connectType), "OPEN".equalsIgnoreCase(finger), inIps, outIps
cipherModel, "TCP".equalsIgnoreCase(connectType), "OPEN".equalsIgnoreCase(finger), inIps, outIps,
"latency".equalsIgnoreCase(priority),port
);
try {
String err = check(configurationInfoBean);
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/top/wherewego/vnt/MyVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ public synchronized int onStartCommand(Intent intent, int flags, int startId) {
boolean finger = selectConfigurationInfoBean.isFinger();
String inIps = selectConfigurationInfoBean.getInIps();
String outIps = selectConfigurationInfoBean.getOutIps();
boolean firstLatency = selectConfigurationInfoBean.isFirstLatency();
int port = selectConfigurationInfoBean.getPort();
config = new Config(token, name, deviceId, server, stunServer, password.isEmpty() ? null : password,
cipherModel, tcp, finger,inIps,outIps);
cipherModel, tcp, finger,inIps,outIps,firstLatency,port);
if (mThread == null) {
mThread = new Thread(this, "VntVPN");
mThread.start();
Expand Down
22 changes: 21 additions & 1 deletion app/src/main/java/top/wherewego/vnt/jni/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ public class Config {
private String cipherModel;
private boolean tcp;
private boolean finger;
private boolean firstLatency;
private int port;
private String inIps;
private String outIps;


public Config(String token, String name, String deviceId, String server,
String stunServer, String password, String cipherModel, boolean tcp,boolean finger,
String inIps,String outIps) {
String inIps,String outIps,boolean firstLatency,int port) {
this.token = token;
this.name = name;
this.deviceId = deviceId;
Expand All @@ -28,6 +30,8 @@ public Config(String token, String name, String deviceId, String server,
this.finger = finger;
this.inIps = inIps;
this.outIps = outIps;
this.firstLatency = firstLatency;
this.port = port;
}

public String getToken() {
Expand Down Expand Up @@ -117,4 +121,20 @@ public String getOutIps() {
public void setOutIps(String outIps) {
this.outIps = outIps;
}

public boolean isFirstLatency() {
return firstLatency;
}

public void setFirstLatency(boolean firstLatency) {
this.firstLatency = firstLatency;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public class ConfigurationInfoBean implements Serializable {
private boolean finger;
private String inIps;
private String outIps;
private boolean firstLatency;
private int port;

public ConfigurationInfoBean(String token, String name, String deviceId, String password,
String server, String stun, String cipherModel, boolean tcp, boolean finger,
String inIps, String outIps) {
String inIps, String outIps,boolean firstLatency,int port) {
this.key = String.valueOf(System.currentTimeMillis());
this.token = token;
this.name = name;
Expand All @@ -31,6 +33,8 @@ public ConfigurationInfoBean(String token, String name, String deviceId, String
this.finger = finger;
this.inIps = inIps;
this.outIps = outIps;
this.firstLatency = firstLatency;
this.port = port;
}

public String getKey() {
Expand Down Expand Up @@ -124,4 +128,20 @@ public String getOutIps() {
public void setOutIps(String outIps) {
this.outIps = outIps;
}

public boolean isFirstLatency() {
return firstLatency;
}

public void setFirstLatency(boolean firstLatency) {
this.firstLatency = firstLatency;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}
}
56 changes: 56 additions & 0 deletions app/src/main/res/layout/activity_add.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,62 @@
android:entries="@array/finger"
android:singleLine="true" />

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
tools:ignore="MissingConstraints">

<TextView
android:id="@+id/tv_add_priority"
android:layout_width="@dimen/dp_68"
android:gravity="end"
android:layout_height="wrap_content"
android:text="Priority:"
android:textSize="@dimen/sp_14"
android:textStyle="bold" />



<Spinner
android:id="@+id/et_add_priority_value"
style="@style/SpinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/priority"
android:singleLine="true" />

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
tools:ignore="MissingConstraints">

<TextView
android:id="@+id/tv_add_port"
android:layout_width="@dimen/dp_68"
android:gravity="end"
android:layout_height="wrap_content"
android:text="Port:"
android:textSize="@dimen/sp_14"
android:textStyle="bold" />



<top.wherewego.widget.view.RegexEditText
android:id="@+id/et_add_port_value"
style="@style/EditTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="监听端口"
android:inputType="number"
android:maxLength="@integer/sms_code_length"
android:singleLine="true" />

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<item>close</item>
<item>open</item>
</string-array>
<string-array name="priority">
<item>p2p</item>
<item>latency</item>
</string-array>
<string name="common_loading">加载中&#8230;</string>

<string name="common_unknown_error">未知错误</string>
Expand Down

0 comments on commit cae35be

Please sign in to comment.