mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Add Android integration tests that checks if included bridges work
This also changes the way bridges are used. Instead of using the torrc config file, bridges are now activated via Tor's control port.
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
package org.briarproject.bramble;
|
||||
|
||||
import org.briarproject.bramble.plugin.tor.BridgeProvider;
|
||||
import org.briarproject.bramble.plugin.tor.BridgeProviderImpl;
|
||||
import org.briarproject.bramble.system.AndroidSystemModule;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module(includes = {
|
||||
AndroidSystemModule.class
|
||||
})
|
||||
public class BrambleAndroidModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
BridgeProvider provideBridgeProvider() {
|
||||
return new BridgeProviderImpl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.briarproject.bramble.plugin.tor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BridgeProvider {
|
||||
|
||||
List<String> getBridges();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.bramble.plugin.tor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
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",
|
||||
};
|
||||
|
||||
@Override
|
||||
public List<String> getBridges() {
|
||||
return Arrays.asList(BRIDGES);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,7 +50,9 @@ import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -120,6 +122,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
private final Backoff backoff;
|
||||
private final DuplexPluginCallback callback;
|
||||
private final String architecture;
|
||||
private final BridgeProvider bridgeProvider;
|
||||
private final int maxLatency, maxIdleTime, socketTimeout;
|
||||
private final ConnectionStatus connectionStatus;
|
||||
private final File torDirectory, torFile, geoIpFile, configFile;
|
||||
@@ -139,7 +142,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
Context appContext, LocationUtils locationUtils,
|
||||
SocketFactory torSocketFactory, Clock clock, Backoff backoff,
|
||||
DuplexPluginCallback callback, String architecture,
|
||||
int maxLatency, int maxIdleTime) {
|
||||
BridgeProvider bridgeProvider, int maxLatency, int maxIdleTime) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.scheduler = scheduler;
|
||||
this.appContext = appContext;
|
||||
@@ -149,6 +152,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
this.backoff = backoff;
|
||||
this.callback = callback;
|
||||
this.architecture = architecture;
|
||||
this.bridgeProvider = bridgeProvider;
|
||||
this.maxLatency = maxLatency;
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
if (maxIdleTime > Integer.MAX_VALUE / 2)
|
||||
@@ -499,6 +503,17 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void enableBridges(boolean enable) throws IOException {
|
||||
if (enable) {
|
||||
Collection<String> conf = new ArrayList<>();
|
||||
conf.add("UseBridges 1");
|
||||
conf.addAll(bridgeProvider.getBridges());
|
||||
controlConnection.setConf(conf);
|
||||
} else {
|
||||
controlConnection.setConf("UseBridges", "0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
running = false;
|
||||
@@ -681,7 +696,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
} else if (blocked) {
|
||||
if (doBridgesWork(country)) {
|
||||
LOG.info("Enabling network, using bridges");
|
||||
controlConnection.setConf("UseBridges", "1");
|
||||
enableBridges(true);
|
||||
enableNetwork(true);
|
||||
} else {
|
||||
LOG.info("Disabling network, country is blocked");
|
||||
@@ -693,6 +708,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
enableNetwork(false);
|
||||
} else {
|
||||
LOG.info("Enabling network");
|
||||
enableBridges(false);
|
||||
enableNetwork(true);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -43,12 +43,14 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
||||
private final EventBus eventBus;
|
||||
private final SocketFactory torSocketFactory;
|
||||
private final BackoffFactory backoffFactory;
|
||||
private final BridgeProvider bridgeProvider;
|
||||
private final Clock clock;
|
||||
|
||||
public TorPluginFactory(Executor ioExecutor,
|
||||
ScheduledExecutorService scheduler, Context appContext,
|
||||
LocationUtils locationUtils, EventBus eventBus,
|
||||
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
||||
BridgeProvider bridgeProvider,
|
||||
Clock clock) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.scheduler = scheduler;
|
||||
@@ -57,6 +59,7 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
||||
this.eventBus = eventBus;
|
||||
this.torSocketFactory = torSocketFactory;
|
||||
this.backoffFactory = backoffFactory;
|
||||
this.bridgeProvider = bridgeProvider;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@@ -95,7 +98,7 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
TorPlugin plugin = new TorPlugin(ioExecutor, scheduler, appContext,
|
||||
locationUtils, torSocketFactory, clock, backoff, callback,
|
||||
architecture, MAX_LATENCY, MAX_IDLE_TIME);
|
||||
architecture, bridgeProvider, MAX_LATENCY, MAX_IDLE_TIME);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user