mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +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.runner.RunWith;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -25,7 +26,6 @@ import javax.net.SocketFactory;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
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.isTorProbablyBlocked;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -50,6 +50,7 @@ public class BridgeTest extends BrambleTestCase {
|
||||
|
||||
private final TorPluginFactory factory;
|
||||
private TorPlugin plugin;
|
||||
private final List<String> bridges;
|
||||
private int currentBridge = 0;
|
||||
|
||||
public BridgeTest() {
|
||||
@@ -62,8 +63,9 @@ public class BridgeTest extends BrambleTestCase {
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
LocationUtils locationUtils = () -> BRIDGE_COUNTRY;
|
||||
SocketFactory torSocketFactory = SocketFactory.getDefault();
|
||||
bridges = new BridgeProviderImpl().getBridges(appContext);
|
||||
BridgeProvider bridgeProvider =
|
||||
() -> singletonList(BRIDGES[currentBridge]);
|
||||
context -> singletonList(bridges.get(currentBridge));
|
||||
factory = new TorPluginFactory(ioExecutor, scheduler, appContext,
|
||||
locationUtils, eventBus, torSocketFactory,
|
||||
backoffFactory, bridgeProvider, clock);
|
||||
@@ -73,9 +75,9 @@ public class BridgeTest extends BrambleTestCase {
|
||||
public void testBridges() throws Exception {
|
||||
assertTrue(isTorProbablyBlocked(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());
|
||||
testBridge(i);
|
||||
}
|
||||
@@ -83,7 +85,7 @@ public class BridgeTest extends BrambleTestCase {
|
||||
|
||||
private void testBridge(int bridge) throws Exception {
|
||||
currentBridge = bridge;
|
||||
LOG.warning("Testing " + BRIDGES[currentBridge]);
|
||||
LOG.warning("Testing " + bridges.get(currentBridge));
|
||||
try {
|
||||
plugin.start();
|
||||
long start = clock.currentTimeMillis();
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package org.briarproject.bramble.plugin.tor;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BridgeProvider {
|
||||
|
||||
List<String> getBridges();
|
||||
@IoExecutor
|
||||
List<String> getBridges(Context context);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,42 @@
|
||||
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.Scanner;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BridgeProviderImpl implements BridgeProvider {
|
||||
|
||||
final static String[] BRIDGES = {
|
||||
"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",
|
||||
};
|
||||
private final static String BRIDGE_FILE_NAME = "bridges";
|
||||
|
||||
@Nullable
|
||||
private volatile List<String> bridges = null;
|
||||
|
||||
@Override
|
||||
public List<String> getBridges() {
|
||||
return Arrays.asList(BRIDGES);
|
||||
@IoExecutor
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
* 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
|
||||
// and https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
||||
|
||||
@@ -507,7 +507,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
if (enable) {
|
||||
Collection<String> conf = new ArrayList<>();
|
||||
conf.add("UseBridges 1");
|
||||
conf.addAll(bridgeProvider.getBridges());
|
||||
conf.addAll(bridgeProvider.getBridges(appContext));
|
||||
controlConnection.setConf(conf);
|
||||
} else {
|
||||
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
|
||||
* for annotating methods that should run on the UI executor.
|
||||
* for annotating methods that should run on the IO executor.
|
||||
* <p>
|
||||
* The contract of this executor is that tasks may be run concurrently, and
|
||||
* submitting a task will never block. Tasks may run indefinitely. Tasks
|
||||
|
||||
Reference in New Issue
Block a user