mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Don't treat an incoming connection as an attempt to raise the limit.
This commit is contained in:
@@ -88,7 +88,7 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
|||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
if (incoming || isContactConnectionAllowedByLimit(now)) {
|
if (incoming || isContactConnectionAllowedByLimit(now)) {
|
||||||
connections.add(new ConnectionRecord(conn, now));
|
connections.add(new ConnectionRecord(conn, now));
|
||||||
if (connections.size() > connectionLimit) {
|
if (!incoming && connections.size() > connectionLimit) {
|
||||||
LOG.info("Attempting to raise connection limit");
|
LOG.info("Attempting to raise connection limit");
|
||||||
timeOfLastAttempt = now;
|
timeOfLastAttempt = now;
|
||||||
}
|
}
|
||||||
@@ -117,13 +117,8 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
|||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if (it.next().connection == conn) {
|
if (it.next().connection == conn) {
|
||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
if (exception) {
|
if (exception) connectionFailed(now);
|
||||||
if (connections.size() > connectionLimit) {
|
else considerRaisingConnectionLimit(now);
|
||||||
connectionFailedAboveLimit(now);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
considerRaisingConnectionLimit(now);
|
|
||||||
}
|
|
||||||
it.remove();
|
it.remove();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -136,9 +131,9 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
|||||||
@Override
|
@Override
|
||||||
public void bluetoothDisabled() {
|
public void bluetoothDisabled() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
|
LOG.info("Bluetooth disabled");
|
||||||
considerRaisingConnectionLimit(clock.currentTimeMillis());
|
considerRaisingConnectionLimit(clock.currentTimeMillis());
|
||||||
connections.clear();
|
connections.clear();
|
||||||
LOG.info("Bluetooth disabled");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +163,7 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
|||||||
}
|
}
|
||||||
if (stable > connectionLimit) {
|
if (stable > connectionLimit) {
|
||||||
LOG.info("Raising connection limit");
|
LOG.info("Raising connection limit");
|
||||||
connectionLimit++;
|
connectionLimit = stable;
|
||||||
attemptInterval = MIN_ATTEMPT_INTERVAL_MS;
|
attemptInterval = MIN_ATTEMPT_INTERVAL_MS;
|
||||||
}
|
}
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
@@ -178,8 +173,9 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("lock")
|
@GuardedBy("lock")
|
||||||
private void connectionFailedAboveLimit(long now) {
|
private void connectionFailed(long now) {
|
||||||
if (now - timeOfLastAttempt < STABILITY_PERIOD_MS) {
|
if (connections.size() > connectionLimit &&
|
||||||
|
now - timeOfLastAttempt < STABILITY_PERIOD_MS) {
|
||||||
LOG.info("Connection failed above limit, increasing interval");
|
LOG.info("Connection failed above limit, increasing interval");
|
||||||
attemptInterval = min(attemptInterval * 2, MAX_ATTEMPT_INTERVAL_MS);
|
attemptInterval = min(attemptInterval * 2, MAX_ATTEMPT_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user