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