mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 14:49:53 +01:00
Added getMaxLatency() method to transport plugins.
This commit is contained in:
@@ -14,6 +14,9 @@ public interface Plugin {
|
|||||||
/** Returns a label for looking up the plugin's translated name. */
|
/** Returns a label for looking up the plugin's translated name. */
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
|
/** Returns the transport's maximum latency in milliseconds. */
|
||||||
|
long getMaxLatency();
|
||||||
|
|
||||||
/** Starts the plugin and returns true if it started successfully. */
|
/** Starts the plugin and returns true if it started successfully. */
|
||||||
boolean start() throws IOException;
|
boolean start() throws IOException;
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
private final long pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
private final Object discoveryLock = new Object();
|
private final Object discoveryLock = new Object();
|
||||||
private final ScheduledExecutorService scheduler;
|
private final ScheduledExecutorService scheduler;
|
||||||
|
|
||||||
@@ -61,10 +61,12 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
private volatile LocalDevice localDevice = null;
|
private volatile LocalDevice localDevice = null;
|
||||||
|
|
||||||
BluetoothPlugin(@PluginExecutor Executor pluginExecutor, Clock clock,
|
BluetoothPlugin(@PluginExecutor Executor pluginExecutor, Clock clock,
|
||||||
DuplexPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long maxLatency,
|
||||||
|
long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
scheduler = Executors.newScheduledThreadPool(0);
|
scheduler = Executors.newScheduledThreadPool(0);
|
||||||
}
|
}
|
||||||
@@ -77,6 +79,10 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
return "BLUETOOTH_PLUGIN_NAME";
|
return "BLUETOOTH_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getMaxLatency() {
|
||||||
|
return maxLatency;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean start() throws IOException {
|
public boolean start() throws IOException {
|
||||||
// Initialise the Bluetooth stack
|
// Initialise the Bluetooth stack
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class BluetoothPluginFactory implements DuplexPluginFactory {
|
public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 mins
|
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
||||||
|
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 minutes
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
@@ -28,6 +29,6 @@ public class BluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
|
|
||||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new BluetoothPlugin(pluginExecutor, clock, callback,
|
return new BluetoothPlugin(pluginExecutor, clock, callback,
|
||||||
POLLING_INTERVAL);
|
MAX_LATENCY, POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
private final AndroidExecutor androidExecutor;
|
private final AndroidExecutor androidExecutor;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
private final long pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
private volatile BluetoothServerSocket socket = null;
|
private volatile BluetoothServerSocket socket = null;
|
||||||
@@ -70,11 +70,13 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
DroidtoothPlugin(@PluginExecutor Executor pluginExecutor,
|
DroidtoothPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
AndroidExecutor androidExecutor, Context appContext,
|
AndroidExecutor androidExecutor, Context appContext,
|
||||||
DuplexPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long maxLatency,
|
||||||
|
long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.androidExecutor = androidExecutor;
|
this.androidExecutor = androidExecutor;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +89,10 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
return "BLUETOOTH_PLUGIN_NAME";
|
return "BLUETOOTH_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getMaxLatency() {
|
||||||
|
return maxLatency;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean start() throws IOException {
|
public boolean start() throws IOException {
|
||||||
// BluetoothAdapter.getDefaultAdapter() must be called on a thread
|
// BluetoothAdapter.getDefaultAdapter() must be called on a thread
|
||||||
// with a message queue, so submit it to the AndroidExecutor
|
// with a message queue, so submit it to the AndroidExecutor
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import android.content.Context;
|
|||||||
|
|
||||||
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 mins
|
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
||||||
|
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 minutes
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final AndroidExecutor androidExecutor;
|
private final AndroidExecutor androidExecutor;
|
||||||
@@ -31,6 +32,6 @@ public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
|||||||
|
|
||||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new DroidtoothPlugin(pluginExecutor, androidExecutor, appContext,
|
return new DroidtoothPlugin(pluginExecutor, androidExecutor, appContext,
|
||||||
callback, POLLING_INTERVAL);
|
callback, MAX_LATENCY, POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,15 @@ implements RemovableDriveMonitor.Callback {
|
|||||||
|
|
||||||
private final RemovableDriveFinder finder;
|
private final RemovableDriveFinder finder;
|
||||||
private final RemovableDriveMonitor monitor;
|
private final RemovableDriveMonitor monitor;
|
||||||
|
private final long maxLatency;
|
||||||
|
|
||||||
RemovableDrivePlugin(@PluginExecutor Executor pluginExecutor,
|
RemovableDrivePlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
SimplexPluginCallback callback, RemovableDriveFinder finder,
|
SimplexPluginCallback callback, RemovableDriveFinder finder,
|
||||||
RemovableDriveMonitor monitor) {
|
RemovableDriveMonitor monitor, long maxLatency) {
|
||||||
super(pluginExecutor, callback);
|
super(pluginExecutor, callback);
|
||||||
this.finder = finder;
|
this.finder = finder;
|
||||||
this.monitor = monitor;
|
this.monitor = monitor;
|
||||||
|
this.maxLatency = maxLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
@@ -48,6 +50,10 @@ implements RemovableDriveMonitor.Callback {
|
|||||||
return "REMOVABLE_DRIVE_PLUGIN_NAME";
|
return "REMOVABLE_DRIVE_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getMaxLatency() {
|
||||||
|
return maxLatency;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean start() throws IOException {
|
public boolean start() throws IOException {
|
||||||
running = true;
|
running = true;
|
||||||
monitor.start(this);
|
monitor.start(this);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import net.sf.briar.util.OsUtils;
|
|||||||
|
|
||||||
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||||
|
|
||||||
|
// Maximum latency 14 days (Royal Mail or lackadaisical carrier pigeon)
|
||||||
|
private static final long MAX_LATENCY = 14L * 24L * 60L * 60L * 1000L;
|
||||||
private static final long POLLING_INTERVAL = 10L * 1000L; // 10 seconds
|
private static final long POLLING_INTERVAL = 10L * 1000L; // 10 seconds
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
@@ -46,6 +48,6 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new RemovableDrivePlugin(pluginExecutor, callback, finder,
|
return new RemovableDrivePlugin(pluginExecutor, callback, finder,
|
||||||
monitor);
|
monitor, MAX_LATENCY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
private final ModemFactory modemFactory;
|
private final ModemFactory modemFactory;
|
||||||
private final SerialPortList serialPortList;
|
private final SerialPortList serialPortList;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
private final long pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
private final boolean shuffle; // Used to disable shuffling for testing
|
private final boolean shuffle; // Used to disable shuffling for testing
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
@@ -49,12 +49,13 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
|
|
||||||
ModemPlugin(@PluginExecutor Executor pluginExecutor,
|
ModemPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
ModemFactory modemFactory, SerialPortList serialPortList,
|
ModemFactory modemFactory, SerialPortList serialPortList,
|
||||||
DuplexPluginCallback callback, long pollingInterval,
|
DuplexPluginCallback callback, long maxLatency,
|
||||||
boolean shuffle) {
|
long pollingInterval, boolean shuffle) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.modemFactory = modemFactory;
|
this.modemFactory = modemFactory;
|
||||||
this.serialPortList = serialPortList;
|
this.serialPortList = serialPortList;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
this.shuffle = shuffle;
|
this.shuffle = shuffle;
|
||||||
}
|
}
|
||||||
@@ -67,6 +68,10 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
return "MODEM_PLUGIN_NAME";
|
return "MODEM_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getMaxLatency() {
|
||||||
|
return maxLatency;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
for(String portName : serialPortList.getPortNames()) {
|
for(String portName : serialPortList.getPortNames()) {
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import net.sf.briar.util.StringUtils;
|
|||||||
|
|
||||||
public class ModemPluginFactory implements DuplexPluginFactory {
|
public class ModemPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
|
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 60L * 60L * 1000L; // 1 hour
|
private static final long POLLING_INTERVAL = 60L * 60L * 1000L; // 1 hour
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
@@ -34,6 +35,6 @@ public class ModemPluginFactory implements DuplexPluginFactory {
|
|||||||
String enabled = callback.getConfig().get("enabled");
|
String enabled = callback.getConfig().get("enabled");
|
||||||
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
||||||
return new ModemPlugin(pluginExecutor, modemFactory, serialPortList,
|
return new ModemPlugin(pluginExecutor, modemFactory, serialPortList,
|
||||||
callback, POLLING_INTERVAL, true);
|
callback, MAX_LATENCY, POLLING_INTERVAL, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
LanTcpPlugin(@PluginExecutor Executor pluginExecutor, Clock clock,
|
LanTcpPlugin(@PluginExecutor Executor pluginExecutor, Clock clock,
|
||||||
DuplexPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long maxLatency,
|
||||||
super(pluginExecutor, callback, pollingInterval);
|
long pollingInterval) {
|
||||||
|
super(pluginExecutor, callback, maxLatency, pollingInterval);
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
|
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 60L * 1000L; // 1 minute
|
private static final long POLLING_INTERVAL = 60L * 1000L; // 1 minute
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
@@ -27,7 +28,7 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new LanTcpPlugin(pluginExecutor, clock, callback,
|
return new LanTcpPlugin(pluginExecutor, clock, callback, MAX_LATENCY,
|
||||||
POLLING_INTERVAL);
|
POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
protected final Executor pluginExecutor;
|
protected final Executor pluginExecutor;
|
||||||
protected final DuplexPluginCallback callback;
|
protected final DuplexPluginCallback callback;
|
||||||
protected final long pollingInterval;
|
protected final long maxLatency, pollingInterval;
|
||||||
|
|
||||||
protected volatile boolean running = false;
|
protected volatile boolean running = false;
|
||||||
private volatile ServerSocket socket = null;
|
private volatile ServerSocket socket = null;
|
||||||
@@ -43,12 +43,18 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
protected abstract List<SocketAddress> getLocalSocketAddresses();
|
protected abstract List<SocketAddress> getLocalSocketAddresses();
|
||||||
|
|
||||||
protected TcpPlugin(@PluginExecutor Executor pluginExecutor,
|
protected TcpPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
DuplexPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long maxLatency,
|
||||||
|
long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getMaxLatency() {
|
||||||
|
return maxLatency;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
running = true;
|
running = true;
|
||||||
pluginExecutor.execute(new Runnable() {
|
pluginExecutor.execute(new Runnable() {
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
private volatile MappingResult mappingResult;
|
private volatile MappingResult mappingResult;
|
||||||
|
|
||||||
WanTcpPlugin(@PluginExecutor Executor pluginExecutor,
|
WanTcpPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
DuplexPluginCallback callback, long pollingInterval,
|
DuplexPluginCallback callback, long maxLatency,
|
||||||
PortMapper portMapper) {
|
long pollingInterval, PortMapper portMapper) {
|
||||||
super(pluginExecutor, callback, pollingInterval);
|
super(pluginExecutor, callback, maxLatency, pollingInterval);
|
||||||
this.portMapper = portMapper;
|
this.portMapper = portMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
|
private static final long MAX_LATENCY = 1L * 60L; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 5L * 60L * 1000L; // 5 minutes
|
private static final long POLLING_INTERVAL = 5L * 60L * 1000L; // 5 minutes
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
@@ -27,7 +28,7 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new WanTcpPlugin(pluginExecutor, callback, POLLING_INTERVAL,
|
return new WanTcpPlugin(pluginExecutor, callback, MAX_LATENCY,
|
||||||
new PortMapperImpl(shutdownManager));
|
POLLING_INTERVAL, new PortMapperImpl(shutdownManager));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,16 +46,18 @@ class TorPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
private final long pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
|
|
||||||
private boolean running = false, connected = false; // Locking: this
|
private boolean running = false, connected = false; // Locking: this
|
||||||
private NetLayer netLayer = null; // Locking: this
|
private NetLayer netLayer = null; // Locking: this
|
||||||
private NetServerSocket socket = null; // Locking: this
|
private NetServerSocket socket = null; // Locking: this
|
||||||
|
|
||||||
TorPlugin(@PluginExecutor Executor pluginExecutor,
|
TorPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
DuplexPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long maxLatency,
|
||||||
|
long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +69,10 @@ class TorPlugin implements DuplexPlugin {
|
|||||||
return "TOR_PLUGIN_NAME";
|
return "TOR_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getMaxLatency() {
|
||||||
|
return maxLatency;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
running = true;
|
running = true;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.sf.briar.util.StringUtils;
|
|||||||
|
|
||||||
public class TorPluginFactory implements DuplexPluginFactory {
|
public class TorPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
|
private static final long MAX_LATENCY = 5L * 60L * 1000L; // 5 minutes
|
||||||
private static final long POLLING_INTERVAL = 15L * 60L * 1000L; // 15 mins
|
private static final long POLLING_INTERVAL = 15L * 60L * 1000L; // 15 mins
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
@@ -27,6 +28,7 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
|||||||
// This plugin is not enabled by default
|
// This plugin is not enabled by default
|
||||||
String enabled = callback.getConfig().get("enabled");
|
String enabled = callback.getConfig().get("enabled");
|
||||||
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
||||||
return new TorPlugin(pluginExecutor, callback, POLLING_INTERVAL);
|
return new TorPlugin(pluginExecutor, callback, MAX_LATENCY,
|
||||||
|
POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ public class BluetoothClientTest extends DuplexClientTest {
|
|||||||
// Create the plugin
|
// Create the plugin
|
||||||
callback = new ClientCallback(new TransportConfig(),
|
callback = new ClientCallback(new TransportConfig(),
|
||||||
new TransportProperties(), remote);
|
new TransportProperties(), remote);
|
||||||
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0L);
|
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0L,
|
||||||
|
0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ public class BluetoothServerTest extends DuplexServerTest {
|
|||||||
// Create the plugin
|
// Create the plugin
|
||||||
callback = new ServerCallback(new TransportConfig(), local,
|
callback = new ServerCallback(new TransportConfig(), local,
|
||||||
Collections.singletonMap(contactId, new TransportProperties()));
|
Collections.singletonMap(contactId, new TransportProperties()));
|
||||||
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0L);
|
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0L,
|
||||||
|
0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor);
|
callback, finder, monitor, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -89,7 +89,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor);
|
callback, finder, monitor, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -126,7 +126,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor);
|
callback, finder, monitor, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -165,7 +165,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor);
|
callback, finder, monitor, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -204,7 +204,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor);
|
callback, finder, monitor, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNotNull(plugin.createWriter(contactId));
|
assertNotNull(plugin.createWriter(contactId));
|
||||||
@@ -247,7 +247,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor);
|
callback, finder, monitor, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
SimplexTransportWriter writer = plugin.createWriter(contactId);
|
SimplexTransportWriter writer = plugin.createWriter(contactId);
|
||||||
@@ -286,7 +286,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor);
|
callback, finder, monitor, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
plugin.driveInserted(testDir);
|
plugin.driveInserted(testDir);
|
||||||
@@ -306,7 +306,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor);
|
callback, finder, monitor, 0L);
|
||||||
|
|
||||||
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
|
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
|
||||||
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
|
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
|
||||||
@@ -334,7 +334,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
|
||||||
new ImmediateExecutor(), callback, finder, monitor);
|
new ImmediateExecutor(), callback, finder, monitor, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
File f = new File(testDir, "abcdefgh.dat");
|
File f = new File(testDir, "abcdefgh.dat");
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final SerialPortList serialPortList =
|
final SerialPortList serialPortList =
|
||||||
context.mock(SerialPortList.class);
|
context.mock(SerialPortList.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, null, 0L, true);
|
serialPortList, null, 0L, 0L, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(serialPortList).getPortNames();
|
oneOf(serialPortList).getPortNames();
|
||||||
@@ -71,7 +71,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L, true);
|
serialPortList, callback, 0L, 0L, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -112,7 +112,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L, true);
|
serialPortList, callback, 0L, 0L, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -153,7 +153,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L, true);
|
serialPortList, callback, 0L, 0L, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -204,7 +204,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
// Disable shuffling for this test, it confuses jMock
|
// Disable shuffling for this test, it confuses jMock
|
||||||
final ModemPlugin plugin = new ModemPlugin(pluginExecutor, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(pluginExecutor, modemFactory,
|
||||||
serialPortList, callback, 0L, false);
|
serialPortList, callback, 0L, 0L, false);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class LanTcpClientTest extends DuplexClientTest {
|
|||||||
// Create the plugin
|
// Create the plugin
|
||||||
callback = new ClientCallback(new TransportConfig(),
|
callback = new ClientCallback(new TransportConfig(),
|
||||||
new TransportProperties(), remote);
|
new TransportProperties(), remote);
|
||||||
plugin = new LanTcpPlugin(executor, new SystemClock(), callback, 0L);
|
plugin = new LanTcpPlugin(executor, new SystemClock(), callback, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
callback.local.put("port", "0");
|
callback.local.put("port", "0");
|
||||||
Executor executor = Executors.newCachedThreadPool();
|
Executor executor = Executors.newCachedThreadPool();
|
||||||
Clock clock = new SystemClock();
|
Clock clock = new SystemClock();
|
||||||
DuplexPlugin plugin = new LanTcpPlugin(executor, clock, callback, 0L);
|
DuplexPlugin plugin = new LanTcpPlugin(executor, clock, callback, 0, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
// The plugin should have bound a socket and stored the port number
|
// The plugin should have bound a socket and stored the port number
|
||||||
assertTrue(callback.propertiesLatch.await(5, SECONDS));
|
assertTrue(callback.propertiesLatch.await(5, SECONDS));
|
||||||
@@ -62,7 +62,7 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
Callback callback = new Callback();
|
Callback callback = new Callback();
|
||||||
Executor executor = Executors.newCachedThreadPool();
|
Executor executor = Executors.newCachedThreadPool();
|
||||||
Clock clock = new SystemClock();
|
Clock clock = new SystemClock();
|
||||||
DuplexPlugin plugin = new LanTcpPlugin(executor, clock, callback, 0L);
|
DuplexPlugin plugin = new LanTcpPlugin(executor, clock, callback, 0, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
// Listen on a local port
|
// Listen on a local port
|
||||||
final ServerSocket ss = new ServerSocket();
|
final ServerSocket ss = new ServerSocket();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class LanTcpServerTest extends DuplexServerTest {
|
|||||||
callback = new ServerCallback(new TransportConfig(),
|
callback = new ServerCallback(new TransportConfig(),
|
||||||
new TransportProperties(),
|
new TransportProperties(),
|
||||||
Collections.singletonMap(contactId, new TransportProperties()));
|
Collections.singletonMap(contactId, new TransportProperties()));
|
||||||
plugin = new LanTcpPlugin(executor, new SystemClock(), callback, 0L);
|
plugin = new LanTcpPlugin(executor, new SystemClock(), callback, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class TorPluginTest extends BriarTestCase {
|
|||||||
try {
|
try {
|
||||||
// Create a plugin instance for the server
|
// Create a plugin instance for the server
|
||||||
Callback serverCallback = new Callback();
|
Callback serverCallback = new Callback();
|
||||||
serverPlugin = new TorPlugin(e, serverCallback, 0L);
|
serverPlugin = new TorPlugin(e, serverCallback, 0, 0);
|
||||||
System.out.println("Starting server plugin");
|
System.out.println("Starting server plugin");
|
||||||
serverPlugin.start();
|
serverPlugin.start();
|
||||||
// The plugin should create a hidden service... eventually
|
// The plugin should create a hidden service... eventually
|
||||||
@@ -46,7 +46,7 @@ public class TorPluginTest extends BriarTestCase {
|
|||||||
TransportProperties p = new TransportProperties();
|
TransportProperties p = new TransportProperties();
|
||||||
p.put("onion", onion);
|
p.put("onion", onion);
|
||||||
clientCallback.remote.put(contactId, p);
|
clientCallback.remote.put(contactId, p);
|
||||||
clientPlugin = new TorPlugin(e, clientCallback, 0L);
|
clientPlugin = new TorPlugin(e, clientCallback, 0, 0);
|
||||||
System.out.println("Starting client plugin");
|
System.out.println("Starting client plugin");
|
||||||
clientPlugin.start();
|
clientPlugin.start();
|
||||||
// The plugin should start without creating a hidden service
|
// The plugin should start without creating a hidden service
|
||||||
@@ -87,7 +87,7 @@ public class TorPluginTest extends BriarTestCase {
|
|||||||
try {
|
try {
|
||||||
// Start a plugin instance with no private key
|
// Start a plugin instance with no private key
|
||||||
Callback callback = new Callback();
|
Callback callback = new Callback();
|
||||||
plugin = new TorPlugin(e, callback, 0L);
|
plugin = new TorPlugin(e, callback, 0, 0);
|
||||||
System.out.println("Starting plugin without private key");
|
System.out.println("Starting plugin without private key");
|
||||||
plugin.start();
|
plugin.start();
|
||||||
// The plugin should create a hidden service... eventually
|
// The plugin should create a hidden service... eventually
|
||||||
@@ -106,7 +106,7 @@ public class TorPluginTest extends BriarTestCase {
|
|||||||
// Start another instance, reusing the private key
|
// Start another instance, reusing the private key
|
||||||
callback = new Callback();
|
callback = new Callback();
|
||||||
callback.config.put("privateKey", privateKey);
|
callback.config.put("privateKey", privateKey);
|
||||||
plugin = new TorPlugin(e, callback, 0L);
|
plugin = new TorPlugin(e, callback, 0, 0);
|
||||||
System.out.println("Starting plugin with private key");
|
System.out.println("Starting plugin with private key");
|
||||||
plugin.start();
|
plugin.start();
|
||||||
// The plugin should create a hidden service... eventually
|
// The plugin should create a hidden service... eventually
|
||||||
|
|||||||
Reference in New Issue
Block a user