mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Check for stability whenever connections are closed.
This commit is contained in:
@@ -113,14 +113,18 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
|||||||
public void connectionClosed(DuplexTransportConnection conn,
|
public void connectionClosed(DuplexTransportConnection conn,
|
||||||
boolean exception) {
|
boolean exception) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
int numConnections = connections.size();
|
|
||||||
Iterator<ConnectionRecord> it = connections.iterator();
|
Iterator<ConnectionRecord> it = connections.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if (it.next().connection == conn) {
|
if (it.next().connection == conn) {
|
||||||
it.remove();
|
long now = clock.currentTimeMillis();
|
||||||
if (exception && numConnections > connectionLimit) {
|
if (exception) {
|
||||||
connectionFailedAboveLimit();
|
if (connections.size() > connectionLimit) {
|
||||||
|
connectionFailedAboveLimit(now);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
considerRaisingConnectionLimit(now);
|
||||||
}
|
}
|
||||||
|
it.remove();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,6 +136,7 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
|||||||
@Override
|
@Override
|
||||||
public void bluetoothDisabled() {
|
public void bluetoothDisabled() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
|
considerRaisingConnectionLimit(clock.currentTimeMillis());
|
||||||
connections.clear();
|
connections.clear();
|
||||||
LOG.info("Bluetooth disabled");
|
LOG.info("Bluetooth disabled");
|
||||||
}
|
}
|
||||||
@@ -173,8 +178,7 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("lock")
|
@GuardedBy("lock")
|
||||||
private void connectionFailedAboveLimit() {
|
private void connectionFailedAboveLimit(long now) {
|
||||||
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");
|
||||||
attemptInterval = min(attemptInterval * 2, MAX_ATTEMPT_INTERVAL_MS);
|
attemptInterval = min(attemptInterval * 2, MAX_ATTEMPT_INTERVAL_MS);
|
||||||
|
|||||||
Reference in New Issue
Block a user