From 304ba53807f34e2f377b7574549a4b9059d85fe4 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Thu, 6 Mar 2014 15:42:21 +0000 Subject: [PATCH] Check whether to enable or disable Tor at each connectivity change. --- .../org/briarproject/plugins/tor/TorPlugin.java | 17 ++++++++++++++--- .../plugins/tor/TorPluginFactory.java | 11 +++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java index 99e9295923..cccd2648e4 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java @@ -40,6 +40,7 @@ import org.briarproject.api.lifecycle.ShutdownManager; import org.briarproject.api.plugins.duplex.DuplexPlugin; import org.briarproject.api.plugins.duplex.DuplexPluginCallback; import org.briarproject.api.plugins.duplex.DuplexTransportConnection; +import org.briarproject.api.system.LocationUtils; import org.briarproject.util.StringUtils; import socks.Socks5Proxy; @@ -66,6 +67,7 @@ class TorPlugin implements DuplexPlugin, EventHandler { private final Executor pluginExecutor; private final Context appContext; + private final LocationUtils locationUtils; private final ShutdownManager shutdownManager; private final DuplexPluginCallback callback; private final int maxFrameLength; @@ -82,10 +84,12 @@ class TorPlugin implements DuplexPlugin, EventHandler { private volatile BroadcastReceiver networkStateReceiver = null; TorPlugin(Executor pluginExecutor, Context appContext, - ShutdownManager shutdownManager, DuplexPluginCallback callback, - int maxFrameLength, long maxLatency, long pollingInterval) { + LocationUtils locationUtils, ShutdownManager shutdownManager, + DuplexPluginCallback callback, int maxFrameLength, long maxLatency, + long pollingInterval) { this.pluginExecutor = pluginExecutor; this.appContext = appContext; + this.locationUtils = locationUtils; this.shutdownManager = shutdownManager; this.callback = callback; this.maxFrameLength = maxFrameLength; @@ -637,8 +641,15 @@ class TorPlugin implements DuplexPlugin, EventHandler { public void onReceive(Context ctx, Intent i) { // Note: Some devices fail to set this extra boolean online = !i.getBooleanExtra(EXTRA_NO_CONNECTIVITY, false); + String country = locationUtils.getCurrentCountry(); + if(LOG.isLoggable(INFO)){ + LOG.info("Online: " + online); + if("".equals(country)) LOG.info("Country code unknown"); + else LOG.info("Country code: " + country); + } + boolean blocked = TorNetworkMetadata.isTorProbablyBlocked(country); try { - enableNetwork(online); + enableNetwork(online && !blocked); } catch(IOException e) { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); } diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java b/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java index 57c7f04500..0990b6acab 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java @@ -45,13 +45,8 @@ public class TorPluginFactory implements DuplexPluginFactory { LOG.info("Tor is not supported on this architecture"); return null; } - // Check whether we know that Tor is blocked in this country - String countryCode = locationUtils.getCurrentCountry(); - if(TorNetworkMetadata.isTorProbablyBlocked(countryCode)) { - LOG.info("Tor has been disabled since it is probably blocked"); - return null; - } - return new TorPlugin(pluginExecutor,appContext, shutdownManager, - callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL); + return new TorPlugin(pluginExecutor,appContext, locationUtils, + shutdownManager, callback, MAX_FRAME_LENGTH, MAX_LATENCY, + POLLING_INTERVAL); } } -- GitLab