mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Don't try to reuse already bound ports for key agreement.
This commit is contained in:
@@ -53,12 +53,12 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<SocketAddress> getLocalSocketAddresses() {
|
protected List<InetSocketAddress> 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 oldIpPorts = p.get(PROP_IP_PORTS);
|
String oldIpPorts = p.get(PROP_IP_PORTS);
|
||||||
List<InetSocketAddress> olds = parseSocketAddresses(oldIpPorts);
|
List<InetSocketAddress> olds = parseSocketAddresses(oldIpPorts);
|
||||||
List<SocketAddress> locals = new LinkedList<SocketAddress>();
|
List<InetSocketAddress> locals = new LinkedList<InetSocketAddress>();
|
||||||
for (InetAddress local : getLocalIpAddresses()) {
|
for (InetAddress local : getLocalIpAddresses()) {
|
||||||
if (isAcceptableAddress(local)) {
|
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
|
||||||
@@ -168,7 +168,9 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
|
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
|
||||||
ServerSocket ss = null;
|
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 {
|
try {
|
||||||
ss = new ServerSocket();
|
ss = new ServerSocket();
|
||||||
ss.bind(addr);
|
ss.bind(addr);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
* Returns zero or more socket addresses on which the plugin should listen,
|
* 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.
|
* 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
|
* 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.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -37,11 +36,11 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<SocketAddress> getLocalSocketAddresses() {
|
protected List<InetSocketAddress> 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();
|
||||||
InetSocketAddress old = parseSocketAddress(p.get(PROP_IP_PORT));
|
InetSocketAddress old = parseSocketAddress(p.get(PROP_IP_PORT));
|
||||||
List<SocketAddress> addrs = new LinkedList<SocketAddress>();
|
List<InetSocketAddress> addrs = new LinkedList<InetSocketAddress>();
|
||||||
for (InetAddress a : getLocalIpAddresses()) {
|
for (InetAddress a : getLocalIpAddresses()) {
|
||||||
if (isAcceptableAddress(a)) {
|
if (isAcceptableAddress(a)) {
|
||||||
// If this is the old address, try to use the same port
|
// If this is the old address, try to use the same port
|
||||||
|
|||||||
Reference in New Issue
Block a user