mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Merge branch '302-lan-plugin-privacy' into 'master'
Store a fixed number of recent IP addresses, padded with fakes Closes #302 See merge request !159
This commit is contained in:
@@ -1,14 +1,19 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.plugins.tcp;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
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;
|
||||||
|
import org.briarproject.api.settings.Settings;
|
||||||
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@@ -17,6 +22,10 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
|
|
||||||
static final TransportId ID = new TransportId("lan");
|
static final TransportId ID = new TransportId("lan");
|
||||||
|
|
||||||
|
private static final int MAX_ADDRESSES = 5;
|
||||||
|
private static final String PROP_IP_PORTS = "ipPorts";
|
||||||
|
private static final String SEPARATOR = ",";
|
||||||
|
|
||||||
LanTcpPlugin(Executor ioExecutor, Backoff backoff,
|
LanTcpPlugin(Executor ioExecutor, Backoff backoff,
|
||||||
DuplexPluginCallback callback, int maxLatency, int maxIdleTime) {
|
DuplexPluginCallback callback, int maxLatency, int maxIdleTime) {
|
||||||
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime);
|
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime);
|
||||||
@@ -30,18 +39,74 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
protected List<SocketAddress> getLocalSocketAddresses() {
|
protected List<SocketAddress> getLocalSocketAddresses() {
|
||||||
// Use the same address and port as last time if available
|
// Use the same address and port as last time if available
|
||||||
TransportProperties p = callback.getLocalProperties();
|
TransportProperties p = callback.getLocalProperties();
|
||||||
String oldAddress = p.get("address"), oldPort = p.get("port");
|
String oldIpPorts = p.get(PROP_IP_PORTS);
|
||||||
InetSocketAddress old = parseSocketAddress(oldAddress, oldPort);
|
List<InetSocketAddress> olds = parseSocketAddresses(oldIpPorts);
|
||||||
List<SocketAddress> addrs = new LinkedList<SocketAddress>();
|
List<SocketAddress> locals = new LinkedList<SocketAddress>();
|
||||||
for (InetAddress a : getLocalIpAddresses()) {
|
for (InetAddress local : getLocalIpAddresses()) {
|
||||||
if (isAcceptableAddress(a)) {
|
if (isAcceptableAddress(local)) {
|
||||||
// If this is the old address, try to use the same port
|
// If this is the old address, try to use the same port
|
||||||
if (old != null && old.getAddress().equals(a))
|
for (InetSocketAddress old : olds) {
|
||||||
addrs.add(0, new InetSocketAddress(a, old.getPort()));
|
if (old.getAddress().equals(local)) {
|
||||||
addrs.add(new InetSocketAddress(a, 0));
|
int port = old.getPort();
|
||||||
|
locals.add(0, new InetSocketAddress(local, port));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
locals.add(new InetSocketAddress(local, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return addrs;
|
return locals;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<InetSocketAddress> parseSocketAddresses(String ipPorts) {
|
||||||
|
if (StringUtils.isNullOrEmpty(ipPorts)) return Collections.emptyList();
|
||||||
|
String[] split = ipPorts.split(SEPARATOR);
|
||||||
|
List<InetSocketAddress> remotes = new ArrayList<InetSocketAddress>();
|
||||||
|
for (String ipPort : split) {
|
||||||
|
InetSocketAddress a = parseSocketAddress(ipPort);
|
||||||
|
if (a != null) remotes.add(a);
|
||||||
|
}
|
||||||
|
return remotes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setLocalSocketAddress(InetSocketAddress a) {
|
||||||
|
String ipPort = getIpPortString(a);
|
||||||
|
// Get the list of recently used addresses
|
||||||
|
String setting = callback.getSettings().get(PROP_IP_PORTS);
|
||||||
|
List<String> recent = new ArrayList<String>();
|
||||||
|
if (!StringUtils.isNullOrEmpty(setting))
|
||||||
|
Collections.addAll(recent, setting.split(SEPARATOR));
|
||||||
|
// Is the address already in the list?
|
||||||
|
if (recent.remove(ipPort)) {
|
||||||
|
// Move the address to the start of the list
|
||||||
|
recent.add(0, ipPort);
|
||||||
|
setting = StringUtils.join(recent, SEPARATOR);
|
||||||
|
} else {
|
||||||
|
// Add the address to the start of the list
|
||||||
|
recent.add(0, ipPort);
|
||||||
|
// Drop the least recently used address if the list is full
|
||||||
|
if (recent.size() > MAX_ADDRESSES)
|
||||||
|
recent = recent.subList(0, MAX_ADDRESSES);
|
||||||
|
setting = StringUtils.join(recent, SEPARATOR);
|
||||||
|
// Update the list of addresses shared with contacts
|
||||||
|
List<String> shared = new ArrayList<String>(recent);
|
||||||
|
Collections.sort(shared);
|
||||||
|
String property = StringUtils.join(shared, SEPARATOR);
|
||||||
|
TransportProperties properties = new TransportProperties();
|
||||||
|
properties.put(PROP_IP_PORTS, property);
|
||||||
|
callback.mergeLocalProperties(properties);
|
||||||
|
}
|
||||||
|
// Save the setting
|
||||||
|
Settings settings = new Settings();
|
||||||
|
settings.put(PROP_IP_PORTS, setting);
|
||||||
|
callback.mergeSettings(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<InetSocketAddress> getRemoteSocketAddresses(ContactId c) {
|
||||||
|
TransportProperties p = callback.getRemoteProperties().get(c);
|
||||||
|
if (p == null) return Collections.emptyList();
|
||||||
|
return parseSocketAddresses(p.get(PROP_IP_PORTS));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAcceptableAddress(InetAddress a) {
|
private boolean isAcceptableAddress(InetAddress a) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ 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;
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -52,7 +51,22 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
*/
|
*/
|
||||||
protected abstract List<SocketAddress> getLocalSocketAddresses();
|
protected abstract List<SocketAddress> getLocalSocketAddresses();
|
||||||
|
|
||||||
/** Returns true if connections to the given address can be attempted. */
|
/**
|
||||||
|
* Adds the address on which the plugin is listening to the transport
|
||||||
|
* properties.
|
||||||
|
*/
|
||||||
|
protected abstract void setLocalSocketAddress(InetSocketAddress a);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns zero or more socket addresses for connecting to the given
|
||||||
|
* contact.
|
||||||
|
*/
|
||||||
|
protected abstract List<InetSocketAddress> getRemoteSocketAddresses(
|
||||||
|
ContactId c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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, Backoff backoff,
|
protected TcpPlugin(Executor ioExecutor, Backoff backoff,
|
||||||
@@ -126,17 +140,11 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getHostAddress(InetAddress a) {
|
protected String getIpPortString(InetSocketAddress a) {
|
||||||
String addr = a.getHostAddress();
|
String addr = a.getAddress().getHostAddress();
|
||||||
int percent = addr.indexOf('%');
|
int percent = addr.indexOf('%');
|
||||||
return percent == -1 ? addr : addr.substring(0, percent);
|
if (percent != -1) addr = addr.substring(0, percent);
|
||||||
}
|
return addr + ":" + a.getPort();
|
||||||
|
|
||||||
protected void setLocalSocketAddress(InetSocketAddress a) {
|
|
||||||
TransportProperties p = new TransportProperties();
|
|
||||||
p.put("address", getHostAddress(a.getAddress()));
|
|
||||||
p.put("port", String.valueOf(a.getPort()));
|
|
||||||
callback.mergeLocalProperties(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void acceptContactConnections() {
|
private void acceptContactConnections() {
|
||||||
@@ -197,37 +205,34 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
public DuplexTransportConnection createConnection(ContactId c) {
|
public DuplexTransportConnection createConnection(ContactId c) {
|
||||||
if (!isRunning()) return null;
|
if (!isRunning()) return null;
|
||||||
InetSocketAddress remote = getRemoteSocketAddress(c);
|
for (InetSocketAddress remote : getRemoteSocketAddresses(c)) {
|
||||||
if (remote == null) return null;
|
if (!isConnectable(remote)) {
|
||||||
if (!isConnectable(remote)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
if (LOG.isLoggable(INFO)) {
|
SocketAddress local = socket.getLocalSocketAddress();
|
||||||
SocketAddress local = socket.getLocalSocketAddress();
|
LOG.info(remote + " is not connectable from " + local);
|
||||||
LOG.info(remote + " is not connectable from " + local);
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Socket s = new Socket();
|
||||||
|
try {
|
||||||
|
if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + remote);
|
||||||
|
s.connect(remote);
|
||||||
|
s.setSoTimeout(socketTimeout);
|
||||||
|
if (LOG.isLoggable(INFO)) LOG.info("Connected to " + remote);
|
||||||
|
return new TcpTransportConnection(this, s);
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Could not connect to " + remote);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Socket s = new Socket();
|
|
||||||
try {
|
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + remote);
|
|
||||||
s.connect(remote);
|
|
||||||
s.setSoTimeout(socketTimeout);
|
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("Connected to " + remote);
|
|
||||||
return new TcpTransportConnection(this, s);
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("Could not connect to " + remote);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InetSocketAddress getRemoteSocketAddress(ContactId c) {
|
protected InetSocketAddress parseSocketAddress(String ipPort) {
|
||||||
TransportProperties p = callback.getRemoteProperties().get(c);
|
if (StringUtils.isNullOrEmpty(ipPort)) return null;
|
||||||
if (p == null) return null;
|
String[] split = ipPort.split(":");
|
||||||
return parseSocketAddress(p.get("address"), p.get("port"));
|
if (split.length != 2) return null;
|
||||||
}
|
String addr = split[0], port = split[1];
|
||||||
|
|
||||||
protected InetSocketAddress parseSocketAddress(String addr, String port) {
|
|
||||||
if (StringUtils.isNullOrEmpty(addr)) return null;
|
|
||||||
if (StringUtils.isNullOrEmpty(port)) return null;
|
|
||||||
// Ensure getByName() won't perform a DNS lookup
|
// Ensure getByName() won't perform a DNS lookup
|
||||||
if (!DOTTED_QUAD.matcher(addr).matches()) return null;
|
if (!DOTTED_QUAD.matcher(addr).matches()) return null;
|
||||||
try {
|
try {
|
||||||
@@ -235,10 +240,12 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
int p = Integer.parseInt(port);
|
int p = Integer.parseInt(port);
|
||||||
return new InetSocketAddress(a, p);
|
return new InetSocketAddress(a, p);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.warning("Invalid address: " + addr);
|
if (LOG.isLoggable(WARNING))
|
||||||
|
LOG.warning("Invalid address: " + addr);
|
||||||
return null;
|
return null;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.warning("Invalid port: " + port);
|
if (LOG.isLoggable(WARNING))
|
||||||
|
LOG.warning("Invalid port: " + port);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.contact.ContactId;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
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;
|
||||||
@@ -9,6 +10,7 @@ import java.net.Inet4Address;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@@ -17,6 +19,8 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
|
|
||||||
static final TransportId ID = new TransportId("wan");
|
static final TransportId ID = new TransportId("wan");
|
||||||
|
|
||||||
|
private static final String PROP_IP_PORT = "ipPort";
|
||||||
|
|
||||||
private final PortMapper portMapper;
|
private final PortMapper portMapper;
|
||||||
|
|
||||||
private volatile MappingResult mappingResult;
|
private volatile MappingResult mappingResult;
|
||||||
@@ -35,8 +39,7 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
protected List<SocketAddress> getLocalSocketAddresses() {
|
protected List<SocketAddress> getLocalSocketAddresses() {
|
||||||
// Use the same address and port as last time if available
|
// Use the same address and port as last time if available
|
||||||
TransportProperties p = callback.getLocalProperties();
|
TransportProperties p = callback.getLocalProperties();
|
||||||
String oldAddress = p.get("address"), oldPort = p.get("port");
|
InetSocketAddress old = parseSocketAddress(p.get(PROP_IP_PORT));
|
||||||
InetSocketAddress old = parseSocketAddress(oldAddress, oldPort);
|
|
||||||
List<SocketAddress> addrs = new LinkedList<SocketAddress>();
|
List<SocketAddress> addrs = new LinkedList<SocketAddress>();
|
||||||
for (InetAddress a : getLocalIpAddresses()) {
|
for (InetAddress a : getLocalIpAddresses()) {
|
||||||
if (isAcceptableAddress(a)) {
|
if (isAcceptableAddress(a)) {
|
||||||
@@ -69,6 +72,15 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
return 32768 + (int) (Math.random() * 32768);
|
return 32768 + (int) (Math.random() * 32768);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<InetSocketAddress> getRemoteSocketAddresses(ContactId c) {
|
||||||
|
TransportProperties p = callback.getRemoteProperties().get(c);
|
||||||
|
if (p == null) return Collections.emptyList();
|
||||||
|
InetSocketAddress parsed = parseSocketAddress(p.get(PROP_IP_PORT));
|
||||||
|
if (parsed == null) return Collections.emptyList();
|
||||||
|
return Collections.singletonList(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isConnectable(InetSocketAddress remote) {
|
protected boolean isConnectable(InetSocketAddress remote) {
|
||||||
if (remote.getPort() == 0) return false;
|
if (remote.getPort() == 0) return false;
|
||||||
@@ -83,8 +95,7 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
a = mappingResult.getExternal();
|
a = mappingResult.getExternal();
|
||||||
}
|
}
|
||||||
TransportProperties p = new TransportProperties();
|
TransportProperties p = new TransportProperties();
|
||||||
p.put("address", getHostAddress(a.getAddress()));
|
p.put(PROP_IP_PORT, getIpPortString(a));
|
||||||
p.put("port", String.valueOf(a.getPort()));
|
|
||||||
callback.mergeLocalProperties(p);
|
callback.mergeLocalProperties(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -91,14 +92,17 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
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));
|
||||||
String addrString = callback.local.get("address");
|
String ipPorts = callback.local.get("ipPorts");
|
||||||
assertNotNull(addrString);
|
assertNotNull(ipPorts);
|
||||||
|
String[] split = ipPorts.split(",");
|
||||||
|
assertEquals(1, split.length);
|
||||||
|
split = split[0].split(":");
|
||||||
|
assertEquals(2, split.length);
|
||||||
|
String addrString = split[0], portString = split[1];
|
||||||
InetAddress addr = InetAddress.getByName(addrString);
|
InetAddress addr = InetAddress.getByName(addrString);
|
||||||
assertTrue(addr instanceof Inet4Address);
|
assertTrue(addr instanceof Inet4Address);
|
||||||
assertFalse(addr.isLoopbackAddress());
|
assertFalse(addr.isLoopbackAddress());
|
||||||
assertTrue(addr.isLinkLocalAddress() || addr.isSiteLocalAddress());
|
assertTrue(addr.isLinkLocalAddress() || addr.isSiteLocalAddress());
|
||||||
String portString = callback.local.get("port");
|
|
||||||
assertNotNull(portString);
|
|
||||||
int port = Integer.parseInt(portString);
|
int port = Integer.parseInt(portString);
|
||||||
assertTrue(port > 0 && port < 65536);
|
assertTrue(port > 0 && port < 65536);
|
||||||
// The plugin should be listening on the port
|
// The plugin should be listening on the port
|
||||||
@@ -124,11 +128,17 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
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));
|
||||||
String addr = callback.local.get("address");
|
assertTrue(callback.propertiesLatch.await(5, SECONDS));
|
||||||
assertNotNull(addr);
|
String ipPorts = callback.local.get("ipPorts");
|
||||||
|
assertNotNull(ipPorts);
|
||||||
|
String[] split = ipPorts.split(",");
|
||||||
|
assertEquals(1, split.length);
|
||||||
|
split = split[0].split(":");
|
||||||
|
assertEquals(2, split.length);
|
||||||
|
String addrString = split[0];
|
||||||
// Listen on the same interface as the plugin
|
// Listen on the same interface as the plugin
|
||||||
final ServerSocket ss = new ServerSocket();
|
final ServerSocket ss = new ServerSocket();
|
||||||
ss.bind(new InetSocketAddress(addr, 0), 10);
|
ss.bind(new InetSocketAddress(addrString, 0), 10);
|
||||||
int port = ss.getLocalPort();
|
int port = ss.getLocalPort();
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
final AtomicBoolean error = new AtomicBoolean(false);
|
final AtomicBoolean error = new AtomicBoolean(false);
|
||||||
@@ -145,8 +155,7 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
}.start();
|
}.start();
|
||||||
// Tell the plugin about the port
|
// Tell the plugin about the port
|
||||||
TransportProperties p = new TransportProperties();
|
TransportProperties p = new TransportProperties();
|
||||||
p.put("address", addr);
|
p.put("ipPorts", addrString + ":" + port);
|
||||||
p.put("port", String.valueOf(port));
|
|
||||||
callback.remote.put(contactId, p);
|
callback.remote.put(contactId, p);
|
||||||
// Connect to the port
|
// Connect to the port
|
||||||
DuplexTransportConnection d = plugin.createConnection(contactId);
|
DuplexTransportConnection d = plugin.createConnection(contactId);
|
||||||
@@ -175,7 +184,7 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
private static class Callback implements DuplexPluginCallback {
|
private static class Callback implements DuplexPluginCallback {
|
||||||
|
|
||||||
private final Map<ContactId, TransportProperties> remote =
|
private final Map<ContactId, TransportProperties> remote =
|
||||||
new Hashtable<ContactId, TransportProperties>();
|
new Hashtable<>();
|
||||||
private final CountDownLatch propertiesLatch = new CountDownLatch(1);
|
private final CountDownLatch propertiesLatch = new CountDownLatch(1);
|
||||||
private final CountDownLatch connectionsLatch = new CountDownLatch(1);
|
private final CountDownLatch connectionsLatch = new CountDownLatch(1);
|
||||||
private final TransportProperties local = new TransportProperties();
|
private final TransportProperties local = new TransportProperties();
|
||||||
@@ -192,7 +201,8 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
return remote;
|
return remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mergeSettings(Settings s) {}
|
public void mergeSettings(Settings s) {
|
||||||
|
}
|
||||||
|
|
||||||
public void mergeLocalProperties(TransportProperties p) {
|
public void mergeLocalProperties(TransportProperties p) {
|
||||||
local.putAll(p);
|
local.putAll(p);
|
||||||
@@ -207,18 +217,22 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showMessage(String... message) {}
|
public void showMessage(String... message) {
|
||||||
|
}
|
||||||
|
|
||||||
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
||||||
connectionsLatch.countDown();
|
connectionsLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outgoingConnectionCreated(ContactId c,
|
public void outgoingConnectionCreated(ContactId c,
|
||||||
DuplexTransportConnection d) {}
|
DuplexTransportConnection d) {
|
||||||
|
}
|
||||||
|
|
||||||
public void transportEnabled() {}
|
public void transportEnabled() {
|
||||||
|
}
|
||||||
|
|
||||||
public void transportDisabled() {}
|
public void transportDisabled() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestBackoff implements Backoff {
|
private static class TestBackoff implements Backoff {
|
||||||
@@ -227,8 +241,10 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
return 60 * 1000;
|
return 60 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void increment() {}
|
public void increment() {
|
||||||
|
}
|
||||||
|
|
||||||
public void reset() {}
|
public void reset() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user