From 7e086d0f4eea0dd84dfd39e7ab71095e0d756f69 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 10 Aug 2016 18:06:07 +0100 Subject: [PATCH] Don't try to reuse already bound ports for key agreement. --- .../src/org/briarproject/plugins/tcp/LanTcpPlugin.java | 8 +++++--- .../src/org/briarproject/plugins/tcp/TcpPlugin.java | 2 +- .../src/org/briarproject/plugins/tcp/WanTcpPlugin.java | 5 ++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java index 499eb9d9b..34de50400 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java +++ b/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java @@ -53,12 +53,12 @@ class LanTcpPlugin extends TcpPlugin { } @Override - protected List getLocalSocketAddresses() { + protected List getLocalSocketAddresses() { // Use the same address and port as last time if available TransportProperties p = callback.getLocalProperties(); String oldIpPorts = p.get(PROP_IP_PORTS); List olds = parseSocketAddresses(oldIpPorts); - List locals = new LinkedList(); + List locals = new LinkedList(); for (InetAddress local : getLocalIpAddresses()) { if (isAcceptableAddress(local)) { // If this is the old address, try to use the same port @@ -168,7 +168,9 @@ class LanTcpPlugin extends TcpPlugin { @Override public KeyAgreementListener createKeyAgreementListener(byte[] commitment) { ServerSocket ss = null; - for (SocketAddress addr : getLocalSocketAddresses()) { + for (InetSocketAddress addr : getLocalSocketAddresses()) { + // Don't try to reuse the same port we use for contact connections + addr = new InetSocketAddress(addr.getAddress(), 0); try { ss = new ServerSocket(); ss.bind(addr); diff --git a/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java index 5fc8742fd..fab2a1cbb 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java +++ b/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java @@ -51,7 +51,7 @@ abstract class TcpPlugin implements DuplexPlugin { * Returns zero or more socket addresses on which the plugin should listen, * in order of preference. At most one of the addresses will be bound. */ - protected abstract List getLocalSocketAddresses(); + protected abstract List getLocalSocketAddresses(); /** * Adds the address on which the plugin is listening to the transport diff --git a/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java index bc54da0ae..82c3221a5 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java +++ b/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java @@ -9,7 +9,6 @@ import org.briarproject.api.properties.TransportProperties; import java.net.Inet4Address; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.SocketAddress; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -37,11 +36,11 @@ class WanTcpPlugin extends TcpPlugin { } @Override - protected List getLocalSocketAddresses() { + protected List getLocalSocketAddresses() { // Use the same address and port as last time if available TransportProperties p = callback.getLocalProperties(); InetSocketAddress old = parseSocketAddress(p.get(PROP_IP_PORT)); - List addrs = new LinkedList(); + List addrs = new LinkedList(); for (InetAddress a : getLocalIpAddresses()) { if (isAcceptableAddress(a)) { // If this is the old address, try to use the same port