diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothConnectionLimiter.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothConnectionLimiter.java index fa6c24916..9bf608a63 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothConnectionLimiter.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothConnectionLimiter.java @@ -45,10 +45,9 @@ interface BluetoothConnectionLimiter { boolean canOpenContactConnection(); /** - * Informs the limiter that a contact connection has been opened. The - * limiter may close the new connection if key agreement is in progress. + * Informs the limiter that a contact connection has been opened. *
- * Returns false if the limiter has closed the new connection. + * Returns true if the connection is allowed. */ boolean contactConnectionOpened(DuplexTransportConnection conn, boolean incoming); diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothConnectionLimiterImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothConnectionLimiterImpl.java index b2c6400cf..047c038e0 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothConnectionLimiterImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothConnectionLimiterImpl.java @@ -6,7 +6,6 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection; import org.briarproject.bramble.api.sync.event.CloseSyncConnectionsEvent; import org.briarproject.bramble.api.system.Clock; -import java.io.IOException; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -18,10 +17,8 @@ import javax.inject.Inject; import static java.lang.Math.min; import static java.util.logging.Level.INFO; -import static java.util.logging.Level.WARNING; import static java.util.logging.Logger.getLogger; import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID; -import static org.briarproject.bramble.util.LogUtils.logException; @NotNullByDefault @ThreadSafe @@ -83,25 +80,24 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter { @Override public boolean contactConnectionOpened(DuplexTransportConnection conn, boolean incoming) { - boolean accept; synchronized (lock) { if (keyAgreementInProgress) { LOG.info("Refusing contact connection during key agreement"); - accept = false; + return false; } else { long now = clock.currentTimeMillis(); - accept = incoming || isContactConnectionAllowedByLimit(now); - if (accept) { + if (incoming || isContactConnectionAllowedByLimit(now)) { connections.add(new ConnectionRecord(conn, now)); if (connections.size() > connectionLimit) { LOG.info("Attempting to raise connection limit"); timeOfLastAttempt = now; } + return true; + } else { + return false; } } } - if (!accept) tryToClose(conn); - return accept; } @Override @@ -113,15 +109,6 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter { } } - private void tryToClose(DuplexTransportConnection conn) { - try { - conn.getWriter().dispose(false); - conn.getReader().dispose(false, false); - } catch (IOException e) { - logException(LOG, WARNING, e); - } - } - @Override public void connectionClosed(DuplexTransportConnection conn, boolean exception) { diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothPlugin.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothPlugin.java index bf88a74b6..4645d6320 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothPlugin.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothPlugin.java @@ -235,11 +235,22 @@ abstract class BluetoothPlugin