Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/src/main/cpp/src/websocket_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Java_org_fptn_vpn_services_websocket_NativeWebSocketClientImpl_nativeStop(
// Send
extern "C" JNIEXPORT jboolean JNICALL
Java_org_fptn_vpn_services_websocket_NativeWebSocketClientImpl_nativeSend(
JNIEnv* env, jobject thiz, jlong native_handle, jbyteArray data) {
JNIEnv* env, jobject thiz, jlong native_handle, jbyteArray data, jlong length) {
(void)thiz;

bool status = false;
Expand All @@ -170,7 +170,6 @@ Java_org_fptn_vpn_services_websocket_NativeWebSocketClientImpl_nativeSend(
if (websocket_client && env && data) {
// Java bytes to std::string
jbyte* buffer = env->GetByteArrayElements(data, nullptr);
const jsize length = env->GetArrayLength(data);
if (buffer != nullptr && length != 0) {
std::string packet(reinterpret_cast<const char*>(buffer), length);
status = websocket_client->Send(std::move(packet));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class WrapperHttpsClient {
std::string md5_fingerprint,
fptn::protocol::https::CensorshipStrategy censorship_strategy);

Response Get(const std::string& handle, int timeout = 5);
Response Get(const std::string& handle, int timeout = 10);

Response Post(
const std::string& handle, const std::string& request, int timeout = 5);
const std::string& handle, const std::string& request, int timeout = 10);

private:
const JNIEnv* env_;
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/java/org/fptn/vpn/services/vpn/FptnConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ public void run() {

final String dnsServer = webSocketClient.getDnsServerIPv4();
builder.addDnsServer(dnsServer);
// builder.addDnsServer(InetAddress.getByName("1.1.1.1"));
// builder.addDnsServer(InetAddress.getByName("8.8.8.8"));
// builder.addDnsServer(InetAddress.getByName("9.9.9.9"));
// builder.addDnsServer(InetAddress.getByName("216.146.35.35"));
// builder.addDnsServer(InetAddress.getByName("208.67.222.222"));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
builder.excludeRoute(new IpPrefix(InetAddress.getByName(serverEntity.getHost()), 32));
builder.excludeRoute(TUN_INTERFACE_SUBNET.getAsIpPrefix());
Expand Down Expand Up @@ -242,8 +236,10 @@ public void run() {
try {
int length = inputStream.read(byteBuffer);
if (length > 0) {
// update speed count
uploadRate.update(length);
webSocketClient.send(byteBuffer);
// send byteArray with length of new bytes
webSocketClient.send(byteBuffer, length);
} else {
// if read buffer empty - sleep
// I set blocking mode - it looks like no need anymore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public boolean isStarted() {
return nativeIsStarted(nativeHandle);
}

public void send(byte[] data) {
public void send(byte[] data, long length) {
if (nativeHandle != 0L && nativeIsStarted(nativeHandle)) {
nativeSend(nativeHandle, data);
nativeSend(nativeHandle, data, length);
}
}

Expand Down Expand Up @@ -145,7 +145,7 @@ private native long nativeCreate(String server_ip,

private native boolean nativeStop(long nativeHandle);

private native boolean nativeSend(long nativeHandle, byte[] data);
private native boolean nativeSend(long nativeHandle, byte[] data, long length);

private native boolean nativeIsStarted(long nativeHandle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ public synchronized void stopWebSocket() {
}
}

public void send(byte[] bytes) {
if (nativeWebSocketClient != null && nativeWebSocketClient.isStarted()) {
nativeWebSocketClient.send(bytes);
public void send(byte[] bytes, long length) {
if (nativeWebSocketClient != null
&& nativeWebSocketClient.isStarted()
&& length > 0) {
nativeWebSocketClient.send(bytes, length);
} else {
throw new RuntimeException("nativeWebSocketClient is null or not started");
}
Expand All @@ -114,7 +116,7 @@ private String getAccessToken() throws PVNClientException {
serverEntity.getUsername(),
serverEntity.getPassword());

NativeResponse response = nativeHttpsClient.Post(LOGIN_URL, request, 5);
NativeResponse response = nativeHttpsClient.Post(LOGIN_URL, request, 15);
if (response != null) {
if (response.code == 200) {
try {
Expand All @@ -138,7 +140,7 @@ private String getAccessToken() throws PVNClientException {
}

public String getDnsServerIPv4() throws PVNClientException {
NativeResponse response = nativeHttpsClient.Get(DNS_URL, 5);
NativeResponse response = nativeHttpsClient.Get(DNS_URL, 15);
if (response != null) {
if (response.code == 200) {
try {
Expand Down