summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-10-19 02:10:30 +0200
committercyBerta <cyberta@riseup.net>2019-10-19 02:10:30 +0200
commit5cd9b7fdb0e78fbe30aca02ad75306a3a5208d3c (patch)
tree2ad0d77991bd6e3b33d5fdbfb4acec24fa6e1c9e /app
parenteab561951adcc46f32b93bd788b4f0ba120d7582 (diff)
fix error handling in Shapeshifter class
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java6
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/pluggableTransports/Shapeshifter.java61
2 files changed, 46 insertions, 21 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index e446021f..2c4462e0 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -387,11 +387,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
if (mProfile.mUsePluggableTransports) {
Obfs4Connection obfs4Connection = (Obfs4Connection) connection;
shapeshifter = new Shapeshifter(obfs4Connection.getDispatcherOptions());
- if (!shapeshifter.start()) {
- //TODO: implement useful error handling
- Log.e(TAG, "Cannot initialize shapeshifter dispatcher for obfs4 connection. Shutting down.");
- VpnStatus.logError("Cannot initialize shapeshifter dispatcher for obfs4 connection. Shutting down.");
- }
+ shapeshifter.start();
}
VpnStatus.logInfo(R.string.building_configration);
diff --git a/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/Shapeshifter.java b/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/Shapeshifter.java
index f7b18083..6d3b1db2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/Shapeshifter.java
+++ b/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/Shapeshifter.java
@@ -18,12 +18,16 @@
package se.leap.bitmaskclient.pluggableTransports;
import android.os.AsyncTask;
+import android.os.Handler;
+import android.os.Looper;
import android.util.Log;
+import java.lang.ref.WeakReference;
+
import de.blinkt.openvpn.core.VpnStatus;
import shapeshifter.ShapeShifter;
-public class Shapeshifter {
+public class Shapeshifter {
public static final String DISPATCHER_PORT = "4430";
public static final String DISPATCHER_IP = "127.0.0.1";
@@ -32,31 +36,48 @@ public class Shapeshifter {
ShapeShifter shapeShifter;
ShapeshifterErrorListner shapeshifterErrorListner;
+ public interface ShapeshifterErrorListenerCallback {
+ void onStarted();
+ }
+
public Shapeshifter(Obfs4Options options) {
shapeShifter = new ShapeShifter();
+ setup(options);
+ Log.d(TAG, "shapeshifter initialized with: \n" + shapeShifter.toString());
+ }
+
+ private void setup(Obfs4Options options) {
shapeShifter.setSocksAddr(DISPATCHER_IP+":"+DISPATCHER_PORT);
shapeShifter.setTarget(options.remoteIP+":"+options.remotePort);
shapeShifter.setCert(options.cert);
- Log.d(TAG, "shapeshifter initialized with: \n" + shapeShifter.toString());
}
- public boolean start() {
+ public void start() {
try {
- shapeshifterErrorListner = new ShapeshifterErrorListner();
+ ShapeshifterErrorListenerCallback errorListenerCallback = () -> {
+ ;
+ Handler handler = new Handler(Looper.getMainLooper());
+ handler.postDelayed(() -> {
+ try {
+ Log.d(TAG, "shapeshifter open");
+ shapeShifter.open();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }, 200);
+ };
+ shapeshifterErrorListner = new ShapeshifterErrorListner(errorListenerCallback);
shapeshifterErrorListner.execute(shapeShifter);
- shapeShifter.open();
- Log.d(TAG, "shapeshifter opened");
- return true;
+
} catch (Exception e) {
- VpnStatus.logError("SHAPESHIFTER ERROR " + e.getLocalizedMessage());
e.printStackTrace();
}
- return false;
}
public boolean stop() {
try {
shapeShifter.close();
+ shapeshifterErrorListner.cancel(true);
Log.d(TAG, "shapeshifter closed");
return true;
} catch (Exception e) {
@@ -67,28 +88,36 @@ public class Shapeshifter {
}
static class ShapeshifterErrorListner extends AsyncTask<ShapeShifter, Void, Void> {
+
+ WeakReference<ShapeshifterErrorListenerCallback> callbackWeakReference;
+
+ public ShapeshifterErrorListner(ShapeshifterErrorListenerCallback callback) {
+ callbackWeakReference = new WeakReference<>(callback);
+ }
+
@Override
protected Void doInBackground(ShapeShifter... shapeShifters) {
ShapeShifter shapeshifter = shapeShifters[0];
+ Log.d(TAG, "Shapeshifter error listener started");
+ ShapeshifterErrorListenerCallback callback = callbackWeakReference.get();
+ if (callback != null) {
+ callback.onStarted();
+ }
try {
shapeshifter.getLastError();
} catch (Exception e) {
e.printStackTrace();
- VpnStatus.logError("SHAPESHIFTER ERROR " + e.getLocalizedMessage());
+ Log.e(TAG, "SHAPESHIFTER ERROR: " + e.getLocalizedMessage());
+ VpnStatus.logError(VpnStatus.ErrorType.SHAPESHIFTER);
+ VpnStatus.logError(e.getLocalizedMessage());
try {
shapeshifter.close();
} catch (Exception ex) {
ex.printStackTrace();
- VpnStatus.logError("SHAPESHIFTER ERROR " + e.getLocalizedMessage());
}
}
return null;
}
-
- @Override
- protected void onPostExecute(Void aVoid) {
- super.onPostExecute(aVoid);
- }
}
}