mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
New polling logic for Bluetooth. #251
The polling interval increases exponentially each time polling is unsuccessful, up to a maximum of 60 minutes. The interval is reset to 2 minutes whenever a connection is made and whenever Bluetooth is re-enabled.
This commit is contained in:
@@ -1,28 +1,34 @@
|
||||
package org.briarproject.plugins.bluetooth;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.plugins.Backoff;
|
||||
import org.briarproject.api.plugins.BackoffFactory;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.system.SystemClock;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||
private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
private static final int MIN_POLLING_INTERVAL = 2 * 60 * 1000; // 2 minutes
|
||||
private static final int MAX_POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final SecureRandom secureRandom;
|
||||
private final BackoffFactory backoffFactory;
|
||||
private final Clock clock;
|
||||
|
||||
public BluetoothPluginFactory(Executor ioExecutor,
|
||||
SecureRandom secureRandom) {
|
||||
SecureRandom secureRandom, BackoffFactory backoffFactory) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.secureRandom = secureRandom;
|
||||
this.backoffFactory = backoffFactory;
|
||||
clock = new SystemClock();
|
||||
}
|
||||
|
||||
@@ -31,7 +37,9 @@ public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||
return new BluetoothPlugin(ioExecutor, clock, secureRandom, callback,
|
||||
MAX_LATENCY, POLLING_INTERVAL);
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
return new BluetoothPlugin(ioExecutor, secureRandom, clock, backoff,
|
||||
callback, MAX_LATENCY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user