mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Merge branch '1142-wakeful-polling' into 'master'
Hold a wake lock while polling See merge request briar/briar!1269
This commit is contained in:
@@ -7,6 +7,7 @@ import org.briarproject.bramble.reporting.ReportingModule;
|
|||||||
import org.briarproject.bramble.socks.SocksModule;
|
import org.briarproject.bramble.socks.SocksModule;
|
||||||
import org.briarproject.bramble.system.AndroidSystemModule;
|
import org.briarproject.bramble.system.AndroidSystemModule;
|
||||||
import org.briarproject.bramble.system.AndroidTaskSchedulerModule;
|
import org.briarproject.bramble.system.AndroidTaskSchedulerModule;
|
||||||
|
import org.briarproject.bramble.system.AndroidWakefulIoExecutorModule;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ import dagger.Module;
|
|||||||
AndroidNetworkModule.class,
|
AndroidNetworkModule.class,
|
||||||
AndroidSystemModule.class,
|
AndroidSystemModule.class,
|
||||||
AndroidTaskSchedulerModule.class,
|
AndroidTaskSchedulerModule.class,
|
||||||
|
AndroidWakefulIoExecutorModule.class,
|
||||||
CircumventionModule.class,
|
CircumventionModule.class,
|
||||||
ReportingModule.class,
|
ReportingModule.class,
|
||||||
SocksModule.class
|
SocksModule.class
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class AndroidBluetoothPlugin
|
|||||||
AndroidBluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
|
AndroidBluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
|
||||||
BluetoothConnectionFactory<BluetoothSocket> connectionFactory,
|
BluetoothConnectionFactory<BluetoothSocket> connectionFactory,
|
||||||
Executor ioExecutor,
|
Executor ioExecutor,
|
||||||
|
Executor wakefulIoExecutor,
|
||||||
SecureRandom secureRandom,
|
SecureRandom secureRandom,
|
||||||
AndroidExecutor androidExecutor,
|
AndroidExecutor androidExecutor,
|
||||||
Context appContext,
|
Context appContext,
|
||||||
@@ -87,8 +88,9 @@ class AndroidBluetoothPlugin
|
|||||||
PluginCallback callback,
|
PluginCallback callback,
|
||||||
int maxLatency,
|
int maxLatency,
|
||||||
int maxIdleTime) {
|
int maxIdleTime) {
|
||||||
super(connectionLimiter, connectionFactory, ioExecutor, secureRandom,
|
super(connectionLimiter, connectionFactory, ioExecutor,
|
||||||
backoff, callback, maxLatency, maxIdleTime);
|
wakefulIoExecutor, secureRandom, backoff, callback,
|
||||||
|
maxLatency, maxIdleTime);
|
||||||
this.androidExecutor = androidExecutor;
|
this.androidExecutor = androidExecutor;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final AndroidExecutor androidExecutor;
|
private final AndroidExecutor androidExecutor;
|
||||||
private final AndroidWakeLockManager wakeLockManager;
|
private final AndroidWakeLockManager wakeLockManager;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
@@ -44,6 +44,7 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
private final BackoffFactory backoffFactory;
|
private final BackoffFactory backoffFactory;
|
||||||
|
|
||||||
public AndroidBluetoothPluginFactory(Executor ioExecutor,
|
public AndroidBluetoothPluginFactory(Executor ioExecutor,
|
||||||
|
Executor wakefulIoExecutor,
|
||||||
AndroidExecutor androidExecutor,
|
AndroidExecutor androidExecutor,
|
||||||
AndroidWakeLockManager wakeLockManager,
|
AndroidWakeLockManager wakeLockManager,
|
||||||
Context appContext,
|
Context appContext,
|
||||||
@@ -53,6 +54,7 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
TimeoutMonitor timeoutMonitor,
|
TimeoutMonitor timeoutMonitor,
|
||||||
BackoffFactory backoffFactory) {
|
BackoffFactory backoffFactory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.androidExecutor = androidExecutor;
|
this.androidExecutor = androidExecutor;
|
||||||
this.wakeLockManager = wakeLockManager;
|
this.wakeLockManager = wakeLockManager;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
@@ -83,9 +85,9 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
AndroidBluetoothPlugin plugin = new AndroidBluetoothPlugin(
|
AndroidBluetoothPlugin plugin = new AndroidBluetoothPlugin(
|
||||||
connectionLimiter, connectionFactory, ioExecutor, secureRandom,
|
connectionLimiter, connectionFactory, ioExecutor,
|
||||||
androidExecutor, appContext, clock, backoff, callback,
|
wakefulIoExecutor, secureRandom, androidExecutor, appContext,
|
||||||
MAX_LATENCY, MAX_IDLE_TIME);
|
clock, backoff, callback, MAX_LATENCY, MAX_IDLE_TIME);
|
||||||
eventBus.addListener(plugin);
|
eventBus.addListener(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,11 +61,16 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
|
|
||||||
private volatile SocketFactory socketFactory;
|
private volatile SocketFactory socketFactory;
|
||||||
|
|
||||||
AndroidLanTcpPlugin(Executor ioExecutor, Context appContext,
|
AndroidLanTcpPlugin(Executor ioExecutor,
|
||||||
Backoff backoff, PluginCallback callback, int maxLatency,
|
Executor wakefulIoExecutor,
|
||||||
int maxIdleTime, int connectionTimeout) {
|
Context appContext,
|
||||||
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime,
|
Backoff backoff,
|
||||||
connectionTimeout);
|
PluginCallback callback,
|
||||||
|
int maxLatency,
|
||||||
|
int maxIdleTime,
|
||||||
|
int connectionTimeout) {
|
||||||
|
super(ioExecutor, wakefulIoExecutor, backoff, callback, maxLatency,
|
||||||
|
maxIdleTime, connectionTimeout);
|
||||||
// Don't execute more than one connection status check at a time
|
// Don't execute more than one connection status check at a time
|
||||||
connectionStatusExecutor =
|
connectionStatusExecutor =
|
||||||
new PoliteExecutor("AndroidLanTcpPlugin", ioExecutor, 1);
|
new PoliteExecutor("AndroidLanTcpPlugin", ioExecutor, 1);
|
||||||
|
|||||||
@@ -28,14 +28,18 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final BackoffFactory backoffFactory;
|
private final BackoffFactory backoffFactory;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
|
|
||||||
public AndroidLanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
|
public AndroidLanTcpPluginFactory(Executor ioExecutor,
|
||||||
BackoffFactory backoffFactory, Context appContext) {
|
Executor wakefulIoExecutor,
|
||||||
|
EventBus eventBus,
|
||||||
|
BackoffFactory backoffFactory,
|
||||||
|
Context appContext) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.backoffFactory = backoffFactory;
|
this.backoffFactory = backoffFactory;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
@@ -56,8 +60,8 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
AndroidLanTcpPlugin plugin = new AndroidLanTcpPlugin(ioExecutor,
|
AndroidLanTcpPlugin plugin = new AndroidLanTcpPlugin(ioExecutor,
|
||||||
appContext, backoff, callback, MAX_LATENCY, MAX_IDLE_TIME,
|
wakefulIoExecutor, appContext, backoff, callback,
|
||||||
CONNECTION_TIMEOUT);
|
MAX_LATENCY, MAX_IDLE_TIME, CONNECTION_TIMEOUT);
|
||||||
eventBus.addListener(plugin);
|
eventBus.addListener(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class AndroidTorPlugin extends TorPlugin {
|
|||||||
private final AndroidWakeLock wakeLock;
|
private final AndroidWakeLock wakeLock;
|
||||||
|
|
||||||
AndroidTorPlugin(Executor ioExecutor,
|
AndroidTorPlugin(Executor ioExecutor,
|
||||||
|
Executor wakefulIoExecutor,
|
||||||
Context appContext,
|
Context appContext,
|
||||||
NetworkManager networkManager,
|
NetworkManager networkManager,
|
||||||
LocationUtils locationUtils,
|
LocationUtils locationUtils,
|
||||||
@@ -47,11 +48,11 @@ class AndroidTorPlugin extends TorPlugin {
|
|||||||
String architecture,
|
String architecture,
|
||||||
int maxLatency,
|
int maxLatency,
|
||||||
int maxIdleTime) {
|
int maxIdleTime) {
|
||||||
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
|
super(ioExecutor, wakefulIoExecutor, networkManager, locationUtils,
|
||||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
torSocketFactory, clock, resourceProvider,
|
||||||
backoff, torRendezvousCrypto, callback, architecture,
|
circumventionProvider, batteryManager, backoff,
|
||||||
maxLatency, maxIdleTime,
|
torRendezvousCrypto, callback, architecture, maxLatency,
|
||||||
appContext.getDir("tor", MODE_PRIVATE));
|
maxIdleTime, appContext.getDir("tor", MODE_PRIVATE));
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
wakeLock = wakeLockManager.createWakeLock("TorPlugin");
|
wakeLock = wakeLockManager.createWakeLock("TorPlugin");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final NetworkManager networkManager;
|
private final NetworkManager networkManager;
|
||||||
private final LocationUtils locationUtils;
|
private final LocationUtils locationUtils;
|
||||||
@@ -52,6 +52,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
|||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
public AndroidTorPluginFactory(Executor ioExecutor,
|
public AndroidTorPluginFactory(Executor ioExecutor,
|
||||||
|
Executor wakefulIoExecutor,
|
||||||
Context appContext,
|
Context appContext,
|
||||||
NetworkManager networkManager,
|
NetworkManager networkManager,
|
||||||
LocationUtils locationUtils,
|
LocationUtils locationUtils,
|
||||||
@@ -64,6 +65,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
|||||||
AndroidWakeLockManager wakeLockManager,
|
AndroidWakeLockManager wakeLockManager,
|
||||||
Clock clock) {
|
Clock clock) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
this.networkManager = networkManager;
|
this.networkManager = networkManager;
|
||||||
this.locationUtils = locationUtils;
|
this.locationUtils = locationUtils;
|
||||||
@@ -118,10 +120,11 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
|||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
||||||
AndroidTorPlugin plugin = new AndroidTorPlugin(ioExecutor,
|
AndroidTorPlugin plugin = new AndroidTorPlugin(ioExecutor,
|
||||||
appContext, networkManager, locationUtils, torSocketFactory,
|
wakefulIoExecutor, appContext, networkManager, locationUtils,
|
||||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
torSocketFactory, clock, resourceProvider,
|
||||||
wakeLockManager, backoff, torRendezvousCrypto, callback,
|
circumventionProvider, batteryManager, wakeLockManager,
|
||||||
architecture, MAX_LATENCY, MAX_IDLE_TIME);
|
backoff, torRendezvousCrypto, callback, architecture,
|
||||||
|
MAX_LATENCY, MAX_IDLE_TIME);
|
||||||
eventBus.addListener(plugin);
|
eventBus.addListener(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
||||||
|
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public
|
||||||
|
class AndroidWakefulIoExecutorModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@WakefulIoExecutor
|
||||||
|
Executor provideWakefulIoExecutor(@IoExecutor Executor ioExecutor,
|
||||||
|
AndroidWakeLockManager wakeLockManager) {
|
||||||
|
return r -> wakeLockManager.executeWakefully(r, ioExecutor,
|
||||||
|
"WakefulIoExecutor");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.briarproject.bramble.api.system;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.FIELD;
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.ElementType.PARAMETER;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation for injecting the executor for long-running IO tasks that should
|
||||||
|
* run without sleeping. Also used for annotating methods that should run on
|
||||||
|
* this executor.
|
||||||
|
* <p>
|
||||||
|
* The contract of this executor is that tasks may be run concurrently, and
|
||||||
|
* submitting a task will never block. Tasks must not run indefinitely. Tasks
|
||||||
|
* submitted during shutdown are discarded.
|
||||||
|
*/
|
||||||
|
@Qualifier
|
||||||
|
@Target({FIELD, METHOD, PARAMETER})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface WakefulIoExecutor {
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ import org.briarproject.bramble.api.properties.TransportProperties;
|
|||||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -56,7 +57,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
|
|
||||||
private static final Logger LOG = getLogger(PollerImpl.class.getName());
|
private static final Logger LOG = getLogger(PollerImpl.class.getName());
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor wakefulIoExecutor;
|
||||||
private final TaskScheduler scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
private final ConnectionRegistry connectionRegistry;
|
private final ConnectionRegistry connectionRegistry;
|
||||||
@@ -69,7 +70,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
private final Map<TransportId, ScheduledPollTask> tasks;
|
private final Map<TransportId, ScheduledPollTask> tasks;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PollerImpl(@IoExecutor Executor ioExecutor,
|
PollerImpl(@WakefulIoExecutor Executor wakefulIoExecutor,
|
||||||
TaskScheduler scheduler,
|
TaskScheduler scheduler,
|
||||||
ConnectionManager connectionManager,
|
ConnectionManager connectionManager,
|
||||||
ConnectionRegistry connectionRegistry,
|
ConnectionRegistry connectionRegistry,
|
||||||
@@ -77,7 +78,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
TransportPropertyManager transportPropertyManager,
|
TransportPropertyManager transportPropertyManager,
|
||||||
SecureRandom random,
|
SecureRandom random,
|
||||||
Clock clock) {
|
Clock clock) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
this.connectionRegistry = connectionRegistry;
|
this.connectionRegistry = connectionRegistry;
|
||||||
@@ -118,7 +119,6 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make this wakeful
|
|
||||||
private void connectToContact(ContactId c) {
|
private void connectToContact(ContactId c) {
|
||||||
for (SimplexPlugin s : pluginManager.getSimplexPlugins())
|
for (SimplexPlugin s : pluginManager.getSimplexPlugins())
|
||||||
if (s.shouldPoll()) connectToContact(c, s);
|
if (s.shouldPoll()) connectToContact(c, s);
|
||||||
@@ -135,7 +135,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void connectToContact(ContactId c, SimplexPlugin p) {
|
private void connectToContact(ContactId c, SimplexPlugin p) {
|
||||||
ioExecutor.execute(() -> {
|
wakefulIoExecutor.execute(() -> {
|
||||||
TransportId t = p.getId();
|
TransportId t = p.getId();
|
||||||
if (connectionRegistry.isConnected(c, t)) return;
|
if (connectionRegistry.isConnected(c, t)) return;
|
||||||
try {
|
try {
|
||||||
@@ -151,7 +151,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void connectToContact(ContactId c, DuplexPlugin p) {
|
private void connectToContact(ContactId c, DuplexPlugin p) {
|
||||||
ioExecutor.execute(() -> {
|
wakefulIoExecutor.execute(() -> {
|
||||||
TransportId t = p.getId();
|
TransportId t = p.getId();
|
||||||
if (connectionRegistry.isConnected(c, t)) return;
|
if (connectionRegistry.isConnected(c, t)) return;
|
||||||
try {
|
try {
|
||||||
@@ -190,8 +190,8 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
// it will abort safely when it finds it's been replaced
|
// it will abort safely when it finds it's been replaced
|
||||||
if (scheduled != null) scheduled.future.cancel(false);
|
if (scheduled != null) scheduled.future.cancel(false);
|
||||||
PollTask task = new PollTask(p, due, randomiseNext);
|
PollTask task = new PollTask(p, due, randomiseNext);
|
||||||
Future<?> future = scheduler.schedule(task, ioExecutor, delay,
|
Future<?> future = scheduler.schedule(task, wakefulIoExecutor,
|
||||||
MILLISECONDS);
|
delay, MILLISECONDS);
|
||||||
tasks.put(t, new ScheduledPollTask(task, future));
|
tasks.put(t, new ScheduledPollTask(task, future));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ abstract class BluetoothPlugin<S, SS> implements DuplexPlugin, EventListener {
|
|||||||
final BluetoothConnectionLimiter connectionLimiter;
|
final BluetoothConnectionLimiter connectionLimiter;
|
||||||
final BluetoothConnectionFactory<S> connectionFactory;
|
final BluetoothConnectionFactory<S> connectionFactory;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final SecureRandom secureRandom;
|
private final SecureRandom secureRandom;
|
||||||
private final Backoff backoff;
|
private final Backoff backoff;
|
||||||
private final PluginCallback callback;
|
private final PluginCallback callback;
|
||||||
@@ -124,6 +124,7 @@ abstract class BluetoothPlugin<S, SS> implements DuplexPlugin, EventListener {
|
|||||||
BluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
|
BluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
|
||||||
BluetoothConnectionFactory<S> connectionFactory,
|
BluetoothConnectionFactory<S> connectionFactory,
|
||||||
Executor ioExecutor,
|
Executor ioExecutor,
|
||||||
|
Executor wakefulIoExecutor,
|
||||||
SecureRandom secureRandom,
|
SecureRandom secureRandom,
|
||||||
Backoff backoff,
|
Backoff backoff,
|
||||||
PluginCallback callback,
|
PluginCallback callback,
|
||||||
@@ -132,6 +133,7 @@ abstract class BluetoothPlugin<S, SS> implements DuplexPlugin, EventListener {
|
|||||||
this.connectionLimiter = connectionLimiter;
|
this.connectionLimiter = connectionLimiter;
|
||||||
this.connectionFactory = connectionFactory;
|
this.connectionFactory = connectionFactory;
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.secureRandom = secureRandom;
|
this.secureRandom = secureRandom;
|
||||||
this.backoff = backoff;
|
this.backoff = backoff;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
@@ -355,7 +357,7 @@ abstract class BluetoothPlugin<S, SS> implements DuplexPlugin, EventListener {
|
|||||||
if (isNullOrEmpty(address)) return;
|
if (isNullOrEmpty(address)) return;
|
||||||
String uuid = p.get(PROP_UUID);
|
String uuid = p.get(PROP_UUID);
|
||||||
if (isNullOrEmpty(uuid)) return;
|
if (isNullOrEmpty(uuid)) return;
|
||||||
ioExecutor.execute(() -> {
|
wakefulIoExecutor.execute(() -> {
|
||||||
DuplexTransportConnection d = createConnection(p);
|
DuplexTransportConnection d = createConnection(p);
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
backoff.reset();
|
backoff.reset();
|
||||||
|
|||||||
@@ -88,10 +88,15 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LanTcpPlugin(Executor ioExecutor, Backoff backoff, PluginCallback callback,
|
LanTcpPlugin(Executor ioExecutor,
|
||||||
int maxLatency, int maxIdleTime, int connectionTimeout) {
|
Executor wakefulIoExecutor,
|
||||||
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime,
|
Backoff backoff,
|
||||||
connectionTimeout);
|
PluginCallback callback,
|
||||||
|
int maxLatency,
|
||||||
|
int maxIdleTime,
|
||||||
|
int connectionTimeout) {
|
||||||
|
super(ioExecutor, wakefulIoExecutor, backoff, callback, maxLatency,
|
||||||
|
maxIdleTime, connectionTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -26,13 +26,16 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final BackoffFactory backoffFactory;
|
private final BackoffFactory backoffFactory;
|
||||||
|
|
||||||
public LanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
|
public LanTcpPluginFactory(Executor ioExecutor,
|
||||||
|
Executor wakefulIoExecutor,
|
||||||
|
EventBus eventBus,
|
||||||
BackoffFactory backoffFactory) {
|
BackoffFactory backoffFactory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.backoffFactory = backoffFactory;
|
this.backoffFactory = backoffFactory;
|
||||||
}
|
}
|
||||||
@@ -51,8 +54,9 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
LanTcpPlugin plugin = new LanTcpPlugin(ioExecutor, backoff, callback, MAX_LATENCY,
|
LanTcpPlugin plugin = new LanTcpPlugin(ioExecutor, wakefulIoExecutor,
|
||||||
MAX_IDLE_TIME, CONNECTION_TIMEOUT);
|
backoff, callback, MAX_LATENCY, MAX_IDLE_TIME,
|
||||||
|
CONNECTION_TIMEOUT);
|
||||||
eventBus.addListener(plugin);
|
eventBus.addListener(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
|||||||
private static final Pattern DOTTED_QUAD =
|
private static final Pattern DOTTED_QUAD =
|
||||||
Pattern.compile("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$");
|
Pattern.compile("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$");
|
||||||
|
|
||||||
protected final Executor ioExecutor, bindExecutor;
|
protected final Executor ioExecutor, wakefulIoExecutor, bindExecutor;
|
||||||
protected final Backoff backoff;
|
protected final Backoff backoff;
|
||||||
protected final PluginCallback callback;
|
protected final PluginCallback callback;
|
||||||
protected final int maxLatency, maxIdleTime;
|
protected final int maxLatency, maxIdleTime;
|
||||||
@@ -107,9 +107,15 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
|||||||
*/
|
*/
|
||||||
protected abstract boolean isEnabledByDefault();
|
protected abstract boolean isEnabledByDefault();
|
||||||
|
|
||||||
TcpPlugin(Executor ioExecutor, Backoff backoff, PluginCallback callback,
|
TcpPlugin(Executor ioExecutor,
|
||||||
int maxLatency, int maxIdleTime, int connectionTimeout) {
|
Executor wakefulIoExecutor,
|
||||||
|
Backoff backoff,
|
||||||
|
PluginCallback callback,
|
||||||
|
int maxLatency,
|
||||||
|
int maxIdleTime,
|
||||||
|
int connectionTimeout) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.backoff = backoff;
|
this.backoff = backoff;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
@@ -245,7 +251,7 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void connect(TransportProperties p, ConnectionHandler h) {
|
private void connect(TransportProperties p, ConnectionHandler h) {
|
||||||
ioExecutor.execute(() -> {
|
wakefulIoExecutor.execute(() -> {
|
||||||
DuplexTransportConnection d = createConnection(p);
|
DuplexTransportConnection d = createConnection(p);
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
backoff.reset();
|
backoff.reset();
|
||||||
|
|||||||
@@ -30,11 +30,16 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
|
|
||||||
private volatile MappingResult mappingResult;
|
private volatile MappingResult mappingResult;
|
||||||
|
|
||||||
WanTcpPlugin(Executor ioExecutor, Backoff backoff, PortMapper portMapper,
|
WanTcpPlugin(Executor ioExecutor,
|
||||||
PluginCallback callback, int maxLatency, int maxIdleTime,
|
Executor wakefulIoExecutor,
|
||||||
|
Backoff backoff,
|
||||||
|
PortMapper portMapper,
|
||||||
|
PluginCallback callback,
|
||||||
|
int maxLatency,
|
||||||
|
int maxIdleTime,
|
||||||
int connectionTimeout) {
|
int connectionTimeout) {
|
||||||
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime,
|
super(ioExecutor, wakefulIoExecutor, backoff, callback, maxLatency,
|
||||||
connectionTimeout);
|
maxIdleTime, connectionTimeout);
|
||||||
this.portMapper = portMapper;
|
this.portMapper = portMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,14 +27,18 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
|
||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final BackoffFactory backoffFactory;
|
private final BackoffFactory backoffFactory;
|
||||||
private final ShutdownManager shutdownManager;
|
private final ShutdownManager shutdownManager;
|
||||||
|
|
||||||
public WanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
|
public WanTcpPluginFactory(Executor ioExecutor,
|
||||||
BackoffFactory backoffFactory, ShutdownManager shutdownManager) {
|
Executor wakefulIoExecutor,
|
||||||
|
EventBus eventBus,
|
||||||
|
BackoffFactory backoffFactory,
|
||||||
|
ShutdownManager shutdownManager) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.backoffFactory = backoffFactory;
|
this.backoffFactory = backoffFactory;
|
||||||
this.shutdownManager = shutdownManager;
|
this.shutdownManager = shutdownManager;
|
||||||
@@ -54,9 +58,10 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
WanTcpPlugin plugin = new WanTcpPlugin(ioExecutor, backoff,
|
PortMapper portMapper = new PortMapperImpl(shutdownManager);
|
||||||
new PortMapperImpl(shutdownManager), callback, MAX_LATENCY,
|
WanTcpPlugin plugin = new WanTcpPlugin(ioExecutor, wakefulIoExecutor,
|
||||||
MAX_IDLE_TIME, CONNECTION_TIMEOUT);
|
backoff, portMapper, callback, MAX_LATENCY, MAX_IDLE_TIME,
|
||||||
|
CONNECTION_TIMEOUT);
|
||||||
eventBus.addListener(plugin);
|
eventBus.addListener(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
private static final Pattern ONION_V2 = Pattern.compile("[a-z2-7]{16}");
|
private static final Pattern ONION_V2 = Pattern.compile("[a-z2-7]{16}");
|
||||||
private static final Pattern ONION_V3 = Pattern.compile("[a-z2-7]{56}");
|
private static final Pattern ONION_V3 = Pattern.compile("[a-z2-7]{56}");
|
||||||
|
|
||||||
private final Executor ioExecutor, connectionStatusExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
|
private final Executor connectionStatusExecutor;
|
||||||
private final NetworkManager networkManager;
|
private final NetworkManager networkManager;
|
||||||
private final LocationUtils locationUtils;
|
private final LocationUtils locationUtils;
|
||||||
private final SocketFactory torSocketFactory;
|
private final SocketFactory torSocketFactory;
|
||||||
@@ -145,15 +146,24 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
|
|
||||||
protected abstract long getLastUpdateTime();
|
protected abstract long getLastUpdateTime();
|
||||||
|
|
||||||
TorPlugin(Executor ioExecutor, NetworkManager networkManager,
|
TorPlugin(Executor ioExecutor,
|
||||||
LocationUtils locationUtils, SocketFactory torSocketFactory,
|
Executor wakefulIoExecutor,
|
||||||
Clock clock, ResourceProvider resourceProvider,
|
NetworkManager networkManager,
|
||||||
|
LocationUtils locationUtils,
|
||||||
|
SocketFactory torSocketFactory,
|
||||||
|
Clock clock,
|
||||||
|
ResourceProvider resourceProvider,
|
||||||
CircumventionProvider circumventionProvider,
|
CircumventionProvider circumventionProvider,
|
||||||
BatteryManager batteryManager, Backoff backoff,
|
BatteryManager batteryManager,
|
||||||
|
Backoff backoff,
|
||||||
TorRendezvousCrypto torRendezvousCrypto,
|
TorRendezvousCrypto torRendezvousCrypto,
|
||||||
PluginCallback callback, String architecture, int maxLatency,
|
PluginCallback callback,
|
||||||
int maxIdleTime, File torDirectory) {
|
String architecture,
|
||||||
|
int maxLatency,
|
||||||
|
int maxIdleTime,
|
||||||
|
File torDirectory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.networkManager = networkManager;
|
this.networkManager = networkManager;
|
||||||
this.locationUtils = locationUtils;
|
this.locationUtils = locationUtils;
|
||||||
this.torSocketFactory = torSocketFactory;
|
this.torSocketFactory = torSocketFactory;
|
||||||
@@ -620,7 +630,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void connect(TransportProperties p, ConnectionHandler h) {
|
private void connect(TransportProperties p, ConnectionHandler h) {
|
||||||
ioExecutor.execute(() -> {
|
wakefulIoExecutor.execute(() -> {
|
||||||
DuplexTransportConnection d = createConnection(p);
|
DuplexTransportConnection d = createConnection(p);
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
backoff.reset();
|
backoff.reset();
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
|
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a default implementation of {@link WakefulIoExecutor} for systems
|
||||||
|
* without wake locks.
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class DefaultWakefulIoExecutorModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@WakefulIoExecutor
|
||||||
|
Executor provideWakefulIoExecutor(@IoExecutor Executor ioExecutor) {
|
||||||
|
return ioExecutor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,7 +58,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
private final Future<?> future = context.mock(Future.class);
|
private final Future<?> future = context.mock(Future.class);
|
||||||
private final SecureRandom random;
|
private final SecureRandom random;
|
||||||
|
|
||||||
private final Executor ioExecutor = new ImmediateExecutor();
|
private final Executor wakefulIoExecutor = new ImmediateExecutor();
|
||||||
private final TransportId transportId = getTransportId();
|
private final TransportId transportId = getTransportId();
|
||||||
private final ContactId contactId = getContactId();
|
private final ContactId contactId = getContactId();
|
||||||
private final TransportProperties properties = new TransportProperties();
|
private final TransportProperties properties = new TransportProperties();
|
||||||
@@ -74,7 +74,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
poller = new PollerImpl(ioExecutor, scheduler, connectionManager,
|
poller = new PollerImpl(wakefulIoExecutor, scheduler, connectionManager,
|
||||||
connectionRegistry, pluginManager, transportPropertyManager,
|
connectionRegistry, pluginManager, transportPropertyManager,
|
||||||
random, clock);
|
random, clock);
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with((long) pollingInterval),
|
with(wakefulIoExecutor), with((long) pollingInterval),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
}});
|
}});
|
||||||
@@ -263,7 +263,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with((long) pollingInterval),
|
with(wakefulIoExecutor), with((long) pollingInterval),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// Second event
|
// Second event
|
||||||
@@ -306,7 +306,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with((long) pollingInterval),
|
with(wakefulIoExecutor), with((long) pollingInterval),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// Second event
|
// Second event
|
||||||
@@ -323,7 +323,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(now + 1));
|
will(returnValue(now + 1));
|
||||||
oneOf(future).cancel(false);
|
oneOf(future).cancel(false);
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with((long) pollingInterval - 2),
|
with(wakefulIoExecutor), with((long) pollingInterval - 2),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@@ -350,7 +350,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with(0L), with(MILLISECONDS));
|
with(wakefulIoExecutor), with(0L), with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
will(new RunAction());
|
will(new RunAction());
|
||||||
// Running the polling task schedules the next polling task
|
// Running the polling task schedules the next polling task
|
||||||
@@ -361,7 +361,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with((long) (pollingInterval * 0.5)),
|
with(wakefulIoExecutor), with((long) (pollingInterval * 0.5)),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// Get the transport properties and connected contacts
|
// Get the transport properties and connected contacts
|
||||||
@@ -394,7 +394,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with(0L), with(MILLISECONDS));
|
with(wakefulIoExecutor), with(0L), with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
will(new RunAction());
|
will(new RunAction());
|
||||||
// Running the polling task schedules the next polling task
|
// Running the polling task schedules the next polling task
|
||||||
@@ -405,7 +405,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with((long) (pollingInterval * 0.5)),
|
with(wakefulIoExecutor), with((long) (pollingInterval * 0.5)),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// Get the transport properties and connected contacts
|
// Get the transport properties and connected contacts
|
||||||
@@ -436,7 +436,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with(0L), with(MILLISECONDS));
|
with(wakefulIoExecutor), with(0L), with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// The plugin is deactivated before the task runs - cancel the task
|
// The plugin is deactivated before the task runs - cancel the task
|
||||||
oneOf(future).cancel(false);
|
oneOf(future).cancel(false);
|
||||||
@@ -460,7 +460,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(ioExecutor), with((long) pollingInterval),
|
with(wakefulIoExecutor), with((long) pollingInterval),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
}});
|
}});
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
callback = new Callback();
|
callback = new Callback();
|
||||||
plugin = new LanTcpPlugin(ioExecutor, backoff, callback, 0, 0, 1000) {
|
plugin = new LanTcpPlugin(ioExecutor, ioExecutor, backoff, callback,
|
||||||
|
0, 0, 1000) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean canConnectToOwnAddress() {
|
protected boolean canConnectToOwnAddress() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.FeatureFlags;
|
|||||||
import org.briarproject.bramble.battery.DefaultBatteryManagerModule;
|
import org.briarproject.bramble.battery.DefaultBatteryManagerModule;
|
||||||
import org.briarproject.bramble.event.DefaultEventExecutorModule;
|
import org.briarproject.bramble.event.DefaultEventExecutorModule;
|
||||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule;
|
import org.briarproject.bramble.system.DefaultTaskSchedulerModule;
|
||||||
|
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
@@ -12,6 +13,7 @@ import dagger.Provides;
|
|||||||
DefaultBatteryManagerModule.class,
|
DefaultBatteryManagerModule.class,
|
||||||
DefaultEventExecutorModule.class,
|
DefaultEventExecutorModule.class,
|
||||||
DefaultTaskSchedulerModule.class,
|
DefaultTaskSchedulerModule.class,
|
||||||
|
DefaultWakefulIoExecutorModule.class,
|
||||||
TestDatabaseConfigModule.class,
|
TestDatabaseConfigModule.class,
|
||||||
TestPluginConfigModule.class,
|
TestPluginConfigModule.class,
|
||||||
TestSecureRandomModule.class
|
TestSecureRandomModule.class
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
|||||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
import org.briarproject.bramble.api.reliability.ReliabilityLayerFactory;
|
import org.briarproject.bramble.api.reliability.ReliabilityLayerFactory;
|
||||||
|
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
||||||
import org.briarproject.bramble.plugin.bluetooth.JavaBluetoothPluginFactory;
|
import org.briarproject.bramble.plugin.bluetooth.JavaBluetoothPluginFactory;
|
||||||
import org.briarproject.bramble.plugin.modem.ModemPluginFactory;
|
import org.briarproject.bramble.plugin.modem.ModemPluginFactory;
|
||||||
import org.briarproject.bramble.plugin.tcp.LanTcpPluginFactory;
|
import org.briarproject.bramble.plugin.tcp.LanTcpPluginFactory;
|
||||||
@@ -37,18 +38,22 @@ public class DesktopPluginModule extends PluginModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
PluginConfig getPluginConfig(@IoExecutor Executor ioExecutor,
|
PluginConfig getPluginConfig(@IoExecutor Executor ioExecutor,
|
||||||
SecureRandom random, BackoffFactory backoffFactory,
|
@WakefulIoExecutor Executor wakefulIoExecutor,
|
||||||
|
SecureRandom random,
|
||||||
|
BackoffFactory backoffFactory,
|
||||||
ReliabilityLayerFactory reliabilityFactory,
|
ReliabilityLayerFactory reliabilityFactory,
|
||||||
ShutdownManager shutdownManager, EventBus eventBus,
|
ShutdownManager shutdownManager,
|
||||||
|
EventBus eventBus,
|
||||||
TimeoutMonitor timeoutMonitor) {
|
TimeoutMonitor timeoutMonitor) {
|
||||||
DuplexPluginFactory bluetooth = new JavaBluetoothPluginFactory(
|
DuplexPluginFactory bluetooth = new JavaBluetoothPluginFactory(
|
||||||
ioExecutor, random, eventBus, timeoutMonitor, backoffFactory);
|
ioExecutor, wakefulIoExecutor, random, eventBus,
|
||||||
|
timeoutMonitor, backoffFactory);
|
||||||
DuplexPluginFactory modem = new ModemPluginFactory(ioExecutor,
|
DuplexPluginFactory modem = new ModemPluginFactory(ioExecutor,
|
||||||
reliabilityFactory);
|
reliabilityFactory);
|
||||||
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor, eventBus,
|
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor,
|
||||||
backoffFactory);
|
wakefulIoExecutor, eventBus, backoffFactory);
|
||||||
DuplexPluginFactory wan = new WanTcpPluginFactory(ioExecutor, eventBus,
|
DuplexPluginFactory wan = new WanTcpPluginFactory(ioExecutor,
|
||||||
backoffFactory, shutdownManager);
|
wakefulIoExecutor, eventBus, backoffFactory, shutdownManager);
|
||||||
Collection<DuplexPluginFactory> duplex =
|
Collection<DuplexPluginFactory> duplex =
|
||||||
asList(bluetooth, modem, lan, wan);
|
asList(bluetooth, modem, lan, wan);
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
|
|||||||
@@ -36,10 +36,16 @@ class JavaBluetoothPlugin
|
|||||||
|
|
||||||
JavaBluetoothPlugin(BluetoothConnectionLimiter connectionManager,
|
JavaBluetoothPlugin(BluetoothConnectionLimiter connectionManager,
|
||||||
BluetoothConnectionFactory<StreamConnection> connectionFactory,
|
BluetoothConnectionFactory<StreamConnection> connectionFactory,
|
||||||
Executor ioExecutor, SecureRandom secureRandom, Backoff backoff,
|
Executor ioExecutor,
|
||||||
PluginCallback callback, int maxLatency, int maxIdleTime) {
|
Executor wakefulIoExecutor,
|
||||||
super(connectionManager, connectionFactory, ioExecutor, secureRandom,
|
SecureRandom secureRandom,
|
||||||
backoff, callback, maxLatency, maxIdleTime);
|
Backoff backoff,
|
||||||
|
PluginCallback callback,
|
||||||
|
int maxLatency,
|
||||||
|
int maxIdleTime) {
|
||||||
|
super(connectionManager, connectionFactory, ioExecutor,
|
||||||
|
wakefulIoExecutor, secureRandom, backoff, callback,
|
||||||
|
maxLatency, maxIdleTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -28,16 +28,20 @@ public class JavaBluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final SecureRandom secureRandom;
|
private final SecureRandom secureRandom;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final TimeoutMonitor timeoutMonitor;
|
private final TimeoutMonitor timeoutMonitor;
|
||||||
private final BackoffFactory backoffFactory;
|
private final BackoffFactory backoffFactory;
|
||||||
|
|
||||||
public JavaBluetoothPluginFactory(Executor ioExecutor,
|
public JavaBluetoothPluginFactory(Executor ioExecutor,
|
||||||
SecureRandom secureRandom, EventBus eventBus,
|
Executor wakefulIoExecutor,
|
||||||
TimeoutMonitor timeoutMonitor, BackoffFactory backoffFactory) {
|
SecureRandom secureRandom,
|
||||||
|
EventBus eventBus,
|
||||||
|
TimeoutMonitor timeoutMonitor,
|
||||||
|
BackoffFactory backoffFactory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.secureRandom = secureRandom;
|
this.secureRandom = secureRandom;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.timeoutMonitor = timeoutMonitor;
|
this.timeoutMonitor = timeoutMonitor;
|
||||||
@@ -64,8 +68,8 @@ public class JavaBluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
JavaBluetoothPlugin plugin = new JavaBluetoothPlugin(connectionLimiter,
|
JavaBluetoothPlugin plugin = new JavaBluetoothPlugin(connectionLimiter,
|
||||||
connectionFactory, ioExecutor, secureRandom, backoff, callback,
|
connectionFactory, ioExecutor, wakefulIoExecutor, secureRandom,
|
||||||
MAX_LATENCY, MAX_IDLE_TIME);
|
backoff, callback, MAX_LATENCY, MAX_IDLE_TIME);
|
||||||
eventBus.addListener(plugin);
|
eventBus.addListener(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,17 +20,26 @@ import javax.net.SocketFactory;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
abstract class JavaTorPlugin extends TorPlugin {
|
abstract class JavaTorPlugin extends TorPlugin {
|
||||||
|
|
||||||
JavaTorPlugin(Executor ioExecutor, NetworkManager networkManager,
|
JavaTorPlugin(Executor ioExecutor,
|
||||||
LocationUtils locationUtils, SocketFactory torSocketFactory,
|
Executor wakefulIoExecutor,
|
||||||
Clock clock, ResourceProvider resourceProvider,
|
NetworkManager networkManager,
|
||||||
|
LocationUtils locationUtils,
|
||||||
|
SocketFactory torSocketFactory,
|
||||||
|
Clock clock,
|
||||||
|
ResourceProvider resourceProvider,
|
||||||
CircumventionProvider circumventionProvider,
|
CircumventionProvider circumventionProvider,
|
||||||
BatteryManager batteryManager, Backoff backoff,
|
BatteryManager batteryManager,
|
||||||
|
Backoff backoff,
|
||||||
TorRendezvousCrypto torRendezvousCrypto,
|
TorRendezvousCrypto torRendezvousCrypto,
|
||||||
PluginCallback callback, String architecture, int maxLatency,
|
PluginCallback callback,
|
||||||
int maxIdleTime, File torDirectory) {
|
String architecture,
|
||||||
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
|
int maxLatency,
|
||||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
int maxIdleTime,
|
||||||
backoff, torRendezvousCrypto, callback, architecture,
|
File torDirectory) {
|
||||||
|
super(ioExecutor, wakefulIoExecutor, networkManager, locationUtils,
|
||||||
|
torSocketFactory, clock, resourceProvider,
|
||||||
|
circumventionProvider, batteryManager, backoff,
|
||||||
|
torRendezvousCrypto, callback, architecture,
|
||||||
maxLatency, maxIdleTime, torDirectory);
|
maxLatency, maxIdleTime, torDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,17 +20,26 @@ import javax.net.SocketFactory;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class UnixTorPlugin extends JavaTorPlugin {
|
class UnixTorPlugin extends JavaTorPlugin {
|
||||||
|
|
||||||
UnixTorPlugin(Executor ioExecutor, NetworkManager networkManager,
|
UnixTorPlugin(Executor ioExecutor,
|
||||||
LocationUtils locationUtils, SocketFactory torSocketFactory,
|
Executor wakefulIoExecutor,
|
||||||
Clock clock, ResourceProvider resourceProvider,
|
NetworkManager networkManager,
|
||||||
|
LocationUtils locationUtils,
|
||||||
|
SocketFactory torSocketFactory,
|
||||||
|
Clock clock,
|
||||||
|
ResourceProvider resourceProvider,
|
||||||
CircumventionProvider circumventionProvider,
|
CircumventionProvider circumventionProvider,
|
||||||
BatteryManager batteryManager, Backoff backoff,
|
BatteryManager batteryManager,
|
||||||
|
Backoff backoff,
|
||||||
TorRendezvousCrypto torRendezvousCrypto,
|
TorRendezvousCrypto torRendezvousCrypto,
|
||||||
PluginCallback callback, String architecture, int maxLatency,
|
PluginCallback callback,
|
||||||
int maxIdleTime, File torDirectory) {
|
String architecture,
|
||||||
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
|
int maxLatency,
|
||||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
int maxIdleTime,
|
||||||
backoff, torRendezvousCrypto, callback, architecture,
|
File torDirectory) {
|
||||||
|
super(ioExecutor, wakefulIoExecutor, networkManager, locationUtils,
|
||||||
|
torSocketFactory, clock, resourceProvider,
|
||||||
|
circumventionProvider, batteryManager, backoff,
|
||||||
|
torRendezvousCrypto, callback, architecture,
|
||||||
maxLatency, maxIdleTime, torDirectory);
|
maxLatency, maxIdleTime, torDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final NetworkManager networkManager;
|
private final NetworkManager networkManager;
|
||||||
private final LocationUtils locationUtils;
|
private final LocationUtils locationUtils;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
@@ -51,12 +51,19 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
|||||||
private final File torDirectory;
|
private final File torDirectory;
|
||||||
|
|
||||||
public UnixTorPluginFactory(Executor ioExecutor,
|
public UnixTorPluginFactory(Executor ioExecutor,
|
||||||
NetworkManager networkManager, LocationUtils locationUtils,
|
Executor wakefulIoExecutor,
|
||||||
EventBus eventBus, SocketFactory torSocketFactory,
|
NetworkManager networkManager,
|
||||||
BackoffFactory backoffFactory, ResourceProvider resourceProvider,
|
LocationUtils locationUtils,
|
||||||
|
EventBus eventBus,
|
||||||
|
SocketFactory torSocketFactory,
|
||||||
|
BackoffFactory backoffFactory,
|
||||||
|
ResourceProvider resourceProvider,
|
||||||
CircumventionProvider circumventionProvider,
|
CircumventionProvider circumventionProvider,
|
||||||
BatteryManager batteryManager, Clock clock, File torDirectory) {
|
BatteryManager batteryManager,
|
||||||
|
Clock clock,
|
||||||
|
File torDirectory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.networkManager = networkManager;
|
this.networkManager = networkManager;
|
||||||
this.locationUtils = locationUtils;
|
this.locationUtils = locationUtils;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
@@ -97,11 +104,11 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
|||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
||||||
UnixTorPlugin plugin = new UnixTorPlugin(ioExecutor, networkManager,
|
UnixTorPlugin plugin = new UnixTorPlugin(ioExecutor, wakefulIoExecutor,
|
||||||
locationUtils, torSocketFactory, clock, resourceProvider,
|
networkManager, locationUtils, torSocketFactory, clock,
|
||||||
circumventionProvider, batteryManager, backoff,
|
resourceProvider, circumventionProvider, batteryManager,
|
||||||
torRendezvousCrypto, callback, architecture, MAX_LATENCY,
|
backoff, torRendezvousCrypto, callback, architecture,
|
||||||
MAX_IDLE_TIME, torDirectory);
|
MAX_LATENCY, MAX_IDLE_TIME, torDirectory);
|
||||||
eventBus.addListener(plugin);
|
eventBus.addListener(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.api.system.ResourceProvider;
|
import org.briarproject.bramble.api.system.ResourceProvider;
|
||||||
|
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
||||||
import org.briarproject.bramble.test.BrambleJavaIntegrationTestComponent;
|
import org.briarproject.bramble.test.BrambleJavaIntegrationTestComponent;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.test.DaggerBrambleJavaIntegrationTestComponent;
|
import org.briarproject.bramble.test.DaggerBrambleJavaIntegrationTestComponent;
|
||||||
@@ -60,6 +61,9 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
@IoExecutor
|
@IoExecutor
|
||||||
Executor ioExecutor;
|
Executor ioExecutor;
|
||||||
@Inject
|
@Inject
|
||||||
|
@WakefulIoExecutor
|
||||||
|
Executor wakefulIoExecutor;
|
||||||
|
@Inject
|
||||||
NetworkManager networkManager;
|
NetworkManager networkManager;
|
||||||
@Inject
|
@Inject
|
||||||
ResourceProvider resourceProvider;
|
ResourceProvider resourceProvider;
|
||||||
@@ -121,10 +125,10 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
return singletonList(bridge);
|
return singletonList(bridge);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
factory = new UnixTorPluginFactory(ioExecutor, networkManager,
|
factory = new UnixTorPluginFactory(ioExecutor, wakefulIoExecutor,
|
||||||
locationUtils, eventBus, torSocketFactory, backoffFactory,
|
networkManager, locationUtils, eventBus, torSocketFactory,
|
||||||
resourceProvider, bridgeProvider, batteryManager, clock,
|
backoffFactory, resourceProvider, bridgeProvider,
|
||||||
torDir);
|
batteryManager, clock, torDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.api.system.ResourceProvider;
|
import org.briarproject.bramble.api.system.ResourceProvider;
|
||||||
|
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
||||||
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
||||||
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
||||||
import org.briarproject.bramble.plugin.tor.AndroidTorPluginFactory;
|
import org.briarproject.bramble.plugin.tor.AndroidTorPluginFactory;
|
||||||
@@ -124,6 +125,7 @@ public class AppModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
||||||
|
@WakefulIoExecutor Executor wakefulIoExecutor,
|
||||||
AndroidExecutor androidExecutor,
|
AndroidExecutor androidExecutor,
|
||||||
SecureRandom random,
|
SecureRandom random,
|
||||||
SocketFactory torSocketFactory,
|
SocketFactory torSocketFactory,
|
||||||
@@ -140,14 +142,15 @@ public class AppModule {
|
|||||||
TimeoutMonitor timeoutMonitor) {
|
TimeoutMonitor timeoutMonitor) {
|
||||||
Context appContext = app.getApplicationContext();
|
Context appContext = app.getApplicationContext();
|
||||||
DuplexPluginFactory bluetooth = new AndroidBluetoothPluginFactory(
|
DuplexPluginFactory bluetooth = new AndroidBluetoothPluginFactory(
|
||||||
ioExecutor, androidExecutor, wakeLockManager, appContext,
|
ioExecutor, wakefulIoExecutor, androidExecutor,
|
||||||
random, eventBus, clock, timeoutMonitor, backoffFactory);
|
wakeLockManager, appContext, random, eventBus, clock,
|
||||||
|
timeoutMonitor, backoffFactory);
|
||||||
DuplexPluginFactory tor = new AndroidTorPluginFactory(ioExecutor,
|
DuplexPluginFactory tor = new AndroidTorPluginFactory(ioExecutor,
|
||||||
appContext, networkManager, locationUtils, eventBus,
|
wakefulIoExecutor, appContext, networkManager, locationUtils,
|
||||||
torSocketFactory, backoffFactory, resourceProvider,
|
eventBus, torSocketFactory, backoffFactory, resourceProvider,
|
||||||
circumventionProvider, batteryManager, wakeLockManager, clock);
|
circumventionProvider, batteryManager, wakeLockManager, clock);
|
||||||
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
||||||
eventBus, backoffFactory, appContext);
|
wakefulIoExecutor, eventBus, backoffFactory, appContext);
|
||||||
Collection<DuplexPluginFactory> duplex = asList(bluetooth, tor, lan);
|
Collection<DuplexPluginFactory> duplex = asList(bluetooth, tor, lan);
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
PluginConfig pluginConfig = new PluginConfig() {
|
PluginConfig pluginConfig = new PluginConfig() {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory
|
|||||||
import org.briarproject.bramble.api.system.Clock
|
import org.briarproject.bramble.api.system.Clock
|
||||||
import org.briarproject.bramble.api.system.LocationUtils
|
import org.briarproject.bramble.api.system.LocationUtils
|
||||||
import org.briarproject.bramble.api.system.ResourceProvider
|
import org.briarproject.bramble.api.system.ResourceProvider
|
||||||
|
import org.briarproject.bramble.api.system.WakefulIoExecutor
|
||||||
import org.briarproject.bramble.battery.DefaultBatteryManagerModule
|
import org.briarproject.bramble.battery.DefaultBatteryManagerModule
|
||||||
import org.briarproject.bramble.event.DefaultEventExecutorModule
|
import org.briarproject.bramble.event.DefaultEventExecutorModule
|
||||||
import org.briarproject.bramble.network.JavaNetworkModule
|
import org.briarproject.bramble.network.JavaNetworkModule
|
||||||
@@ -26,6 +27,7 @@ import org.briarproject.bramble.plugin.tor.CircumventionProvider
|
|||||||
import org.briarproject.bramble.plugin.tor.UnixTorPluginFactory
|
import org.briarproject.bramble.plugin.tor.UnixTorPluginFactory
|
||||||
import org.briarproject.bramble.socks.SocksModule
|
import org.briarproject.bramble.socks.SocksModule
|
||||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule
|
import org.briarproject.bramble.system.DefaultTaskSchedulerModule
|
||||||
|
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule
|
||||||
import org.briarproject.bramble.system.DesktopSecureRandomModule
|
import org.briarproject.bramble.system.DesktopSecureRandomModule
|
||||||
import org.briarproject.bramble.system.JavaSystemModule
|
import org.briarproject.bramble.system.JavaSystemModule
|
||||||
import org.briarproject.bramble.util.OsUtils.isLinux
|
import org.briarproject.bramble.util.OsUtils.isLinux
|
||||||
@@ -48,6 +50,7 @@ import javax.net.SocketFactory
|
|||||||
DefaultBatteryManagerModule::class,
|
DefaultBatteryManagerModule::class,
|
||||||
DefaultEventExecutorModule::class,
|
DefaultEventExecutorModule::class,
|
||||||
DefaultTaskSchedulerModule::class,
|
DefaultTaskSchedulerModule::class,
|
||||||
|
DefaultWakefulIoExecutorModule::class,
|
||||||
DesktopSecureRandomModule::class,
|
DesktopSecureRandomModule::class,
|
||||||
HeadlessBlogModule::class,
|
HeadlessBlogModule::class,
|
||||||
HeadlessContactModule::class,
|
HeadlessContactModule::class,
|
||||||
@@ -75,16 +78,32 @@ internal class HeadlessModule(private val appDir: File) {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
internal fun providePluginConfig(
|
internal fun providePluginConfig(
|
||||||
@IoExecutor ioExecutor: Executor, torSocketFactory: SocketFactory,
|
@IoExecutor ioExecutor: Executor,
|
||||||
backoffFactory: BackoffFactory, networkManager: NetworkManager,
|
@WakefulIoExecutor wakefulIoExecutor: Executor,
|
||||||
locationUtils: LocationUtils, eventBus: EventBus, resourceProvider: ResourceProvider,
|
torSocketFactory: SocketFactory,
|
||||||
circumventionProvider: CircumventionProvider, batteryManager: BatteryManager, clock: Clock
|
backoffFactory: BackoffFactory,
|
||||||
|
networkManager: NetworkManager,
|
||||||
|
locationUtils: LocationUtils,
|
||||||
|
eventBus: EventBus,
|
||||||
|
resourceProvider: ResourceProvider,
|
||||||
|
circumventionProvider: CircumventionProvider,
|
||||||
|
batteryManager: BatteryManager,
|
||||||
|
clock: Clock
|
||||||
): PluginConfig {
|
): PluginConfig {
|
||||||
val duplex: List<DuplexPluginFactory> = if (isLinux() || isMac()) {
|
val duplex: List<DuplexPluginFactory> = if (isLinux() || isMac()) {
|
||||||
val torDirectory = File(appDir, "tor")
|
val torDirectory = File(appDir, "tor")
|
||||||
val tor = UnixTorPluginFactory(
|
val tor = UnixTorPluginFactory(
|
||||||
ioExecutor, networkManager, locationUtils, eventBus, torSocketFactory,
|
ioExecutor,
|
||||||
backoffFactory, resourceProvider, circumventionProvider, batteryManager, clock,
|
wakefulIoExecutor,
|
||||||
|
networkManager,
|
||||||
|
locationUtils,
|
||||||
|
eventBus,
|
||||||
|
torSocketFactory,
|
||||||
|
backoffFactory,
|
||||||
|
resourceProvider,
|
||||||
|
circumventionProvider,
|
||||||
|
batteryManager,
|
||||||
|
clock,
|
||||||
torDirectory
|
torDirectory
|
||||||
)
|
)
|
||||||
listOf(tor)
|
listOf(tor)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.briarproject.bramble.network.JavaNetworkModule
|
|||||||
import org.briarproject.bramble.plugin.tor.CircumventionModule
|
import org.briarproject.bramble.plugin.tor.CircumventionModule
|
||||||
import org.briarproject.bramble.socks.SocksModule
|
import org.briarproject.bramble.socks.SocksModule
|
||||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule
|
import org.briarproject.bramble.system.DefaultTaskSchedulerModule
|
||||||
|
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule
|
||||||
import org.briarproject.bramble.system.JavaSystemModule
|
import org.briarproject.bramble.system.JavaSystemModule
|
||||||
import org.briarproject.bramble.test.TestSecureRandomModule
|
import org.briarproject.bramble.test.TestSecureRandomModule
|
||||||
import org.briarproject.briar.headless.blogs.HeadlessBlogModule
|
import org.briarproject.briar.headless.blogs.HeadlessBlogModule
|
||||||
@@ -34,6 +35,7 @@ import javax.inject.Singleton
|
|||||||
CircumventionModule::class,
|
CircumventionModule::class,
|
||||||
DefaultEventExecutorModule::class,
|
DefaultEventExecutorModule::class,
|
||||||
DefaultTaskSchedulerModule::class,
|
DefaultTaskSchedulerModule::class,
|
||||||
|
DefaultWakefulIoExecutorModule::class,
|
||||||
SocksModule::class,
|
SocksModule::class,
|
||||||
TestSecureRandomModule::class,
|
TestSecureRandomModule::class,
|
||||||
HeadlessBlogModule::class,
|
HeadlessBlogModule::class,
|
||||||
|
|||||||
Reference in New Issue
Block a user