mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Compare commits
4 Commits
beta-1.4.9
...
remove-bac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98e5d892a4 | ||
|
|
94f8f68336 | ||
|
|
2f8dd51ef8 | ||
|
|
5dd1c28e77 |
@@ -12,7 +12,6 @@ import android.content.IntentFilter;
|
||||
import org.briarproject.bramble.api.io.TimeoutMonitor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.PluginException;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
@@ -82,10 +81,10 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
||||
TimeoutMonitor timeoutMonitor, Executor ioExecutor,
|
||||
SecureRandom secureRandom, ScheduledExecutorService scheduler,
|
||||
AndroidExecutor androidExecutor, Context appContext, Clock clock,
|
||||
Backoff backoff, PluginCallback callback, int maxLatency,
|
||||
int maxIdleTime) {
|
||||
PluginCallback callback, int maxLatency, int maxIdleTime,
|
||||
int pollingInterval) {
|
||||
super(connectionLimiter, timeoutMonitor, ioExecutor, secureRandom,
|
||||
backoff, callback, maxLatency, maxIdleTime);
|
||||
callback, maxLatency, maxIdleTime, pollingInterval);
|
||||
this.scheduler = scheduler;
|
||||
this.androidExecutor = androidExecutor;
|
||||
this.appContext = appContext;
|
||||
|
||||
@@ -5,8 +5,6 @@ import android.content.Context;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.io.TimeoutMonitor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
@@ -20,17 +18,17 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||
private static final int MIN_POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
private static final int MAX_LATENCY = (int) SECONDS.toMillis(30);
|
||||
private static final int MAX_IDLE_TIME = (int) SECONDS.toMillis(30);
|
||||
private static final int POLLING_INTERVAL = (int) MINUTES.toMillis(2);
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
@@ -40,13 +38,12 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
private final EventBus eventBus;
|
||||
private final Clock clock;
|
||||
private final TimeoutMonitor timeoutMonitor;
|
||||
private final BackoffFactory backoffFactory;
|
||||
|
||||
public AndroidBluetoothPluginFactory(Executor ioExecutor,
|
||||
ScheduledExecutorService scheduler,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
SecureRandom secureRandom, EventBus eventBus, Clock clock,
|
||||
TimeoutMonitor timeoutMonitor, BackoffFactory backoffFactory) {
|
||||
TimeoutMonitor timeoutMonitor) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.scheduler = scheduler;
|
||||
this.androidExecutor = androidExecutor;
|
||||
@@ -55,7 +52,6 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
this.eventBus = eventBus;
|
||||
this.clock = clock;
|
||||
this.timeoutMonitor = timeoutMonitor;
|
||||
this.backoffFactory = backoffFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,12 +68,10 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
BluetoothConnectionLimiter connectionLimiter =
|
||||
new BluetoothConnectionLimiterImpl(eventBus);
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
AndroidBluetoothPlugin plugin = new AndroidBluetoothPlugin(
|
||||
connectionLimiter, timeoutMonitor, ioExecutor, secureRandom,
|
||||
scheduler, androidExecutor, appContext, clock, backoff,
|
||||
callback, MAX_LATENCY, MAX_IDLE_TIME);
|
||||
scheduler, androidExecutor, appContext, clock, callback,
|
||||
MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.briarproject.bramble.api.Pair;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.network.event.NetworkStatusEvent;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
|
||||
@@ -62,9 +61,9 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
private volatile SocketFactory socketFactory;
|
||||
|
||||
AndroidLanTcpPlugin(Executor ioExecutor, Context appContext,
|
||||
Backoff backoff, PluginCallback callback, int maxLatency,
|
||||
int maxIdleTime, int connectionTimeout) {
|
||||
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime,
|
||||
PluginCallback callback, int maxLatency, int maxIdleTime,
|
||||
int pollingInterval, int connectionTimeout) {
|
||||
super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval,
|
||||
connectionTimeout);
|
||||
// Don't execute more than one connection status check at a time
|
||||
connectionStatusExecutor =
|
||||
|
||||
@@ -4,8 +4,6 @@ import android.content.Context;
|
||||
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
@@ -15,29 +13,27 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_LATENCY = 30_000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30_000; // 30 seconds
|
||||
private static final int CONNECTION_TIMEOUT = 3_000; // 3 seconds
|
||||
private static final int MIN_POLLING_INTERVAL = 60_000; // 1 minute
|
||||
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
private static final int MAX_LATENCY = (int) SECONDS.toMillis(30);
|
||||
private static final int MAX_IDLE_TIME = (int) SECONDS.toMillis(30);
|
||||
private static final int POLLING_INTERVAL = (int) MINUTES.toMillis(1);
|
||||
private static final int CONNECTION_TIMEOUT = (int) SECONDS.toMillis(3);
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final EventBus eventBus;
|
||||
private final BackoffFactory backoffFactory;
|
||||
private final Context appContext;
|
||||
|
||||
public AndroidLanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
|
||||
BackoffFactory backoffFactory, Context appContext) {
|
||||
Context appContext) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.eventBus = eventBus;
|
||||
this.backoffFactory = backoffFactory;
|
||||
this.appContext = appContext;
|
||||
}
|
||||
|
||||
@@ -53,11 +49,9 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
@Override
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
AndroidLanTcpPlugin plugin = new AndroidLanTcpPlugin(ioExecutor,
|
||||
appContext, backoff, callback, MAX_LATENCY, MAX_IDLE_TIME,
|
||||
CONNECTION_TIMEOUT);
|
||||
appContext, callback, MAX_LATENCY, MAX_IDLE_TIME,
|
||||
POLLING_INTERVAL, CONNECTION_TIMEOUT);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.briarproject.bramble.api.battery.BatteryManager;
|
||||
import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.system.LocationUtils;
|
||||
@@ -41,13 +40,15 @@ class AndroidTorPlugin extends TorPlugin {
|
||||
LocationUtils locationUtils, SocketFactory torSocketFactory,
|
||||
Clock clock, ResourceProvider resourceProvider,
|
||||
CircumventionProvider circumventionProvider,
|
||||
BatteryManager batteryManager, Backoff backoff,
|
||||
BatteryManager batteryManager,
|
||||
TorRendezvousCrypto torRendezvousCrypto,
|
||||
PluginCallback callback, String architecture, int maxLatency,
|
||||
int maxIdleTime) {
|
||||
int maxIdleTime, int initialPollingInterval,
|
||||
int stablePollingInterval) {
|
||||
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
|
||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
||||
backoff, torRendezvousCrypto, callback, architecture, maxLatency, maxIdleTime,
|
||||
torRendezvousCrypto, callback, architecture, maxLatency,
|
||||
maxIdleTime, initialPollingInterval, stablePollingInterval,
|
||||
appContext.getDir("tor", MODE_PRIVATE));
|
||||
this.appContext = appContext;
|
||||
PowerManager pm = (PowerManager)
|
||||
|
||||
@@ -6,8 +6,6 @@ import org.briarproject.bramble.api.battery.BatteryManager;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
@@ -25,18 +23,33 @@ import java.util.logging.Logger;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(AndroidTorPluginFactory.class.getName());
|
||||
getLogger(AndroidTorPluginFactory.class.getName());
|
||||
|
||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||
private static final int MIN_POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
private static final int MAX_LATENCY = (int) SECONDS.toMillis(30);
|
||||
private static final int MAX_IDLE_TIME = (int) SECONDS.toMillis(30);
|
||||
|
||||
/**
|
||||
* How often to poll before our hidden service becomes reachable.
|
||||
*/
|
||||
private static final int INITIAL_POLLING_INTERVAL =
|
||||
(int) MINUTES.toMillis(1);
|
||||
|
||||
/**
|
||||
* How often to poll when our hidden service is reachable. Our contacts
|
||||
* will poll when they come online, so our polling is just a fallback in
|
||||
* case of repeated connection failures.
|
||||
*/
|
||||
private static final int STABLE_POLLING_INTERVAL =
|
||||
(int) MINUTES.toMillis(15);
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
@@ -45,7 +58,6 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
||||
private final LocationUtils locationUtils;
|
||||
private final EventBus eventBus;
|
||||
private final SocketFactory torSocketFactory;
|
||||
private final BackoffFactory backoffFactory;
|
||||
private final ResourceProvider resourceProvider;
|
||||
private final CircumventionProvider circumventionProvider;
|
||||
private final BatteryManager batteryManager;
|
||||
@@ -55,7 +67,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
||||
ScheduledExecutorService scheduler, Context appContext,
|
||||
NetworkManager networkManager, LocationUtils locationUtils,
|
||||
EventBus eventBus, SocketFactory torSocketFactory,
|
||||
BackoffFactory backoffFactory, ResourceProvider resourceProvider,
|
||||
ResourceProvider resourceProvider,
|
||||
CircumventionProvider circumventionProvider,
|
||||
BatteryManager batteryManager, Clock clock) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
@@ -65,7 +77,6 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
||||
this.locationUtils = locationUtils;
|
||||
this.eventBus = eventBus;
|
||||
this.torSocketFactory = torSocketFactory;
|
||||
this.backoffFactory = backoffFactory;
|
||||
this.resourceProvider = resourceProvider;
|
||||
this.circumventionProvider = circumventionProvider;
|
||||
this.batteryManager = batteryManager;
|
||||
@@ -109,14 +120,13 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
||||
// Use position-independent executable
|
||||
architecture += "_pie";
|
||||
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
||||
AndroidTorPlugin plugin = new AndroidTorPlugin(ioExecutor, scheduler,
|
||||
appContext, networkManager, locationUtils, torSocketFactory,
|
||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
||||
backoff, torRendezvousCrypto, callback, architecture,
|
||||
MAX_LATENCY, MAX_IDLE_TIME);
|
||||
torRendezvousCrypto, callback, architecture, MAX_LATENCY,
|
||||
MAX_IDLE_TIME, INITIAL_POLLING_INTERVAL,
|
||||
STABLE_POLLING_INTERVAL);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package org.briarproject.bramble.api.plugin;
|
||||
|
||||
/**
|
||||
* Calculates polling intervals for transport plugins that use backoff.
|
||||
*/
|
||||
public interface Backoff {
|
||||
|
||||
/**
|
||||
* Returns the current polling interval.
|
||||
*/
|
||||
int getPollingInterval();
|
||||
|
||||
/**
|
||||
* Increments the backoff counter.
|
||||
*/
|
||||
void increment();
|
||||
|
||||
/**
|
||||
* Resets the backoff counter.
|
||||
*/
|
||||
void reset();
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.briarproject.bramble.api.plugin;
|
||||
|
||||
public interface BackoffFactory {
|
||||
|
||||
Backoff createBackoff(int minInterval, int maxInterval,
|
||||
double base);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.briarproject.bramble.plugin;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class BackoffFactoryImpl implements BackoffFactory {
|
||||
|
||||
@Override
|
||||
public Backoff createBackoff(int minInterval, int maxInterval,
|
||||
double base) {
|
||||
return new BackoffImpl(minInterval, maxInterval, base);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.briarproject.bramble.plugin;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
class BackoffImpl implements Backoff {
|
||||
|
||||
private final int minInterval, maxInterval;
|
||||
private final double base;
|
||||
private final AtomicInteger backoff;
|
||||
|
||||
BackoffImpl(int minInterval, int maxInterval, double base) {
|
||||
this.minInterval = minInterval;
|
||||
this.maxInterval = maxInterval;
|
||||
this.base = base;
|
||||
backoff = new AtomicInteger(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPollingInterval() {
|
||||
double multiplier = Math.pow(base, backoff.get());
|
||||
// Large or infinite values will be rounded to Integer.MAX_VALUE
|
||||
int interval = (int) (minInterval * multiplier);
|
||||
return Math.min(interval, maxInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increment() {
|
||||
backoff.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
backoff.set(0);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.bramble.plugin;
|
||||
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||
|
||||
@@ -22,11 +21,6 @@ public class PluginModule {
|
||||
Poller poller;
|
||||
}
|
||||
|
||||
@Provides
|
||||
BackoffFactory provideBackoffFactory() {
|
||||
return new BackoffFactoryImpl();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PluginManager providePluginManager(LifecycleManager lifecycleManager,
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.plugin.event.ConnectionClosedEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.ConnectionOpenedEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
||||
@@ -96,16 +95,10 @@ class PollerImpl implements Poller, EventListener {
|
||||
connectToContact(c.getContactId());
|
||||
} else if (e instanceof ConnectionClosedEvent) {
|
||||
ConnectionClosedEvent c = (ConnectionClosedEvent) e;
|
||||
// Reschedule polling, the polling interval may have decreased
|
||||
reschedule(c.getTransportId());
|
||||
// If an outgoing connection failed, try to reconnect
|
||||
if (!c.isIncoming() && c.isException()) {
|
||||
connectToContact(c.getContactId(), c.getTransportId());
|
||||
}
|
||||
} else if (e instanceof ConnectionOpenedEvent) {
|
||||
ConnectionOpenedEvent c = (ConnectionOpenedEvent) e;
|
||||
// Reschedule polling, the polling interval may have decreased
|
||||
reschedule(c.getTransportId());
|
||||
} else if (e instanceof TransportActiveEvent) {
|
||||
TransportActiveEvent t = (TransportActiveEvent) e;
|
||||
// Poll the newly activated transport
|
||||
@@ -164,12 +157,6 @@ class PollerImpl implements Poller, EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void reschedule(TransportId t) {
|
||||
Plugin p = pluginManager.getPlugin(t);
|
||||
if (p != null && p.shouldPoll())
|
||||
schedule(p, p.getPollingInterval(), false);
|
||||
}
|
||||
|
||||
private void pollNow(TransportId t) {
|
||||
Plugin p = pluginManager.getPlugin(t);
|
||||
// Randomise next polling interval
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.ConnectionHandler;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.PluginException;
|
||||
@@ -73,9 +72,8 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final SecureRandom secureRandom;
|
||||
private final Backoff backoff;
|
||||
private final PluginCallback callback;
|
||||
private final int maxLatency, maxIdleTime;
|
||||
private final int maxLatency, maxIdleTime, pollingInterval;
|
||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||
|
||||
protected final PluginState state = new PluginState();
|
||||
@@ -116,16 +114,16 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
|
||||
BluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
|
||||
TimeoutMonitor timeoutMonitor, Executor ioExecutor,
|
||||
SecureRandom secureRandom, Backoff backoff,
|
||||
PluginCallback callback, int maxLatency, int maxIdleTime) {
|
||||
SecureRandom secureRandom, PluginCallback callback, int maxLatency, int maxIdleTime,
|
||||
int pollingInterval) {
|
||||
this.connectionLimiter = connectionLimiter;
|
||||
this.timeoutMonitor = timeoutMonitor;
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.secureRandom = secureRandom;
|
||||
this.backoff = backoff;
|
||||
this.callback = callback;
|
||||
this.maxLatency = maxLatency;
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
this.pollingInterval = pollingInterval;
|
||||
}
|
||||
|
||||
void onAdapterEnabled() {
|
||||
@@ -196,7 +194,6 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
tryToClose(ss);
|
||||
return;
|
||||
}
|
||||
backoff.reset();
|
||||
acceptContactConnections(ss);
|
||||
});
|
||||
}
|
||||
@@ -239,7 +236,6 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
}
|
||||
LOG.info("Connection received");
|
||||
connectionLimiter.connectionOpened(conn);
|
||||
backoff.reset();
|
||||
callback.handleConnection(conn);
|
||||
}
|
||||
}
|
||||
@@ -268,14 +264,13 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
|
||||
@Override
|
||||
public int getPollingInterval() {
|
||||
return backoff.getPollingInterval();
|
||||
return pollingInterval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
||||
properties) {
|
||||
if (getState() != ACTIVE) return;
|
||||
backoff.increment();
|
||||
for (Pair<TransportProperties, ConnectionHandler> p : properties) {
|
||||
connect(p.getFirst(), p.getSecond());
|
||||
}
|
||||
@@ -288,10 +283,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
if (isNullOrEmpty(uuid)) return;
|
||||
ioExecutor.execute(() -> {
|
||||
DuplexTransportConnection d = createConnection(p);
|
||||
if (d != null) {
|
||||
backoff.reset();
|
||||
h.handleConnection(d);
|
||||
}
|
||||
if (d != null) h.handleConnection(d);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementConnection;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
@@ -88,9 +87,9 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
LanTcpPlugin(Executor ioExecutor, Backoff backoff, PluginCallback callback,
|
||||
int maxLatency, int maxIdleTime, int connectionTimeout) {
|
||||
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime,
|
||||
LanTcpPlugin(Executor ioExecutor, PluginCallback callback, int maxLatency,
|
||||
int maxIdleTime, int pollingInterval, int connectionTimeout) {
|
||||
super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval,
|
||||
connectionTimeout);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ package org.briarproject.bramble.plugin.tcp;
|
||||
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
@@ -13,28 +11,25 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_LATENCY = 30_000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30_000; // 30 seconds
|
||||
private static final int CONNECTION_TIMEOUT = 3_000; // 3 seconds
|
||||
private static final int MIN_POLLING_INTERVAL = 60_000; // 1 minute
|
||||
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
private static final int MAX_LATENCY = (int) SECONDS.toMillis(30);
|
||||
private static final int MAX_IDLE_TIME = (int) SECONDS.toMillis(30);
|
||||
private static final int POLLING_INTERVAL = (int) MINUTES.toMillis(1);
|
||||
private static final int CONNECTION_TIMEOUT = (int) SECONDS.toMillis(3);
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final EventBus eventBus;
|
||||
private final BackoffFactory backoffFactory;
|
||||
|
||||
public LanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
|
||||
BackoffFactory backoffFactory) {
|
||||
public LanTcpPluginFactory(Executor ioExecutor, EventBus eventBus) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.eventBus = eventBus;
|
||||
this.backoffFactory = backoffFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,10 +44,9 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
@Override
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
LanTcpPlugin plugin = new LanTcpPlugin(ioExecutor, backoff, callback, MAX_LATENCY,
|
||||
MAX_IDLE_TIME, CONNECTION_TIMEOUT);
|
||||
LanTcpPlugin plugin = new LanTcpPlugin(ioExecutor, callback,
|
||||
MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL,
|
||||
CONNECTION_TIMEOUT);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.ConnectionHandler;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
@@ -67,9 +66,8 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
Pattern.compile("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$");
|
||||
|
||||
protected final Executor ioExecutor, bindExecutor;
|
||||
protected final Backoff backoff;
|
||||
protected final PluginCallback callback;
|
||||
protected final int maxLatency, maxIdleTime;
|
||||
protected final int maxLatency, maxIdleTime, pollingInterval;
|
||||
protected final int connectionTimeout, socketTimeout;
|
||||
protected final AtomicBoolean used = new AtomicBoolean(false);
|
||||
protected final PluginState state = new PluginState();
|
||||
@@ -107,13 +105,13 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
*/
|
||||
protected abstract boolean isEnabledByDefault();
|
||||
|
||||
TcpPlugin(Executor ioExecutor, Backoff backoff, PluginCallback callback,
|
||||
int maxLatency, int maxIdleTime, int connectionTimeout) {
|
||||
TcpPlugin(Executor ioExecutor, PluginCallback callback, int maxLatency,
|
||||
int maxIdleTime, int pollingInterval, int connectionTimeout) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.backoff = backoff;
|
||||
this.callback = callback;
|
||||
this.maxLatency = maxLatency;
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
this.pollingInterval = pollingInterval;
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
if (maxIdleTime > Integer.MAX_VALUE / 2)
|
||||
socketTimeout = Integer.MAX_VALUE;
|
||||
@@ -171,7 +169,6 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
return;
|
||||
}
|
||||
backoff.reset();
|
||||
InetSocketAddress local =
|
||||
(InetSocketAddress) ss.getLocalSocketAddress();
|
||||
setLocalSocketAddress(local, ipv4);
|
||||
@@ -204,7 +201,6 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
LOG.info("Connection from " +
|
||||
scrubSocketAddress(s.getRemoteSocketAddress()));
|
||||
}
|
||||
backoff.reset();
|
||||
callback.handleConnection(new TcpTransportConnection(this, s));
|
||||
}
|
||||
}
|
||||
@@ -231,14 +227,13 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
|
||||
@Override
|
||||
public int getPollingInterval() {
|
||||
return backoff.getPollingInterval();
|
||||
return pollingInterval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
||||
properties) {
|
||||
if (getState() != ACTIVE) return;
|
||||
backoff.increment();
|
||||
for (Pair<TransportProperties, ConnectionHandler> p : properties) {
|
||||
connect(p.getFirst(), p.getSecond());
|
||||
}
|
||||
@@ -247,10 +242,7 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
private void connect(TransportProperties p, ConnectionHandler h) {
|
||||
ioExecutor.execute(() -> {
|
||||
DuplexTransportConnection d = createConnection(p);
|
||||
if (d != null) {
|
||||
backoff.reset();
|
||||
h.handleConnection(d);
|
||||
}
|
||||
if (d != null) h.handleConnection(d);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.bramble.plugin.tcp;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
@@ -30,10 +29,10 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
|
||||
private volatile MappingResult mappingResult;
|
||||
|
||||
WanTcpPlugin(Executor ioExecutor, Backoff backoff, PortMapper portMapper,
|
||||
WanTcpPlugin(Executor ioExecutor, PortMapper portMapper,
|
||||
PluginCallback callback, int maxLatency, int maxIdleTime,
|
||||
int connectionTimeout) {
|
||||
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime,
|
||||
int pollingInterval, int connectionTimeout) {
|
||||
super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval,
|
||||
connectionTimeout);
|
||||
this.portMapper = portMapper;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.briarproject.bramble.plugin.tcp;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
@@ -14,29 +12,27 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.briarproject.bramble.api.plugin.WanTcpConstants.ID;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_LATENCY = 30_000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30_000; // 30 seconds
|
||||
private static final int CONNECTION_TIMEOUT = 30_000; // 30 seconds
|
||||
private static final int MIN_POLLING_INTERVAL = 60_000; // 1 minute
|
||||
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
private static final int MAX_LATENCY = (int) SECONDS.toMillis(30);
|
||||
private static final int MAX_IDLE_TIME = (int) SECONDS.toMillis(30);
|
||||
private static final int POLLING_INTERVAL = (int) MINUTES.toMillis(1);
|
||||
private static final int CONNECTION_TIMEOUT = (int) SECONDS.toMillis(30);
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final EventBus eventBus;
|
||||
private final BackoffFactory backoffFactory;
|
||||
private final ShutdownManager shutdownManager;
|
||||
|
||||
public WanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
|
||||
BackoffFactory backoffFactory, ShutdownManager shutdownManager) {
|
||||
ShutdownManager shutdownManager) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.eventBus = eventBus;
|
||||
this.backoffFactory = backoffFactory;
|
||||
this.shutdownManager = shutdownManager;
|
||||
}
|
||||
|
||||
@@ -52,11 +48,9 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
@Override
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
WanTcpPlugin plugin = new WanTcpPlugin(ioExecutor, backoff,
|
||||
WanTcpPlugin plugin = new WanTcpPlugin(ioExecutor,
|
||||
new PortMapperImpl(shutdownManager), callback, MAX_LATENCY,
|
||||
MAX_IDLE_TIME, CONNECTION_TIMEOUT);
|
||||
MAX_IDLE_TIME, POLLING_INTERVAL, CONNECTION_TIMEOUT);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.briarproject.bramble.api.network.event.NetworkStatusEvent;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.ConnectionHandler;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.PluginException;
|
||||
@@ -46,9 +45,11 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Logger;
|
||||
@@ -109,28 +110,59 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
private static final Logger LOG = getLogger(TorPlugin.class.getName());
|
||||
|
||||
/**
|
||||
* Controller events we want to receive.
|
||||
*/
|
||||
private static final String[] EVENTS = {
|
||||
"CIRC", "ORCONN", "HS_DESC", "NOTICE", "WARN", "ERR"
|
||||
};
|
||||
|
||||
/**
|
||||
* Command-line argument to set our process as Tor's owning controller
|
||||
* so Tor exits when our process dies.
|
||||
*/
|
||||
private static final String OWNER = "__OwningControllerProcess";
|
||||
|
||||
/**
|
||||
* How long to wait for the authentication cookie file to be created.
|
||||
*/
|
||||
private static final int COOKIE_TIMEOUT_MS = 3000;
|
||||
|
||||
/**
|
||||
* How often to check whether the authentication cookie file has been
|
||||
* created.
|
||||
*/
|
||||
private static final int COOKIE_POLLING_INTERVAL_MS = 200;
|
||||
|
||||
/**
|
||||
* Regex for matching v2 hidden service names.
|
||||
*/
|
||||
private static final Pattern ONION_V2 = Pattern.compile("[a-z2-7]{16}");
|
||||
|
||||
/**
|
||||
* Regex for matching v3 hidden service names.
|
||||
*/
|
||||
private static final Pattern ONION_V3 = Pattern.compile("[a-z2-7]{56}");
|
||||
|
||||
/**
|
||||
* How many copies of our descriptor must be uploaded before we consider
|
||||
* our hidden service to be reachable and switch to less frequent polling.
|
||||
*/
|
||||
private static final int MIN_DESCRIPTORS_UPLOADED = 5;
|
||||
|
||||
private final Executor ioExecutor, connectionStatusExecutor;
|
||||
private final NetworkManager networkManager;
|
||||
private final LocationUtils locationUtils;
|
||||
private final SocketFactory torSocketFactory;
|
||||
private final Clock clock;
|
||||
private final BatteryManager batteryManager;
|
||||
private final Backoff backoff;
|
||||
private final TorRendezvousCrypto torRendezvousCrypto;
|
||||
private final PluginCallback callback;
|
||||
private final String architecture;
|
||||
private final CircumventionProvider circumventionProvider;
|
||||
private final ResourceProvider resourceProvider;
|
||||
private final int maxLatency, maxIdleTime, socketTimeout;
|
||||
private final int initialPollingInterval, stablePollingInterval;
|
||||
private final File torDirectory, torFile, geoIpFile, obfs4File, configFile;
|
||||
private final File doneFile, cookieFile;
|
||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||
@@ -149,10 +181,11 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
LocationUtils locationUtils, SocketFactory torSocketFactory,
|
||||
Clock clock, ResourceProvider resourceProvider,
|
||||
CircumventionProvider circumventionProvider,
|
||||
BatteryManager batteryManager, Backoff backoff,
|
||||
BatteryManager batteryManager,
|
||||
TorRendezvousCrypto torRendezvousCrypto,
|
||||
PluginCallback callback, String architecture, int maxLatency,
|
||||
int maxIdleTime, File torDirectory) {
|
||||
int maxIdleTime, int initialPollingInterval,
|
||||
int stablePollingInterval, File torDirectory) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.networkManager = networkManager;
|
||||
this.locationUtils = locationUtils;
|
||||
@@ -161,7 +194,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
this.resourceProvider = resourceProvider;
|
||||
this.circumventionProvider = circumventionProvider;
|
||||
this.batteryManager = batteryManager;
|
||||
this.backoff = backoff;
|
||||
this.torRendezvousCrypto = torRendezvousCrypto;
|
||||
this.callback = callback;
|
||||
this.architecture = architecture;
|
||||
@@ -170,6 +202,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
if (maxIdleTime > Integer.MAX_VALUE / 2)
|
||||
socketTimeout = Integer.MAX_VALUE;
|
||||
else socketTimeout = maxIdleTime * 2;
|
||||
this.initialPollingInterval = initialPollingInterval;
|
||||
this.stablePollingInterval = stablePollingInterval;
|
||||
this.torDirectory = torDirectory;
|
||||
torFile = new File(torDirectory, "tor");
|
||||
geoIpFile = new File(torDirectory, "geoip");
|
||||
@@ -434,7 +468,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
callback.mergeSettings(s);
|
||||
// Create a hidden service if necessary
|
||||
ioExecutor.execute(() -> publishHiddenService(localPort));
|
||||
backoff.reset();
|
||||
// Accept incoming hidden service connections from Tor
|
||||
acceptContactConnections(ss);
|
||||
});
|
||||
@@ -544,7 +577,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
return;
|
||||
}
|
||||
LOG.info("Connection received");
|
||||
backoff.reset();
|
||||
callback.handleConnection(new TorTransportConnection(this, s));
|
||||
}
|
||||
}
|
||||
@@ -606,14 +638,19 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
@Override
|
||||
public int getPollingInterval() {
|
||||
return backoff.getPollingInterval();
|
||||
if (state.isDescriptorPublished()) {
|
||||
LOG.info("Using stable polling interval");
|
||||
return stablePollingInterval;
|
||||
} else {
|
||||
LOG.info("Using initial polling interval");
|
||||
return initialPollingInterval;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
||||
properties) {
|
||||
if (getState() != ACTIVE) return;
|
||||
backoff.increment();
|
||||
for (Pair<TransportProperties, ConnectionHandler> p : properties) {
|
||||
connect(p.getFirst(), p.getSecond());
|
||||
}
|
||||
@@ -622,10 +659,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
private void connect(TransportProperties p, ConnectionHandler h) {
|
||||
ioExecutor.execute(() -> {
|
||||
DuplexTransportConnection d = createConnection(p);
|
||||
if (d != null) {
|
||||
backoff.reset();
|
||||
h.handleConnection(d);
|
||||
}
|
||||
if (d != null) h.handleConnection(d);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -755,10 +789,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
@Override
|
||||
public void circuitStatus(String status, String id, String path) {
|
||||
if (status.equals("BUILT") &&
|
||||
state.getAndSetCircuitBuilt()) {
|
||||
if (status.equals("BUILT") && state.getAndSetCircuitBuilt()) {
|
||||
LOG.info("First circuit built");
|
||||
backoff.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -768,8 +800,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
@Override
|
||||
public void orConnStatus(String status, String orName) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("OR connection " + status + " " + orName);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
|
||||
state.setOrConnectionStatus(orName, status);
|
||||
if (status.equals("CLOSED") || status.equals("FAILED")) {
|
||||
// Check whether we've lost connectivity
|
||||
updateConnectionStatus(networkManager.getNetworkStatus(),
|
||||
@@ -790,20 +822,18 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
if (LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
|
||||
if (severity.equals("NOTICE") && msg.startsWith("Bootstrapped 100%")) {
|
||||
state.setBootstrapped();
|
||||
backoff.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unrecognized(String type, String msg) {
|
||||
if (type.equals("HS_DESC") && msg.startsWith("UPLOADED")) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String[] words = msg.split(" ");
|
||||
if (words.length > 1 && ONION_V3.matcher(words[1]).matches()) {
|
||||
LOG.info("V3 descriptor uploaded");
|
||||
} else {
|
||||
LOG.info("V2 descriptor uploaded");
|
||||
}
|
||||
String[] words = msg.split(" ");
|
||||
if (words.length > 1 && ONION_V3.matcher(words[1]).matches()) {
|
||||
LOG.info("V3 descriptor uploaded");
|
||||
state.descriptorUploaded();
|
||||
} else {
|
||||
LOG.info("V2 descriptor uploaded");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -959,6 +989,12 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
@Nullable
|
||||
private ServerSocket serverSocket = null;
|
||||
|
||||
@GuardedBy("this")
|
||||
private final Set<String> orConnections = new HashSet<>();
|
||||
|
||||
@GuardedBy("this")
|
||||
private int descriptorsUploaded = 0;
|
||||
|
||||
synchronized void setStarted() {
|
||||
started = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
@@ -992,7 +1028,10 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
synchronized void enableNetwork(boolean enable) {
|
||||
networkInitialised = true;
|
||||
networkEnabled = enable;
|
||||
if (!enable) circuitBuilt = false;
|
||||
if (!enable) {
|
||||
circuitBuilt = false;
|
||||
descriptorsUploaded = 0;
|
||||
}
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
@@ -1002,6 +1041,34 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized void setOrConnectionStatus(String orName, String status) {
|
||||
if (status.equals("CONNECTED")) {
|
||||
if (!orConnections.add(orName)) {
|
||||
LOG.warning("Duplicate OR connection");
|
||||
}
|
||||
} else {
|
||||
orConnections.remove(orName);
|
||||
if (orConnections.isEmpty()) descriptorsUploaded = 0;
|
||||
}
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info(orConnections.size() + " OR connections");
|
||||
}
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
// Doesn't affect getState()
|
||||
synchronized void descriptorUploaded() {
|
||||
if (networkEnabled && !orConnections.isEmpty()) {
|
||||
descriptorsUploaded++;
|
||||
} else {
|
||||
LOG.warning("Descriptor was uploaded with no OR connection");
|
||||
}
|
||||
}
|
||||
|
||||
synchronized boolean isDescriptorPublished() {
|
||||
return descriptorsUploaded >= MIN_DESCRIPTORS_UPLOADED;
|
||||
}
|
||||
|
||||
// Doesn't affect getState()
|
||||
synchronized boolean setServerSocket(ServerSocket ss) {
|
||||
if (stopped || serverSocket != null) return false;
|
||||
@@ -1021,7 +1088,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
if (reasonsDisabled != 0) return DISABLED;
|
||||
if (!networkInitialised) return ENABLING;
|
||||
if (!networkEnabled) return INACTIVE;
|
||||
return bootstrapped && circuitBuilt ? ACTIVE : ENABLING;
|
||||
return bootstrapped && circuitBuilt && !orConnections.isEmpty()
|
||||
? ACTIVE : ENABLING;
|
||||
}
|
||||
|
||||
synchronized int getReasonsDisabled() {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package org.briarproject.bramble.plugin;
|
||||
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BackoffImplTest extends BrambleTestCase {
|
||||
|
||||
private static final int MIN_INTERVAL = 60 * 1000;
|
||||
private static final int MAX_INTERVAL = 60 * 60 * 1000;
|
||||
private static final double BASE = 1.2;
|
||||
|
||||
@Test
|
||||
public void testPollingIntervalStartsAtMinimum() {
|
||||
BackoffImpl b = new BackoffImpl(MIN_INTERVAL, MAX_INTERVAL, BASE);
|
||||
assertEquals(MIN_INTERVAL, b.getPollingInterval());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementIncreasesPollingInterval() {
|
||||
BackoffImpl b = new BackoffImpl(MIN_INTERVAL, MAX_INTERVAL, BASE);
|
||||
b.increment();
|
||||
assertTrue(b.getPollingInterval() > MIN_INTERVAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetResetsPollingInterval() {
|
||||
BackoffImpl b = new BackoffImpl(MIN_INTERVAL, MAX_INTERVAL, BASE);
|
||||
b.increment();
|
||||
b.increment();
|
||||
b.reset();
|
||||
assertEquals(MIN_INTERVAL, b.getPollingInterval());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseAffectsBackoffSpeed() {
|
||||
BackoffImpl b = new BackoffImpl(MIN_INTERVAL, MAX_INTERVAL, BASE);
|
||||
b.increment();
|
||||
int interval = b.getPollingInterval();
|
||||
BackoffImpl b1 = new BackoffImpl(MIN_INTERVAL, MAX_INTERVAL, BASE * 2);
|
||||
b1.increment();
|
||||
int interval1 = b1.getPollingInterval();
|
||||
assertTrue(interval < interval1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntervalDoesNotExceedMaxInterval() {
|
||||
BackoffImpl b = new BackoffImpl(MIN_INTERVAL, MAX_INTERVAL, BASE);
|
||||
for (int i = 0; i < 100; i++) b.increment();
|
||||
assertEquals(MAX_INTERVAL, b.getPollingInterval());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntervalDoesNotExceedMaxIntervalWithInfiniteMultiplier() {
|
||||
BackoffImpl b = new BackoffImpl(MIN_INTERVAL, MAX_INTERVAL,
|
||||
Double.POSITIVE_INFINITY);
|
||||
b.increment();
|
||||
assertEquals(MAX_INTERVAL, b.getPollingInterval());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.plugin.event.ConnectionClosedEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.ConnectionOpenedEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
||||
@@ -157,22 +156,20 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRescheduleOnOutgoingConnectionClosed() {
|
||||
public void testDoesNotReconnectOnOutgoingConnectionClosed() {
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
will(returnValue(transportId));
|
||||
}});
|
||||
expectReschedule(plugin);
|
||||
|
||||
poller.eventOccurred(new ConnectionClosedEvent(contactId, transportId,
|
||||
false, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRescheduleAndReconnectOnOutgoingConnectionFailed()
|
||||
throws Exception {
|
||||
public void testReconnectsOnOutgoingConnectionFailed() throws Exception {
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
DuplexTransportConnection duplexConnection =
|
||||
context.mock(DuplexTransportConnection.class);
|
||||
@@ -181,7 +178,6 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
allowing(plugin).getId();
|
||||
will(returnValue(transportId));
|
||||
}});
|
||||
expectReschedule(plugin);
|
||||
expectReconnect(plugin, duplexConnection);
|
||||
|
||||
poller.eventOccurred(new ConnectionClosedEvent(contactId, transportId,
|
||||
@@ -189,147 +185,31 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRescheduleOnIncomingConnectionClosed() {
|
||||
public void testDoesNotReconnectOnIncomingConnectionClosed() {
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
will(returnValue(transportId));
|
||||
}});
|
||||
expectReschedule(plugin);
|
||||
|
||||
poller.eventOccurred(new ConnectionClosedEvent(contactId, transportId,
|
||||
true, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRescheduleOnIncomingConnectionFailed() {
|
||||
public void testDoesNotReconnectOnIncomingConnectionFailed() {
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
will(returnValue(transportId));
|
||||
}});
|
||||
expectReschedule(plugin);
|
||||
|
||||
poller.eventOccurred(new ConnectionClosedEvent(contactId, transportId,
|
||||
true, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRescheduleOnConnectionOpened() {
|
||||
Plugin plugin = context.mock(Plugin.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
will(returnValue(transportId));
|
||||
// Get the plugin
|
||||
oneOf(pluginManager).getPlugin(transportId);
|
||||
will(returnValue(plugin));
|
||||
// The plugin supports polling
|
||||
oneOf(plugin).shouldPoll();
|
||||
will(returnValue(true));
|
||||
// Schedule the next poll
|
||||
oneOf(plugin).getPollingInterval();
|
||||
will(returnValue(pollingInterval));
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval), with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
}});
|
||||
|
||||
poller.eventOccurred(new ConnectionOpenedEvent(contactId, transportId,
|
||||
false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRescheduleDoesNotReplaceEarlierTask() {
|
||||
Plugin plugin = context.mock(Plugin.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
will(returnValue(transportId));
|
||||
// First event
|
||||
// Get the plugin
|
||||
oneOf(pluginManager).getPlugin(transportId);
|
||||
will(returnValue(plugin));
|
||||
// The plugin supports polling
|
||||
oneOf(plugin).shouldPoll();
|
||||
will(returnValue(true));
|
||||
// Schedule the next poll
|
||||
oneOf(plugin).getPollingInterval();
|
||||
will(returnValue(pollingInterval));
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval), with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
// Second event
|
||||
// Get the plugin
|
||||
oneOf(pluginManager).getPlugin(transportId);
|
||||
will(returnValue(plugin));
|
||||
// The plugin supports polling
|
||||
oneOf(plugin).shouldPoll();
|
||||
will(returnValue(true));
|
||||
// Don't replace the previously scheduled task, due earlier
|
||||
oneOf(plugin).getPollingInterval();
|
||||
will(returnValue(pollingInterval));
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now + 1));
|
||||
}});
|
||||
|
||||
poller.eventOccurred(new ConnectionOpenedEvent(contactId, transportId,
|
||||
false));
|
||||
poller.eventOccurred(new ConnectionOpenedEvent(contactId, transportId,
|
||||
false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRescheduleReplacesLaterTask() {
|
||||
Plugin plugin = context.mock(Plugin.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
will(returnValue(transportId));
|
||||
// First event
|
||||
// Get the plugin
|
||||
oneOf(pluginManager).getPlugin(transportId);
|
||||
will(returnValue(plugin));
|
||||
// The plugin supports polling
|
||||
oneOf(plugin).shouldPoll();
|
||||
will(returnValue(true));
|
||||
// Schedule the next poll
|
||||
oneOf(plugin).getPollingInterval();
|
||||
will(returnValue(pollingInterval));
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval), with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
// Second event
|
||||
// Get the plugin
|
||||
oneOf(pluginManager).getPlugin(transportId);
|
||||
will(returnValue(plugin));
|
||||
// The plugin supports polling
|
||||
oneOf(plugin).shouldPoll();
|
||||
will(returnValue(true));
|
||||
// Replace the previously scheduled task, due later
|
||||
oneOf(plugin).getPollingInterval();
|
||||
will(returnValue(pollingInterval - 2));
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now + 1));
|
||||
oneOf(future).cancel(false);
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval - 2), with(MILLISECONDS));
|
||||
}});
|
||||
|
||||
poller.eventOccurred(new ConnectionOpenedEvent(contactId, transportId,
|
||||
false));
|
||||
poller.eventOccurred(new ConnectionOpenedEvent(contactId, transportId,
|
||||
false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPollsOnTransportActivated() throws Exception {
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
@@ -441,25 +321,6 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
poller.eventOccurred(new TransportInactiveEvent(transportId));
|
||||
}
|
||||
|
||||
private void expectReschedule(Plugin plugin) {
|
||||
context.checking(new Expectations() {{
|
||||
// Get the plugin
|
||||
oneOf(pluginManager).getPlugin(transportId);
|
||||
will(returnValue(plugin));
|
||||
// The plugin supports polling
|
||||
oneOf(plugin).shouldPoll();
|
||||
will(returnValue(true));
|
||||
// Schedule the next poll
|
||||
oneOf(plugin).getPollingInterval();
|
||||
will(returnValue(pollingInterval));
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval), with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectReconnect(DuplexPlugin plugin,
|
||||
DuplexTransportConnection duplexConnection) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.bramble.plugin.tcp;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
||||
@@ -42,7 +41,6 @@ import static org.junit.Assume.assumeTrue;
|
||||
|
||||
public class LanTcpPluginTest extends BrambleTestCase {
|
||||
|
||||
private final Backoff backoff = new TestBackoff();
|
||||
private final ExecutorService ioExecutor = newCachedThreadPool();
|
||||
|
||||
private Callback callback = null;
|
||||
@@ -51,7 +49,7 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
callback = new Callback();
|
||||
plugin = new LanTcpPlugin(ioExecutor, backoff, callback, 0, 0, 1000) {
|
||||
plugin = new LanTcpPlugin(ioExecutor, callback, 0, 0, 0, 1000) {
|
||||
@Override
|
||||
protected boolean canConnectToOwnAddress() {
|
||||
return true;
|
||||
@@ -347,20 +345,4 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
public void handleWriter(TransportConnectionWriter w) {
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestBackoff implements Backoff {
|
||||
|
||||
@Override
|
||||
public int getPollingInterval() {
|
||||
return 60 * 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.io.TimeoutMonitor;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||
import org.briarproject.bramble.api.plugin.LanTcpConstants;
|
||||
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||
@@ -37,18 +36,16 @@ public class DesktopPluginModule extends PluginModule {
|
||||
|
||||
@Provides
|
||||
PluginConfig getPluginConfig(@IoExecutor Executor ioExecutor,
|
||||
SecureRandom random, BackoffFactory backoffFactory,
|
||||
ReliabilityLayerFactory reliabilityFactory,
|
||||
SecureRandom random, ReliabilityLayerFactory reliabilityFactory,
|
||||
ShutdownManager shutdownManager, EventBus eventBus,
|
||||
TimeoutMonitor timeoutMonitor) {
|
||||
DuplexPluginFactory bluetooth = new JavaBluetoothPluginFactory(
|
||||
ioExecutor, random, eventBus, timeoutMonitor, backoffFactory);
|
||||
ioExecutor, random, eventBus, timeoutMonitor);
|
||||
DuplexPluginFactory modem = new ModemPluginFactory(ioExecutor,
|
||||
reliabilityFactory);
|
||||
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor, eventBus,
|
||||
backoffFactory);
|
||||
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor, eventBus);
|
||||
DuplexPluginFactory wan = new WanTcpPluginFactory(ioExecutor, eventBus,
|
||||
backoffFactory, shutdownManager);
|
||||
shutdownManager);
|
||||
Collection<DuplexPluginFactory> duplex =
|
||||
asList(bluetooth, modem, lan, wan);
|
||||
@NotNullByDefault
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.bramble.plugin.bluetooth;
|
||||
import org.briarproject.bramble.api.io.TimeoutMonitor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
|
||||
@@ -36,10 +35,10 @@ class JavaBluetoothPlugin extends BluetoothPlugin<StreamConnectionNotifier> {
|
||||
|
||||
JavaBluetoothPlugin(BluetoothConnectionLimiter connectionManager,
|
||||
TimeoutMonitor timeoutMonitor, Executor ioExecutor,
|
||||
SecureRandom secureRandom, Backoff backoff,
|
||||
PluginCallback callback, int maxLatency, int maxIdleTime) {
|
||||
SecureRandom secureRandom, PluginCallback callback, int maxLatency,
|
||||
int maxIdleTime, int pollingInterval) {
|
||||
super(connectionManager, timeoutMonitor, ioExecutor, secureRandom,
|
||||
backoff, callback, maxLatency, maxIdleTime);
|
||||
callback, maxLatency, maxIdleTime, pollingInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.briarproject.bramble.plugin.bluetooth;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.io.TimeoutMonitor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
@@ -15,32 +13,30 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class JavaBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||
private static final int MIN_POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
private static final int MAX_LATENCY = (int) SECONDS.toMillis(30);
|
||||
private static final int MAX_IDLE_TIME = (int) SECONDS.toMillis(30);
|
||||
private static final int POLLING_INTERVAL = (int) MINUTES.toMillis(2);
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final SecureRandom secureRandom;
|
||||
private final EventBus eventBus;
|
||||
private final TimeoutMonitor timeoutMonitor;
|
||||
private final BackoffFactory backoffFactory;
|
||||
|
||||
public JavaBluetoothPluginFactory(Executor ioExecutor,
|
||||
SecureRandom secureRandom, EventBus eventBus,
|
||||
TimeoutMonitor timeoutMonitor, BackoffFactory backoffFactory) {
|
||||
TimeoutMonitor timeoutMonitor) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.secureRandom = secureRandom;
|
||||
this.eventBus = eventBus;
|
||||
this.timeoutMonitor = timeoutMonitor;
|
||||
this.backoffFactory = backoffFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,11 +53,9 @@ public class JavaBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
BluetoothConnectionLimiter connectionLimiter =
|
||||
new BluetoothConnectionLimiterImpl(eventBus);
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
JavaBluetoothPlugin plugin = new JavaBluetoothPlugin(connectionLimiter,
|
||||
timeoutMonitor, ioExecutor, secureRandom, backoff, callback,
|
||||
MAX_LATENCY, MAX_IDLE_TIME);
|
||||
timeoutMonitor, ioExecutor, secureRandom, callback, MAX_LATENCY,
|
||||
MAX_IDLE_TIME, POLLING_INTERVAL);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.bramble.plugin.tor;
|
||||
import org.briarproject.bramble.api.battery.BatteryManager;
|
||||
import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.system.LocationUtils;
|
||||
@@ -24,14 +23,16 @@ abstract class JavaTorPlugin extends TorPlugin {
|
||||
LocationUtils locationUtils, SocketFactory torSocketFactory,
|
||||
Clock clock, ResourceProvider resourceProvider,
|
||||
CircumventionProvider circumventionProvider,
|
||||
BatteryManager batteryManager, Backoff backoff,
|
||||
BatteryManager batteryManager,
|
||||
TorRendezvousCrypto torRendezvousCrypto,
|
||||
PluginCallback callback, String architecture, int maxLatency,
|
||||
int maxIdleTime, File torDirectory) {
|
||||
int maxIdleTime, int initialPollingInterval,
|
||||
int stablePollingInterval, File torDirectory) {
|
||||
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
|
||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
||||
backoff, torRendezvousCrypto, callback, architecture,
|
||||
maxLatency, maxIdleTime, torDirectory);
|
||||
torRendezvousCrypto, callback, architecture, maxLatency,
|
||||
maxIdleTime, initialPollingInterval, stablePollingInterval,
|
||||
torDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.sun.jna.Native;
|
||||
import org.briarproject.bramble.api.battery.BatteryManager;
|
||||
import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.system.LocationUtils;
|
||||
@@ -24,14 +23,16 @@ class UnixTorPlugin extends JavaTorPlugin {
|
||||
LocationUtils locationUtils, SocketFactory torSocketFactory,
|
||||
Clock clock, ResourceProvider resourceProvider,
|
||||
CircumventionProvider circumventionProvider,
|
||||
BatteryManager batteryManager, Backoff backoff,
|
||||
BatteryManager batteryManager,
|
||||
TorRendezvousCrypto torRendezvousCrypto,
|
||||
PluginCallback callback, String architecture, int maxLatency,
|
||||
int maxIdleTime, File torDirectory) {
|
||||
int maxIdleTime, int initialPollingInterval,
|
||||
int stablePollingInterval, File torDirectory) {
|
||||
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
|
||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
||||
backoff, torRendezvousCrypto, callback, architecture,
|
||||
maxLatency, maxIdleTime, torDirectory);
|
||||
torRendezvousCrypto, callback, architecture,
|
||||
maxLatency, maxIdleTime, initialPollingInterval,
|
||||
stablePollingInterval, torDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,8 +4,6 @@ import org.briarproject.bramble.api.battery.BatteryManager;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
@@ -22,6 +20,8 @@ import java.util.logging.Logger;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.OsUtils.isLinux;
|
||||
|
||||
@@ -32,18 +32,28 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
||||
private static final Logger LOG =
|
||||
getLogger(UnixTorPluginFactory.class.getName());
|
||||
|
||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||
private static final int MIN_POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
private static final int MAX_LATENCY = (int) SECONDS.toMillis(30);
|
||||
private static final int MAX_IDLE_TIME = (int) SECONDS.toMillis(30);
|
||||
|
||||
/**
|
||||
* How often to poll before our hidden service becomes reachable.
|
||||
*/
|
||||
private static final int INITIAL_POLLING_INTERVAL =
|
||||
(int) MINUTES.toMillis(1);
|
||||
|
||||
/**
|
||||
* How often to poll when our hidden service is reachable. Our contacts
|
||||
* will poll when they come online, so our polling is just a fallback in
|
||||
* case of repeated connection failures.
|
||||
*/
|
||||
private static final int STABLE_POLLING_INTERVAL =
|
||||
(int) MINUTES.toMillis(15);
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final NetworkManager networkManager;
|
||||
private final LocationUtils locationUtils;
|
||||
private final EventBus eventBus;
|
||||
private final SocketFactory torSocketFactory;
|
||||
private final BackoffFactory backoffFactory;
|
||||
private final ResourceProvider resourceProvider;
|
||||
private final CircumventionProvider circumventionProvider;
|
||||
private final BatteryManager batteryManager;
|
||||
@@ -53,7 +63,7 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
||||
public UnixTorPluginFactory(Executor ioExecutor,
|
||||
NetworkManager networkManager, LocationUtils locationUtils,
|
||||
EventBus eventBus, SocketFactory torSocketFactory,
|
||||
BackoffFactory backoffFactory, ResourceProvider resourceProvider,
|
||||
ResourceProvider resourceProvider,
|
||||
CircumventionProvider circumventionProvider,
|
||||
BatteryManager batteryManager, Clock clock, File torDirectory) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
@@ -61,7 +71,6 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
||||
this.locationUtils = locationUtils;
|
||||
this.eventBus = eventBus;
|
||||
this.torSocketFactory = torSocketFactory;
|
||||
this.backoffFactory = backoffFactory;
|
||||
this.resourceProvider = resourceProvider;
|
||||
this.circumventionProvider = circumventionProvider;
|
||||
this.batteryManager = batteryManager;
|
||||
@@ -94,14 +103,13 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
||||
UnixTorPlugin plugin = new UnixTorPlugin(ioExecutor, networkManager,
|
||||
locationUtils, torSocketFactory, clock, resourceProvider,
|
||||
circumventionProvider, batteryManager, backoff,
|
||||
torRendezvousCrypto, callback, architecture, MAX_LATENCY,
|
||||
MAX_IDLE_TIME, torDirectory);
|
||||
circumventionProvider, batteryManager, torRendezvousCrypto,
|
||||
callback, architecture, MAX_LATENCY, MAX_IDLE_TIME,
|
||||
INITIAL_POLLING_INTERVAL, STABLE_POLLING_INTERVAL,
|
||||
torDirectory);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.battery.BatteryManager;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.system.LocationUtils;
|
||||
@@ -69,8 +68,6 @@ public class BridgeTest extends BrambleTestCase {
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
@Inject
|
||||
BackoffFactory backoffFactory;
|
||||
@Inject
|
||||
Clock clock;
|
||||
|
||||
private final File torDir = getTestDirectory();
|
||||
@@ -120,9 +117,8 @@ public class BridgeTest extends BrambleTestCase {
|
||||
}
|
||||
};
|
||||
factory = new UnixTorPluginFactory(ioExecutor, networkManager,
|
||||
locationUtils, eventBus, torSocketFactory, backoffFactory,
|
||||
resourceProvider, bridgeProvider, batteryManager, clock,
|
||||
torDir);
|
||||
locationUtils, eventBus, torSocketFactory, resourceProvider,
|
||||
bridgeProvider, batteryManager, clock, torDir);
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||
import org.briarproject.bramble.api.plugin.LanTcpConstants;
|
||||
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||
@@ -127,23 +126,22 @@ public class AppModule {
|
||||
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
||||
@Scheduler ScheduledExecutorService scheduler,
|
||||
AndroidExecutor androidExecutor, SecureRandom random,
|
||||
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
||||
Application app, NetworkManager networkManager,
|
||||
LocationUtils locationUtils, EventBus eventBus,
|
||||
ResourceProvider resourceProvider,
|
||||
SocketFactory torSocketFactory, Application app,
|
||||
NetworkManager networkManager, LocationUtils locationUtils,
|
||||
EventBus eventBus, ResourceProvider resourceProvider,
|
||||
CircumventionProvider circumventionProvider,
|
||||
BatteryManager batteryManager, Clock clock,
|
||||
TimeoutMonitor timeoutMonitor) {
|
||||
Context appContext = app.getApplicationContext();
|
||||
DuplexPluginFactory bluetooth = new AndroidBluetoothPluginFactory(
|
||||
ioExecutor, scheduler, androidExecutor, appContext, random,
|
||||
eventBus, clock, timeoutMonitor, backoffFactory);
|
||||
eventBus, clock, timeoutMonitor);
|
||||
DuplexPluginFactory tor = new AndroidTorPluginFactory(ioExecutor,
|
||||
scheduler, appContext, networkManager, locationUtils, eventBus,
|
||||
torSocketFactory, backoffFactory, resourceProvider,
|
||||
circumventionProvider, batteryManager, clock);
|
||||
torSocketFactory, resourceProvider, circumventionProvider,
|
||||
batteryManager, clock);
|
||||
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
||||
eventBus, backoffFactory, appContext);
|
||||
eventBus, appContext);
|
||||
Collection<DuplexPluginFactory> duplex = asList(bluetooth, tor, lan);
|
||||
@NotNullByDefault
|
||||
PluginConfig pluginConfig = new PluginConfig() {
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.briarproject.bramble.api.db.DatabaseConfig
|
||||
import org.briarproject.bramble.api.event.EventBus
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor
|
||||
import org.briarproject.bramble.api.network.NetworkManager
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory
|
||||
import org.briarproject.bramble.api.plugin.PluginConfig
|
||||
import org.briarproject.bramble.api.plugin.TransportId
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory
|
||||
@@ -70,16 +69,15 @@ internal class HeadlessModule(private val appDir: File) {
|
||||
@Provides
|
||||
internal fun providePluginConfig(
|
||||
@IoExecutor ioExecutor: Executor, torSocketFactory: SocketFactory,
|
||||
backoffFactory: BackoffFactory, networkManager: NetworkManager,
|
||||
locationUtils: LocationUtils, eventBus: EventBus, resourceProvider: ResourceProvider,
|
||||
circumventionProvider: CircumventionProvider, batteryManager: BatteryManager, clock: Clock
|
||||
networkManager: NetworkManager, locationUtils: LocationUtils, eventBus: EventBus,
|
||||
resourceProvider: ResourceProvider, circumventionProvider: CircumventionProvider,
|
||||
batteryManager: BatteryManager, clock: Clock
|
||||
): PluginConfig {
|
||||
val duplex: List<DuplexPluginFactory> = if (isLinux() || isMac()) {
|
||||
val torDirectory = File(appDir, "tor")
|
||||
val tor = UnixTorPluginFactory(
|
||||
ioExecutor, networkManager, locationUtils, eventBus, torSocketFactory,
|
||||
backoffFactory, resourceProvider, circumventionProvider, batteryManager, clock,
|
||||
torDirectory
|
||||
resourceProvider, circumventionProvider, batteryManager, clock, torDirectory
|
||||
)
|
||||
listOf(tor)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user