mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Made coding style consistent with rest of project.
This commit is contained in:
@@ -3,37 +3,16 @@ package org.briarproject.plugins.tor;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.briarproject.api.system.LocationUtils;
|
||||
|
||||
public class TorNetworkMetadata {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(TorNetworkMetadata.class.getName());
|
||||
|
||||
// for country codes see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
||||
// below list from https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
||||
// See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
||||
// and https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
||||
// TODO: get a more complete list
|
||||
public static final Set<String> BLOCKED_IN_COUNTRIES = new HashSet<String>(Arrays.asList(
|
||||
"CN",
|
||||
"IR",
|
||||
"SY",
|
||||
//"ET", // possibly lifted - https://metrics.torproject.org/users.html?graph=userstats-relay-country&start=2012-02-08&end=2014-02-06&country=et&events=off#userstats-relay-country
|
||||
//"KZ", // unclear due to botnet - https://metrics.torproject.org/users.html?graph=userstats-relay-country&start=2012-02-08&end=2014-02-06&country=kz&events=off#userstats-relay-country
|
||||
//"PH", // unclear due to botnet - https://metrics.torproject.org/users.html?graph=userstats-relay-country&start=2012-02-08&end=2014-02-06&country=ph&events=off#userstats-relay-country
|
||||
//"AE", // unclear due to botnet - https://metrics.torproject.org/users.html?graph=userstats-relay-country&start=2012-02-08&end=2014-02-06&country=ae&events=off#userstats-relay-country
|
||||
//"GB", // for testing
|
||||
"ZZ"
|
||||
));
|
||||
private static final Set<String> BLOCKED_IN_COUNTRIES =
|
||||
new HashSet<String>(Arrays.asList("CN", "IR", "SY", "ZZ"));
|
||||
|
||||
public static boolean isTorProbablyBlocked(LocationUtils locationUtils) {
|
||||
String countryCode = locationUtils.getCurrentCountry();
|
||||
if (BLOCKED_IN_COUNTRIES.contains(countryCode)) {
|
||||
LOG.info("Tor is probably blocked in your country: " + countryCode);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public static boolean isTorProbablyBlocked(String countryCode) {
|
||||
return BLOCKED_IN_COUNTRIES.contains(countryCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.system.LocationUtils;
|
||||
import org.briarproject.plugins.AndroidPluginsModule;
|
||||
import org.briarproject.plugins.tor.TorNetworkMetadata;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
@@ -43,10 +41,14 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||
// Check that we have a Tor binary for this architecture
|
||||
if(!Build.CPU_ABI.startsWith("armeabi")) return null;
|
||||
// Check that we don't know that Tor is blocked here
|
||||
if (TorNetworkMetadata.isTorProbablyBlocked(locationUtils)) {
|
||||
LOG.info("Tor has been pre-emptively disabled since it is probably blocked");
|
||||
if(!Build.CPU_ABI.startsWith("armeabi")) {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user