From 9341f1e405bba7de0ea57a0588ac54ce653ff32f Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sun, 6 Oct 2019 00:21:49 +0200 Subject: write shapeshifter errors into Log fragment --- .../pluggableTransports/Shapeshifter.java | 39 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'app/src/main/java') 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 175e236a..f7b18083 100644 --- a/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/Shapeshifter.java +++ b/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/Shapeshifter.java @@ -17,8 +17,10 @@ package se.leap.bitmaskclient.pluggableTransports; +import android.os.AsyncTask; import android.util.Log; +import de.blinkt.openvpn.core.VpnStatus; import shapeshifter.ShapeShifter; public class Shapeshifter { @@ -28,25 +30,25 @@ public class Shapeshifter { private static final String TAG = Shapeshifter.class.getSimpleName(); ShapeShifter shapeShifter; + ShapeshifterErrorListner shapeshifterErrorListner; public Shapeshifter(Obfs4Options options) { shapeShifter = new ShapeShifter(); - shapeShifter.setIatMode(Long.valueOf(options.iatMode)); shapeShifter.setSocksAddr(DISPATCHER_IP+":"+DISPATCHER_PORT); shapeShifter.setTarget(options.remoteIP+":"+options.remotePort); shapeShifter.setCert(options.cert); - Log.d(TAG, "shapeshifter initialized with: iat - " + shapeShifter.getIatMode() + - "; socksAddr - " + shapeShifter.getSocksAddr() + - "; target addr - " + shapeShifter.getTarget() + - "; cert - " + shapeShifter.getCert()); + Log.d(TAG, "shapeshifter initialized with: \n" + shapeShifter.toString()); } public boolean start() { try { + shapeshifterErrorListner = new ShapeshifterErrorListner(); + 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; @@ -59,7 +61,34 @@ public class Shapeshifter { return true; } catch (Exception e) { e.printStackTrace(); + VpnStatus.logError("SHAPESHIFTER ERROR " + e.getLocalizedMessage()); } return false; } + + static class ShapeshifterErrorListner extends AsyncTask { + @Override + protected Void doInBackground(ShapeShifter... shapeShifters) { + ShapeShifter shapeshifter = shapeShifters[0]; + try { + shapeshifter.getLastError(); + } catch (Exception e) { + e.printStackTrace(); + VpnStatus.logError("SHAPESHIFTER ERROR " + 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); + } + } + } -- cgit v1.2.3