Verified Commit 173b6006 authored by akwizgran's avatar akwizgran

Don't treat an incoming connection as an attempt to raise the limit.

parent 99edb893
Pipeline #4372 passed with stage
in 8 minutes and 48 seconds
...@@ -88,7 +88,7 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment