mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Load bridges from file res/raw/bridges
This commit is contained in:
@@ -14,6 +14,7 @@ import org.briarproject.bramble.test.BrambleTestCase;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
@@ -25,7 +26,6 @@ import javax.net.SocketFactory;
|
|||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
import static org.briarproject.bramble.plugin.tor.BridgeProviderImpl.BRIDGES;
|
|
||||||
import static org.briarproject.bramble.plugin.tor.TorNetworkMetadata.doBridgesWork;
|
import static org.briarproject.bramble.plugin.tor.TorNetworkMetadata.doBridgesWork;
|
||||||
import static org.briarproject.bramble.plugin.tor.TorNetworkMetadata.isTorProbablyBlocked;
|
import static org.briarproject.bramble.plugin.tor.TorNetworkMetadata.isTorProbablyBlocked;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -50,6 +50,7 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
|
|
||||||
private final TorPluginFactory factory;
|
private final TorPluginFactory factory;
|
||||||
private TorPlugin plugin;
|
private TorPlugin plugin;
|
||||||
|
private final List<String> bridges;
|
||||||
private int currentBridge = 0;
|
private int currentBridge = 0;
|
||||||
|
|
||||||
public BridgeTest() {
|
public BridgeTest() {
|
||||||
@@ -62,8 +63,9 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
LocationUtils locationUtils = () -> BRIDGE_COUNTRY;
|
LocationUtils locationUtils = () -> BRIDGE_COUNTRY;
|
||||||
SocketFactory torSocketFactory = SocketFactory.getDefault();
|
SocketFactory torSocketFactory = SocketFactory.getDefault();
|
||||||
|
bridges = new BridgeProviderImpl().getBridges(appContext);
|
||||||
BridgeProvider bridgeProvider =
|
BridgeProvider bridgeProvider =
|
||||||
() -> singletonList(BRIDGES[currentBridge]);
|
context -> singletonList(bridges.get(currentBridge));
|
||||||
factory = new TorPluginFactory(ioExecutor, scheduler, appContext,
|
factory = new TorPluginFactory(ioExecutor, scheduler, appContext,
|
||||||
locationUtils, eventBus, torSocketFactory,
|
locationUtils, eventBus, torSocketFactory,
|
||||||
backoffFactory, bridgeProvider, clock);
|
backoffFactory, bridgeProvider, clock);
|
||||||
@@ -73,9 +75,9 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
public void testBridges() throws Exception {
|
public void testBridges() throws Exception {
|
||||||
assertTrue(isTorProbablyBlocked(BRIDGE_COUNTRY));
|
assertTrue(isTorProbablyBlocked(BRIDGE_COUNTRY));
|
||||||
assertTrue(doBridgesWork(BRIDGE_COUNTRY));
|
assertTrue(doBridgesWork(BRIDGE_COUNTRY));
|
||||||
assertTrue(BRIDGES.length > 0);
|
assertTrue(bridges.size() > 0);
|
||||||
|
|
||||||
for (int i = 0; i < BRIDGES.length; i++) {
|
for (int i = 0; i < bridges.size(); i++) {
|
||||||
plugin = (TorPlugin) factory.createPlugin(new TorPluginCallBack());
|
plugin = (TorPlugin) factory.createPlugin(new TorPluginCallBack());
|
||||||
testBridge(i);
|
testBridge(i);
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,7 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
|
|
||||||
private void testBridge(int bridge) throws Exception {
|
private void testBridge(int bridge) throws Exception {
|
||||||
currentBridge = bridge;
|
currentBridge = bridge;
|
||||||
LOG.warning("Testing " + BRIDGES[currentBridge]);
|
LOG.warning("Testing " + bridges.get(currentBridge));
|
||||||
try {
|
try {
|
||||||
plugin.start();
|
plugin.start();
|
||||||
long start = clock.currentTimeMillis();
|
long start = clock.currentTimeMillis();
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package org.briarproject.bramble.plugin.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface BridgeProvider {
|
public interface BridgeProvider {
|
||||||
|
|
||||||
List<String> getBridges();
|
@IoExecutor
|
||||||
|
List<String> getBridges(Context context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,42 @@
|
|||||||
package org.briarproject.bramble.plugin.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class BridgeProviderImpl implements BridgeProvider {
|
public class BridgeProviderImpl implements BridgeProvider {
|
||||||
|
|
||||||
final static String[] BRIDGES = {
|
private final static String BRIDGE_FILE_NAME = "bridges";
|
||||||
"Bridge 131.252.210.150:8081 0E858AC201BF0F3FA3C462F64844CBFFC7297A42",
|
|
||||||
// "Bridge 128.105.214.161:8081 1E326AAFB3FCB515015250D8FCCC8E37F91A153B",
|
@Nullable
|
||||||
"Bridge 67.205.189.122:8443 12D64D5D44E20169585E7378580C0D33A872AD98",
|
private volatile List<String> bridges = null;
|
||||||
"Bridge 45.32.148.146:8443 0CE016FB2462D8BF179AE71F7D702D09DEAC3F1D",
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getBridges() {
|
@IoExecutor
|
||||||
return Arrays.asList(BRIDGES);
|
public List<String> getBridges(Context context) {
|
||||||
|
if (this.bridges != null) return this.bridges;
|
||||||
|
|
||||||
|
Resources res = context.getResources();
|
||||||
|
int resId = res.getIdentifier(BRIDGE_FILE_NAME, "raw",
|
||||||
|
context.getPackageName());
|
||||||
|
InputStream is = context.getResources().openRawResource(resId);
|
||||||
|
Scanner scanner = new Scanner(is);
|
||||||
|
|
||||||
|
List<String> bridges = new ArrayList<>();
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
String line = scanner.nextLine();
|
||||||
|
if (!line.startsWith("#")) bridges.add(line);
|
||||||
|
}
|
||||||
|
this.bridges = bridges;
|
||||||
|
return bridges;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ class TorNetworkMetadata {
|
|||||||
/**
|
/**
|
||||||
* Countries where Tor is blocked, i.e. vanilla Tor connection won't work.
|
* Countries where Tor is blocked, i.e. vanilla Tor connection won't work.
|
||||||
*/
|
*/
|
||||||
private static final String[] BLOCKED = { "CN", "IR", "EG", "SY", "VE" };
|
private static final String[] BLOCKED =
|
||||||
|
{"CN", "IR", "EG", "BY", "TR", "SY", "VE"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Countries where vanilla bridge connection are likely to work.
|
* Countries where vanilla bridge connection are likely to work.
|
||||||
* Should be a subset of {@link #BLOCKED}.
|
* Should be a subset of {@link #BLOCKED}.
|
||||||
*/
|
*/
|
||||||
private static final String[] BRIDGES = { "SY", "VE" };
|
private static final String[] BRIDGES = { "EG", "BY", "TR", "SY", "VE" };
|
||||||
|
|
||||||
// See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
// See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
||||||
// and https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
// and https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
if (enable) {
|
if (enable) {
|
||||||
Collection<String> conf = new ArrayList<>();
|
Collection<String> conf = new ArrayList<>();
|
||||||
conf.add("UseBridges 1");
|
conf.add("UseBridges 1");
|
||||||
conf.addAll(bridgeProvider.getBridges());
|
conf.addAll(bridgeProvider.getBridges(appContext));
|
||||||
controlConnection.setConf(conf);
|
controlConnection.setConf(conf);
|
||||||
} else {
|
} else {
|
||||||
controlConnection.setConf("UseBridges", "0");
|
controlConnection.setConf("UseBridges", "0");
|
||||||
|
|||||||
4
bramble-android/src/main/res/raw/bridges
Normal file
4
bramble-android/src/main/res/raw/bridges
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Bridge 131.252.210.150:8081 0E858AC201BF0F3FA3C462F64844CBFFC7297A42
|
||||||
|
#Bridge 128.105.214.161:8081 1E326AAFB3FCB515015250D8FCCC8E37F91A153B
|
||||||
|
Bridge 67.205.189.122:8443 12D64D5D44E20169585E7378580C0D33A872AD98
|
||||||
|
Bridge 45.32.148.146:8443 0CE016FB2462D8BF179AE71F7D702D09DEAC3F1D
|
||||||
@@ -12,7 +12,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation for injecting the executor for long-running IO tasks. Also used
|
* Annotation for injecting the executor for long-running IO tasks. Also used
|
||||||
* for annotating methods that should run on the UI executor.
|
* for annotating methods that should run on the IO executor.
|
||||||
* <p>
|
* <p>
|
||||||
* The contract of this executor is that tasks may be run concurrently, and
|
* The contract of this executor is that tasks may be run concurrently, and
|
||||||
* submitting a task will never block. Tasks may run indefinitely. Tasks
|
* submitting a task will never block. Tasks may run indefinitely. Tasks
|
||||||
|
|||||||
Reference in New Issue
Block a user