mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
New polling logic for LAN (and WAN). #252
Same exponential backoff approach as Bluetooth.
This commit is contained in:
@@ -46,7 +46,7 @@ public class AndroidPluginsModule extends PluginsModule {
|
|||||||
DuplexPluginFactory tor = new TorPluginFactory(ioExecutor, appContext,
|
DuplexPluginFactory tor = new TorPluginFactory(ioExecutor, appContext,
|
||||||
locationUtils, eventBus);
|
locationUtils, eventBus);
|
||||||
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
||||||
appContext);
|
backoffFactory, appContext);
|
||||||
final Collection<DuplexPluginFactory> factories =
|
final Collection<DuplexPluginFactory> factories =
|
||||||
Arrays.asList(bluetooth, tor, lan);
|
Arrays.asList(bluetooth, tor, lan);
|
||||||
return new DuplexPluginConfig() {
|
return new DuplexPluginConfig() {
|
||||||
|
|||||||
@@ -1,14 +1,5 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.plugins.tcp;
|
||||||
|
|
||||||
import static android.content.Context.CONNECTIVITY_SERVICE;
|
|
||||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
|
||||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -16,6 +7,16 @@ import android.content.IntentFilter;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
|
||||||
|
import org.briarproject.api.plugins.Backoff;
|
||||||
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||||
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||||
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
|
|
||||||
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -25,10 +26,10 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
|
|
||||||
private volatile BroadcastReceiver networkStateReceiver = null;
|
private volatile BroadcastReceiver networkStateReceiver = null;
|
||||||
|
|
||||||
AndroidLanTcpPlugin(Executor ioExecutor, Context appContext,
|
AndroidLanTcpPlugin(Executor ioExecutor, Backoff backoff,
|
||||||
DuplexPluginCallback callback, int maxLatency,
|
Context appContext, DuplexPluginCallback callback, int maxLatency,
|
||||||
int maxIdleTime, int pollingInterval) {
|
int maxIdleTime) {
|
||||||
super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval);
|
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime);
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,32 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.plugins.tcp;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
|
import org.briarproject.api.plugins.Backoff;
|
||||||
|
import org.briarproject.api.plugins.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||||
|
|
||||||
import android.content.Context;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||||
private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
private static final int MIN_POLLING_INTERVAL = 2 * 60 * 1000; // 2 minutes
|
||||||
|
private static final int MAX_POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
|
||||||
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
|
private final BackoffFactory backoffFactory;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
|
|
||||||
public AndroidLanTcpPluginFactory(Executor ioExecutor, Context appContext) {
|
public AndroidLanTcpPluginFactory(Executor ioExecutor,
|
||||||
|
BackoffFactory backoffFactory, Context appContext) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.backoffFactory = backoffFactory;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +35,9 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new AndroidLanTcpPlugin(ioExecutor, appContext, callback,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
|
return new AndroidLanTcpPlugin(ioExecutor, backoff, appContext,
|
||||||
|
callback, MAX_LATENCY, MAX_IDLE_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.plugins.tcp;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
|
import org.briarproject.api.plugins.Backoff;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
import org.briarproject.api.properties.TransportProperties;
|
||||||
|
|
||||||
@@ -16,9 +17,9 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
|
|
||||||
static final TransportId ID = new TransportId("lan");
|
static final TransportId ID = new TransportId("lan");
|
||||||
|
|
||||||
LanTcpPlugin(Executor ioExecutor, DuplexPluginCallback callback,
|
LanTcpPlugin(Executor ioExecutor, Backoff backoff,
|
||||||
int maxLatency, int maxIdleTime, int pollingInterval) {
|
DuplexPluginCallback callback, int maxLatency, int maxIdleTime) {
|
||||||
super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval);
|
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
|
|||||||
@@ -1,22 +1,29 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.plugins.tcp;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
|
import org.briarproject.api.plugins.Backoff;
|
||||||
|
import org.briarproject.api.plugins.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||||
private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
private static final int MIN_POLLING_INTERVAL = 2 * 60 * 1000; // 2 minutes
|
||||||
|
private static final int MAX_POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
|
||||||
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
|
private final BackoffFactory backoffFactory;
|
||||||
|
|
||||||
public LanTcpPluginFactory(Executor ioExecutor) {
|
public LanTcpPluginFactory(Executor ioExecutor,
|
||||||
|
BackoffFactory backoffFactory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.backoffFactory = backoffFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
@@ -24,7 +31,9 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new LanTcpPlugin(ioExecutor, callback, MAX_LATENCY,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_IDLE_TIME, POLLING_INTERVAL);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
|
return new LanTcpPlugin(ioExecutor, backoff, callback, MAX_LATENCY,
|
||||||
|
MAX_IDLE_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.briarproject.plugins.tcp;
|
|||||||
|
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.api.crypto.PseudoRandom;
|
||||||
|
import org.briarproject.api.plugins.Backoff;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
@@ -36,8 +37,9 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
Logger.getLogger(TcpPlugin.class.getName());
|
Logger.getLogger(TcpPlugin.class.getName());
|
||||||
|
|
||||||
protected final Executor ioExecutor;
|
protected final Executor ioExecutor;
|
||||||
|
protected final Backoff backoff;
|
||||||
protected final DuplexPluginCallback callback;
|
protected final DuplexPluginCallback callback;
|
||||||
protected final int maxLatency, maxIdleTime, pollingInterval, socketTimeout;
|
protected final int maxLatency, maxIdleTime, socketTimeout;
|
||||||
|
|
||||||
protected volatile boolean running = false;
|
protected volatile boolean running = false;
|
||||||
protected volatile ServerSocket socket = null;
|
protected volatile ServerSocket socket = null;
|
||||||
@@ -51,13 +53,13 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
/** Returns true if connections to the given address can be attempted. */
|
/** Returns true if connections to the given address can be attempted. */
|
||||||
protected abstract boolean isConnectable(InetSocketAddress remote);
|
protected abstract boolean isConnectable(InetSocketAddress remote);
|
||||||
|
|
||||||
protected TcpPlugin(Executor ioExecutor, DuplexPluginCallback callback,
|
protected TcpPlugin(Executor ioExecutor, Backoff backoff,
|
||||||
int maxLatency, int maxIdleTime, int pollingInterval) {
|
DuplexPluginCallback callback, int maxLatency, int maxIdleTime) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.backoff = backoff;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
this.maxIdleTime = maxIdleTime;
|
this.maxIdleTime = maxIdleTime;
|
||||||
this.pollingInterval = pollingInterval;
|
|
||||||
if (maxIdleTime > Integer.MAX_VALUE / 2)
|
if (maxIdleTime > Integer.MAX_VALUE / 2)
|
||||||
socketTimeout = Integer.MAX_VALUE;
|
socketTimeout = Integer.MAX_VALUE;
|
||||||
else socketTimeout = maxIdleTime * 2;
|
else socketTimeout = maxIdleTime * 2;
|
||||||
@@ -102,6 +104,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
socket = ss;
|
socket = ss;
|
||||||
|
backoff.reset();
|
||||||
SocketAddress local = ss.getLocalSocketAddress();
|
SocketAddress local = ss.getLocalSocketAddress();
|
||||||
setLocalSocketAddress((InetSocketAddress) local);
|
setLocalSocketAddress((InetSocketAddress) local);
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("Listening on " + local);
|
if (LOG.isLoggable(INFO)) LOG.info("Listening on " + local);
|
||||||
@@ -147,6 +150,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
}
|
}
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Connection from " + s.getRemoteSocketAddress());
|
LOG.info("Connection from " + s.getRemoteSocketAddress());
|
||||||
|
backoff.reset();
|
||||||
TcpTransportConnection conn = new TcpTransportConnection(this, s);
|
TcpTransportConnection conn = new TcpTransportConnection(this, s);
|
||||||
callback.incomingConnectionCreated(conn);
|
callback.incomingConnectionCreated(conn);
|
||||||
}
|
}
|
||||||
@@ -166,11 +170,12 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getPollingInterval() {
|
public int getPollingInterval() {
|
||||||
return pollingInterval;
|
return backoff.getPollingInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void poll(Collection<ContactId> connected) {
|
public void poll(Collection<ContactId> connected) {
|
||||||
if (!isRunning()) return;
|
if (!isRunning()) return;
|
||||||
|
backoff.increment();
|
||||||
for (ContactId c : callback.getRemoteProperties().keySet())
|
for (ContactId c : callback.getRemoteProperties().keySet())
|
||||||
if (!connected.contains(c)) connectAndCallBack(c);
|
if (!connected.contains(c)) connectAndCallBack(c);
|
||||||
}
|
}
|
||||||
@@ -179,7 +184,10 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
ioExecutor.execute(new Runnable() {
|
ioExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
DuplexTransportConnection d = createConnection(c);
|
DuplexTransportConnection d = createConnection(c);
|
||||||
if (d != null) callback.outgoingConnectionCreated(c, d);
|
if (d != null) {
|
||||||
|
backoff.reset();
|
||||||
|
callback.outgoingConnectionCreated(c, d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.plugins.tcp;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
|
import org.briarproject.api.plugins.Backoff;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
import org.briarproject.api.properties.TransportProperties;
|
||||||
|
|
||||||
@@ -20,10 +21,9 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
|
|
||||||
private volatile MappingResult mappingResult;
|
private volatile MappingResult mappingResult;
|
||||||
|
|
||||||
WanTcpPlugin(Executor ioExecutor, PortMapper portMapper,
|
WanTcpPlugin(Executor ioExecutor, Backoff backoff, PortMapper portMapper,
|
||||||
DuplexPluginCallback callback, int maxLatency, int maxIdleTime,
|
DuplexPluginCallback callback, int maxLatency, int maxIdleTime) {
|
||||||
int pollingInterval) {
|
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime);
|
||||||
super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval);
|
|
||||||
this.portMapper = portMapper;
|
this.portMapper = portMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,31 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.plugins.tcp;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||||
|
import org.briarproject.api.plugins.Backoff;
|
||||||
|
import org.briarproject.api.plugins.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||||
private static final int POLLING_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
private static final int MIN_POLLING_INTERVAL = 2 * 60 * 1000; // 2 minutes
|
||||||
|
private static final int MAX_POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
|
||||||
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
|
private final BackoffFactory backoffFactory;
|
||||||
private final ShutdownManager shutdownManager;
|
private final ShutdownManager shutdownManager;
|
||||||
|
|
||||||
public WanTcpPluginFactory(Executor ioExecutor,
|
public WanTcpPluginFactory(Executor ioExecutor,
|
||||||
ShutdownManager shutdownManager) {
|
BackoffFactory backoffFactory, ShutdownManager shutdownManager) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.backoffFactory = backoffFactory;
|
||||||
this.shutdownManager = shutdownManager;
|
this.shutdownManager = shutdownManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +34,10 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new WanTcpPlugin(ioExecutor, new PortMapperImpl(shutdownManager),
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
callback, MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
|
return new WanTcpPlugin(ioExecutor, backoff,
|
||||||
|
new PortMapperImpl(shutdownManager), callback, MAX_LATENCY,
|
||||||
|
MAX_IDLE_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,9 +47,10 @@ public class DesktopPluginsModule extends PluginsModule {
|
|||||||
random, backoffFactory);
|
random, backoffFactory);
|
||||||
DuplexPluginFactory modem = new ModemPluginFactory(ioExecutor,
|
DuplexPluginFactory modem = new ModemPluginFactory(ioExecutor,
|
||||||
reliabilityFactory);
|
reliabilityFactory);
|
||||||
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor);
|
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor,
|
||||||
|
backoffFactory);
|
||||||
DuplexPluginFactory wan = new WanTcpPluginFactory(ioExecutor,
|
DuplexPluginFactory wan = new WanTcpPluginFactory(ioExecutor,
|
||||||
shutdownManager);
|
backoffFactory, shutdownManager);
|
||||||
final Collection<DuplexPluginFactory> factories =
|
final Collection<DuplexPluginFactory> factories =
|
||||||
Arrays.asList(bluetooth, modem, lan, wan);
|
Arrays.asList(bluetooth, modem, lan, wan);
|
||||||
return new DuplexPluginConfig() {
|
return new DuplexPluginConfig() {
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
|
||||||
|
|
||||||
import org.briarproject.api.contact.ContactId;
|
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
|
||||||
import org.briarproject.api.settings.Settings;
|
|
||||||
import org.briarproject.plugins.DuplexClientTest;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
// This is not a JUnit test - it has to be run manually while the server test
|
|
||||||
// is running on another machine
|
|
||||||
public class LanTcpClientTest extends DuplexClientTest {
|
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 60 * 1000;
|
|
||||||
private static final int MAX_IDLE_TIME = 30 * 1000;
|
|
||||||
private static final int POLLING_INTERVAL = 60 * 1000;
|
|
||||||
|
|
||||||
private LanTcpClientTest(Executor executor, String serverAddress,
|
|
||||||
String serverPort) {
|
|
||||||
// Store the server's internal address and port
|
|
||||||
TransportProperties p = new TransportProperties();
|
|
||||||
p.put("address", serverAddress);
|
|
||||||
p.put("port", serverPort);
|
|
||||||
Map<ContactId, TransportProperties> remote =
|
|
||||||
Collections.singletonMap(contactId, p);
|
|
||||||
// Create the plugin
|
|
||||||
callback = new ClientCallback(new Settings(),
|
|
||||||
new TransportProperties(), remote);
|
|
||||||
plugin = new LanTcpPlugin(executor, callback, MAX_LATENCY,
|
|
||||||
MAX_IDLE_TIME, POLLING_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
if (args.length != 2) {
|
|
||||||
System.err.println("Please specify the server's address and port");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
ExecutorService executor = Executors.newCachedThreadPool();
|
|
||||||
try {
|
|
||||||
new LanTcpClientTest(executor, args[0], args[1]).run();
|
|
||||||
} finally {
|
|
||||||
executor.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package org.briarproject.plugins.tcp;
|
|||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
import org.briarproject.api.plugins.Backoff;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
@@ -32,10 +33,11 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class LanTcpPluginTest extends BriarTestCase {
|
public class LanTcpPluginTest extends BriarTestCase {
|
||||||
|
|
||||||
private final ContactId contactId = new ContactId(234);
|
private final ContactId contactId = new ContactId(234);
|
||||||
|
private final Backoff backoff = new TestBackoff();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddressesAreOnSameLan() {
|
public void testAddressesAreOnSameLan() {
|
||||||
LanTcpPlugin plugin = new LanTcpPlugin(null, null, 0, 0, 0);
|
LanTcpPlugin plugin = new LanTcpPlugin(null, null, null, 0, 0);
|
||||||
// Local and remote in 10.0.0.0/8 should return true
|
// Local and remote in 10.0.0.0/8 should return true
|
||||||
assertTrue(plugin.addressesAreOnSameLan(makeAddress(10, 0, 0, 0),
|
assertTrue(plugin.addressesAreOnSameLan(makeAddress(10, 0, 0, 0),
|
||||||
makeAddress(10, 255, 255, 255)));
|
makeAddress(10, 255, 255, 255)));
|
||||||
@@ -84,7 +86,8 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
Callback callback = new Callback();
|
Callback callback = new Callback();
|
||||||
Executor executor = Executors.newCachedThreadPool();
|
Executor executor = Executors.newCachedThreadPool();
|
||||||
DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0);
|
DuplexPlugin plugin = new LanTcpPlugin(executor, backoff, 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));
|
||||||
@@ -116,7 +119,8 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
Callback callback = new Callback();
|
Callback callback = new Callback();
|
||||||
Executor executor = Executors.newCachedThreadPool();
|
Executor executor = Executors.newCachedThreadPool();
|
||||||
DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0);
|
DuplexPlugin plugin = new LanTcpPlugin(executor, backoff, 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));
|
||||||
@@ -216,4 +220,15 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
public void transportDisabled() {}
|
public void transportDisabled() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class TestBackoff implements Backoff {
|
||||||
|
|
||||||
|
public int getPollingInterval() {
|
||||||
|
return 60 * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increment() {}
|
||||||
|
|
||||||
|
public void reset() {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
|
||||||
|
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
|
||||||
import org.briarproject.api.settings.Settings;
|
|
||||||
import org.briarproject.plugins.DuplexServerTest;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
// This is not a JUnit test - it has to be run manually while the client test
|
|
||||||
// is running on another machine
|
|
||||||
public class LanTcpServerTest extends DuplexServerTest {
|
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 60 * 1000;
|
|
||||||
private static final int MAX_IDLE_TIME = 30 * 1000;
|
|
||||||
private static final int POLLING_INTERVAL = 60 * 1000;
|
|
||||||
|
|
||||||
private LanTcpServerTest(Executor executor) {
|
|
||||||
callback = new ServerCallback(new Settings(),
|
|
||||||
new TransportProperties(),
|
|
||||||
Collections.singletonMap(contactId, new TransportProperties()));
|
|
||||||
plugin = new LanTcpPlugin(executor, callback, MAX_LATENCY,
|
|
||||||
MAX_IDLE_TIME, POLLING_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
ExecutorService executor = Executors.newCachedThreadPool();
|
|
||||||
try {
|
|
||||||
new LanTcpServerTest(executor).run();
|
|
||||||
} finally {
|
|
||||||
executor.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user