From fece9e3133a39b885d014cabf62cd905b6667348 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sun, 26 Jun 2022 19:33:20 +0200 Subject: handle multi-threaded access to obfsvpn client state flags correctly --- .../bitmaskclient/pluggableTransports/ObfsVpnClient.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/ObfsVpnClient.java b/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/ObfsVpnClient.java index 632dc878..635f795d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/ObfsVpnClient.java +++ b/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/ObfsVpnClient.java @@ -4,6 +4,7 @@ import android.util.Log; import java.util.Observable; import java.util.Observer; +import java.util.concurrent.atomic.AtomicBoolean; import client.Client_; import de.blinkt.openvpn.core.ConnectionStatus; @@ -15,9 +16,9 @@ public class ObfsVpnClient implements Observer { public static final String SOCKS_IP = "127.0.0.1"; private static final String TAG = ObfsVpnClient.class.getSimpleName(); - private boolean noNetwork; + private volatile boolean noNetwork; // TODO: implement error signaling go->java - private boolean isErrorHandling; + private AtomicBoolean isErrorHandling = new AtomicBoolean(false); private final client.Client_ obfsVpnClient; private final Object LOCK = new Object(); @@ -34,6 +35,9 @@ public class ObfsVpnClient implements Observer { obfsVpnClient.start(); } catch (Exception e) { e.printStackTrace(); + if (noNetwork) { + isErrorHandling.set(true); + } } }).start(); @@ -56,6 +60,7 @@ public class ObfsVpnClient implements Observer { e.printStackTrace(); VpnStatus.logError("[obfsvpn] " + e.getLocalizedMessage()); } + isErrorHandling.set(false); Log.d(TAG, "stopping obfsVpnClient releasing LOCK ..."); } } @@ -73,8 +78,7 @@ public class ObfsVpnClient implements Observer { noNetwork = true; } else { noNetwork = false; - if (isErrorHandling) { - isErrorHandling = false; + if (isErrorHandling.getAndSet(false)) { stop(); start(); } -- cgit v1.2.3