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 9bf608a63..f8b965059 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 @@ -3,6 +3,7 @@ package org.briarproject.bramble.plugin.bluetooth; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection; +import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; @@ -22,11 +23,9 @@ interface BluetoothConnectionLimiter { long MIN_ATTEMPT_INTERVAL_MS = MINUTES.toMillis(2); /** - * The maximum exponent to use when backing off between attempts to raise - * the connection limit. The maximum interval between attempts is - * MIN_ATTEMPT_INTERVAL_MS * (1L << MAX_ATTEMPT_BACKOFF) =~ 34 hours. + * The maximum interval between attempts to raise the connection limit. */ - int MAX_ATTEMPT_BACKOFF = 10; + long MAX_ATTEMPT_INTERVAL_MS = DAYS.toMillis(2); /** * Informs the limiter that key agreement has started. 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 047c038e0..3ab39b03c 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 @@ -36,7 +36,7 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter { @GuardedBy("lock") private boolean keyAgreementInProgress = false; @GuardedBy("lock") - private int connectionLimit = 1, attemptBackoff = 0; + private int connectionLimit = 1; @GuardedBy("lock") private long timeOfLastAttempt = 0, attemptInterval = MIN_ATTEMPT_INTERVAL_MS; @@ -164,7 +164,6 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter { if (stable > connectionLimit) { LOG.info("Raising connection limit"); connectionLimit++; - attemptBackoff = 0; attemptInterval = MIN_ATTEMPT_INTERVAL_MS; } if (LOG.isLoggable(INFO)) { @@ -178,8 +177,7 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter { long now = clock.currentTimeMillis(); if (now - timeOfLastAttempt < STABILITY_PERIOD_MS) { LOG.info("Connection failed above limit, increasing interval"); - attemptBackoff = min(attemptBackoff + 1, MAX_ATTEMPT_BACKOFF); - attemptInterval = MIN_ATTEMPT_INTERVAL_MS * (1L << attemptBackoff); + attemptInterval = min(attemptInterval * 2, MAX_ATTEMPT_INTERVAL_MS); } }