Skip to content

Commit

Permalink
fix connection intrupt issue, better connection state handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Feb 12, 2024
1 parent 1b6a707 commit bb9d7e7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 46 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "org.bepass.oblivion"
minSdk 21
targetSdk 34
versionCode 8
versionName "1.7"
versionCode 9
versionName "1.8"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -49,7 +49,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'])
}
2 changes: 1 addition & 1 deletion app/libs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/Psiphon-Labs/psiphon-tunnel-core => github.com/uoosef/psiphon
replace github.com/eycorsican/go-tun2socks => github.com/trojan-gfw/go-tun2socks v1.16.3-0.20210702214000-083d49176e05

require (
github.com/bepass-org/wireguard-go v1.0.2-rc1
github.com/bepass-org/wireguard-go v1.0.3-rc2
github.com/eycorsican/go-tun2socks v1.16.11
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/xjasonlyu/tun2socks/v2 v2.5.2
Expand Down
42 changes: 1 addition & 41 deletions app/src/main/java/org/bepass/oblivion/OblivionVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,15 @@
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import tun2socks.Tun2socks;
import tun2socks.StartOptions;

import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ServerSocket;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class OblivionVpnService extends VpnService {
private static final String TAG = "oblivionVPN";
Expand Down Expand Up @@ -135,39 +128,6 @@ public static Map<String, Integer> splitHostAndPort(String hostPort) {
return result;
}


public static String pingOverHTTP(String bindAddress) {
Map<String, Integer> result = splitHostAndPort(bindAddress);
if (result == null) {
return "exception";
}
String socksHost = result.keySet().iterator().next();
int socksPort = result.values().iterator().next();

// Set up the SOCKS proxy
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(socksHost, socksPort));

// Create OkHttpClient with SOCKS proxy
OkHttpClient client = new OkHttpClient.Builder()
.proxy(proxy)
.connectTimeout(5, TimeUnit.SECONDS) // 5 seconds connection timeout
.readTimeout(5, TimeUnit.SECONDS) // 5 seconds read timeout
.build();

// Build the request
Request request = new Request.Builder()
.url("https://1.1.1.1") // Replace with actual URL
.build();

// Execute the request
try (Response response = client.newCall(request).execute()) {
return response.isSuccessful() ? "true" : "false";
} catch (IOException e) {
//e.printStackTrace();
return Objects.requireNonNull(e.getMessage()).contains("ECONNREFUSED") || e.getMessage().contains("general failure") || e.getMessage().contains("timed out") ? "false" : "exception";
}
}

private static int findFreePort() {
ServerSocket socket = null;
try {
Expand Down Expand Up @@ -473,7 +433,7 @@ private void createNotification() {
this, 2, new Intent(this, MainActivity.class), PendingIntent.FLAG_IMMUTABLE);
notification = new NotificationCompat.Builder(this, notificationChannel.getId())
.setContentTitle("Vpn service")
.setContentText("Testing Tun2Socks")
.setContentText("Oblivion WARP")
.setSmallIcon(R.mipmap.ic_launcher)
.setOnlyAlertOnce(true)
.setOngoing(true)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
android:fontFamily="@font/shabnam"
android:textColor="@color/black"
android:gravity="center"
android:text="App Version: 0.0.7-test" />
android:text="App Version: 0.0.8-test" />


</LinearLayout>

0 comments on commit bb9d7e7

Please sign in to comment.