Added getMaxLatency() method to transport plugins.

This commit is contained in:
akwizgran
2013-02-01 20:19:23 +00:00
parent 14177e51f6
commit a73d9d05f2
24 changed files with 101 additions and 51 deletions

View File

@@ -50,7 +50,7 @@ class BluetoothPlugin implements DuplexPlugin {
private final Executor pluginExecutor;
private final Clock clock;
private final DuplexPluginCallback callback;
private final long pollingInterval;
private final long maxLatency, pollingInterval;
private final Object discoveryLock = new Object();
private final ScheduledExecutorService scheduler;
@@ -61,10 +61,12 @@ class BluetoothPlugin implements DuplexPlugin {
private volatile LocalDevice localDevice = null;
BluetoothPlugin(@PluginExecutor Executor pluginExecutor, Clock clock,
DuplexPluginCallback callback, long pollingInterval) {
DuplexPluginCallback callback, long maxLatency,
long pollingInterval) {
this.pluginExecutor = pluginExecutor;
this.clock = clock;
this.callback = callback;
this.maxLatency = maxLatency;
this.pollingInterval = pollingInterval;
scheduler = Executors.newScheduledThreadPool(0);
}
@@ -77,6 +79,10 @@ class BluetoothPlugin implements DuplexPlugin {
return "BLUETOOTH_PLUGIN_NAME";
}
public long getMaxLatency() {
return maxLatency;
}
public boolean start() throws IOException {
// Initialise the Bluetooth stack
try {

View File

@@ -12,7 +12,8 @@ import net.sf.briar.api.plugins.duplex.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 Clock clock;
@@ -28,6 +29,6 @@ public class BluetoothPluginFactory implements DuplexPluginFactory {
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
return new BluetoothPlugin(pluginExecutor, clock, callback,
POLLING_INTERVAL);
MAX_LATENCY, POLLING_INTERVAL);
}
}

View File

@@ -60,7 +60,7 @@ class DroidtoothPlugin implements DuplexPlugin {
private final AndroidExecutor androidExecutor;
private final Context appContext;
private final DuplexPluginCallback callback;
private final long pollingInterval;
private final long maxLatency, pollingInterval;
private volatile boolean running = false;
private volatile BluetoothServerSocket socket = null;
@@ -70,11 +70,13 @@ class DroidtoothPlugin implements DuplexPlugin {
DroidtoothPlugin(@PluginExecutor Executor pluginExecutor,
AndroidExecutor androidExecutor, Context appContext,
DuplexPluginCallback callback, long pollingInterval) {
DuplexPluginCallback callback, long maxLatency,
long pollingInterval) {
this.pluginExecutor = pluginExecutor;
this.androidExecutor = androidExecutor;
this.appContext = appContext;
this.callback = callback;
this.maxLatency = maxLatency;
this.pollingInterval = pollingInterval;
}
@@ -87,6 +89,10 @@ class DroidtoothPlugin implements DuplexPlugin {
return "BLUETOOTH_PLUGIN_NAME";
}
public long getMaxLatency() {
return maxLatency;
}
public boolean start() throws IOException {
// BluetoothAdapter.getDefaultAdapter() must be called on a thread
// with a message queue, so submit it to the AndroidExecutor

View File

@@ -12,7 +12,8 @@ import android.content.Context;
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 AndroidExecutor androidExecutor;
@@ -31,6 +32,6 @@ public class DroidtoothPluginFactory implements DuplexPluginFactory {
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
return new DroidtoothPlugin(pluginExecutor, androidExecutor, appContext,
callback, POLLING_INTERVAL);
callback, MAX_LATENCY, POLLING_INTERVAL);
}
}

View File

@@ -31,13 +31,15 @@ implements RemovableDriveMonitor.Callback {
private final RemovableDriveFinder finder;
private final RemovableDriveMonitor monitor;
private final long maxLatency;
RemovableDrivePlugin(@PluginExecutor Executor pluginExecutor,
SimplexPluginCallback callback, RemovableDriveFinder finder,
RemovableDriveMonitor monitor) {
RemovableDriveMonitor monitor, long maxLatency) {
super(pluginExecutor, callback);
this.finder = finder;
this.monitor = monitor;
this.maxLatency = maxLatency;
}
public TransportId getId() {
@@ -48,6 +50,10 @@ implements RemovableDriveMonitor.Callback {
return "REMOVABLE_DRIVE_PLUGIN_NAME";
}
public long getMaxLatency() {
return maxLatency;
}
public boolean start() throws IOException {
running = true;
monitor.start(this);

View File

@@ -11,6 +11,8 @@ import net.sf.briar.util.OsUtils;
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 final Executor pluginExecutor;
@@ -46,6 +48,6 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
return null;
}
return new RemovableDrivePlugin(pluginExecutor, callback, finder,
monitor);
monitor, MAX_LATENCY);
}
}

View File

@@ -41,7 +41,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
private final ModemFactory modemFactory;
private final SerialPortList serialPortList;
private final DuplexPluginCallback callback;
private final long pollingInterval;
private final long maxLatency, pollingInterval;
private final boolean shuffle; // Used to disable shuffling for testing
private volatile boolean running = false;
@@ -49,12 +49,13 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
ModemPlugin(@PluginExecutor Executor pluginExecutor,
ModemFactory modemFactory, SerialPortList serialPortList,
DuplexPluginCallback callback, long pollingInterval,
boolean shuffle) {
DuplexPluginCallback callback, long maxLatency,
long pollingInterval, boolean shuffle) {
this.pluginExecutor = pluginExecutor;
this.modemFactory = modemFactory;
this.serialPortList = serialPortList;
this.callback = callback;
this.maxLatency = maxLatency;
this.pollingInterval = pollingInterval;
this.shuffle = shuffle;
}
@@ -67,6 +68,10 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
return "MODEM_PLUGIN_NAME";
}
public long getMaxLatency() {
return maxLatency;
}
public boolean start() {
for(String portName : serialPortList.getPortNames()) {
if(LOG.isLoggable(INFO))

View File

@@ -12,6 +12,7 @@ import net.sf.briar.util.StringUtils;
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 final Executor pluginExecutor;
@@ -34,6 +35,6 @@ public class ModemPluginFactory implements DuplexPluginFactory {
String enabled = callback.getConfig().get("enabled");
if(StringUtils.isNullOrEmpty(enabled)) return null;
return new ModemPlugin(pluginExecutor, modemFactory, serialPortList,
callback, POLLING_INTERVAL, true);
callback, MAX_LATENCY, POLLING_INTERVAL, true);
}
}

View File

@@ -46,8 +46,9 @@ class LanTcpPlugin extends TcpPlugin {
private final Clock clock;
LanTcpPlugin(@PluginExecutor Executor pluginExecutor, Clock clock,
DuplexPluginCallback callback, long pollingInterval) {
super(pluginExecutor, callback, pollingInterval);
DuplexPluginCallback callback, long maxLatency,
long pollingInterval) {
super(pluginExecutor, callback, maxLatency, pollingInterval);
this.clock = clock;
}

View File

@@ -12,6 +12,7 @@ import net.sf.briar.api.plugins.duplex.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 final Executor pluginExecutor;
@@ -27,7 +28,7 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
}
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
return new LanTcpPlugin(pluginExecutor, clock, callback,
return new LanTcpPlugin(pluginExecutor, clock, callback, MAX_LATENCY,
POLLING_INTERVAL);
}
}

View File

@@ -31,7 +31,7 @@ abstract class TcpPlugin implements DuplexPlugin {
protected final Executor pluginExecutor;
protected final DuplexPluginCallback callback;
protected final long pollingInterval;
protected final long maxLatency, pollingInterval;
protected volatile boolean running = false;
private volatile ServerSocket socket = null;
@@ -43,12 +43,18 @@ abstract class TcpPlugin implements DuplexPlugin {
protected abstract List<SocketAddress> getLocalSocketAddresses();
protected TcpPlugin(@PluginExecutor Executor pluginExecutor,
DuplexPluginCallback callback, long pollingInterval) {
DuplexPluginCallback callback, long maxLatency,
long pollingInterval) {
this.pluginExecutor = pluginExecutor;
this.callback = callback;
this.maxLatency = maxLatency;
this.pollingInterval = pollingInterval;
}
public long getMaxLatency() {
return maxLatency;
}
public boolean start() {
running = true;
pluginExecutor.execute(new Runnable() {

View File

@@ -38,9 +38,9 @@ class WanTcpPlugin extends TcpPlugin {
private volatile MappingResult mappingResult;
WanTcpPlugin(@PluginExecutor Executor pluginExecutor,
DuplexPluginCallback callback, long pollingInterval,
PortMapper portMapper) {
super(pluginExecutor, callback, pollingInterval);
DuplexPluginCallback callback, long maxLatency,
long pollingInterval, PortMapper portMapper) {
super(pluginExecutor, callback, maxLatency, pollingInterval);
this.portMapper = portMapper;
}

View File

@@ -11,6 +11,7 @@ import net.sf.briar.api.plugins.duplex.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 final Executor pluginExecutor;
@@ -27,7 +28,7 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
}
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
return new WanTcpPlugin(pluginExecutor, callback, POLLING_INTERVAL,
new PortMapperImpl(shutdownManager));
return new WanTcpPlugin(pluginExecutor, callback, MAX_LATENCY,
POLLING_INTERVAL, new PortMapperImpl(shutdownManager));
}
}

View File

@@ -46,16 +46,18 @@ class TorPlugin implements DuplexPlugin {
private final Executor pluginExecutor;
private final DuplexPluginCallback callback;
private final long pollingInterval;
private final long maxLatency, pollingInterval;
private boolean running = false, connected = false; // Locking: this
private NetLayer netLayer = null; // Locking: this
private NetServerSocket socket = null; // Locking: this
TorPlugin(@PluginExecutor Executor pluginExecutor,
DuplexPluginCallback callback, long pollingInterval) {
DuplexPluginCallback callback, long maxLatency,
long pollingInterval) {
this.pluginExecutor = pluginExecutor;
this.callback = callback;
this.maxLatency = maxLatency;
this.pollingInterval = pollingInterval;
}
@@ -67,6 +69,10 @@ class TorPlugin implements DuplexPlugin {
return "TOR_PLUGIN_NAME";
}
public long getMaxLatency() {
return maxLatency;
}
public boolean start() {
synchronized(this) {
running = true;

View File

@@ -11,6 +11,7 @@ import net.sf.briar.util.StringUtils;
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 final Executor pluginExecutor;
@@ -27,6 +28,7 @@ public class TorPluginFactory implements DuplexPluginFactory {
// This plugin is not enabled by default
String enabled = callback.getConfig().get("enabled");
if(StringUtils.isNullOrEmpty(enabled)) return null;
return new TorPlugin(pluginExecutor, callback, POLLING_INTERVAL);
return new TorPlugin(pluginExecutor, callback, MAX_LATENCY,
POLLING_INTERVAL);
}
}