mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch '447-lan-ports' into 'master'
Don't try to reuse already bound ports for key agreement This is one cause of #447, but probably not the only one. See merge request !281
This commit is contained in:
@@ -53,12 +53,12 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SocketAddress> getLocalSocketAddresses() {
|
||||
protected List<InetSocketAddress> getLocalSocketAddresses() {
|
||||
// Use the same address and port as last time if available
|
||||
TransportProperties p = callback.getLocalProperties();
|
||||
String oldIpPorts = p.get(PROP_IP_PORTS);
|
||||
List<InetSocketAddress> olds = parseSocketAddresses(oldIpPorts);
|
||||
List<SocketAddress> locals = new LinkedList<SocketAddress>();
|
||||
List<InetSocketAddress> locals = new LinkedList<InetSocketAddress>();
|
||||
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);
|
||||
|
||||
@@ -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<SocketAddress> getLocalSocketAddresses();
|
||||
protected abstract List<InetSocketAddress> getLocalSocketAddresses();
|
||||
|
||||
/**
|
||||
* Adds the address on which the plugin is listening to the transport
|
||||
|
||||
@@ -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<SocketAddress> getLocalSocketAddresses() {
|
||||
protected List<InetSocketAddress> 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<SocketAddress> addrs = new LinkedList<SocketAddress>();
|
||||
List<InetSocketAddress> addrs = new LinkedList<InetSocketAddress>();
|
||||
for (InetAddress a : getLocalIpAddresses()) {
|
||||
if (isAcceptableAddress(a)) {
|
||||
// If this is the old address, try to use the same port
|
||||
|
||||
Reference in New Issue
Block a user