mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Simplify backoff.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user