mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Disable polling while doing connect-via-BT
This commit is contained in:
@@ -473,6 +473,16 @@ abstract class AbstractBluetoothPlugin<S, SS> implements BluetoothPlugin,
|
||||
return discoverSemaphore.availablePermits() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disablePolling() {
|
||||
connectionLimiter.startLimiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enablePolling() {
|
||||
connectionLimiter.endLimiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DuplexTransportConnection discoverAndConnectForSetup(String uuid) {
|
||||
DuplexTransportConnection conn = discoverAndConnect(uuid);
|
||||
@@ -501,9 +511,9 @@ abstract class AbstractBluetoothPlugin<S, SS> implements BluetoothPlugin,
|
||||
if (s.getNamespace().equals(ID.getString()))
|
||||
ioExecutor.execute(() -> onSettingsUpdated(s.getSettings()));
|
||||
} else if (e instanceof KeyAgreementListeningEvent) {
|
||||
ioExecutor.execute(connectionLimiter::keyAgreementStarted);
|
||||
connectionLimiter.startLimiting();
|
||||
} else if (e instanceof KeyAgreementStoppedListeningEvent) {
|
||||
ioExecutor.execute(connectionLimiter::keyAgreementEnded);
|
||||
connectionLimiter.endLimiting();
|
||||
} else if (e instanceof RemoteTransportPropertiesUpdatedEvent) {
|
||||
RemoteTransportPropertiesUpdatedEvent r =
|
||||
(RemoteTransportPropertiesUpdatedEvent) e;
|
||||
|
||||
@@ -7,14 +7,15 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
interface BluetoothConnectionLimiter {
|
||||
|
||||
/**
|
||||
* Informs the limiter that key agreement has started.
|
||||
* Tells the limiter to not allow regular polling connections (because we
|
||||
* are about to do key agreement, or connect via BT for setup).
|
||||
*/
|
||||
void keyAgreementStarted();
|
||||
void startLimiting();
|
||||
|
||||
/**
|
||||
* Informs the limiter that key agreement has ended.
|
||||
* Tells the limiter to no longer limit regular polling connections.
|
||||
*/
|
||||
void keyAgreementEnded();
|
||||
void endLimiting();
|
||||
|
||||
/**
|
||||
* Returns true if a contact connection can be opened. This method does not
|
||||
|
||||
@@ -30,34 +30,37 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
||||
private final List<DuplexTransportConnection> connections =
|
||||
new LinkedList<>();
|
||||
@GuardedBy("lock")
|
||||
private boolean keyAgreementInProgress = false;
|
||||
private int limitingInProgress = 0;
|
||||
|
||||
BluetoothConnectionLimiterImpl(EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyAgreementStarted() {
|
||||
public void startLimiting() {
|
||||
synchronized (lock) {
|
||||
keyAgreementInProgress = true;
|
||||
limitingInProgress++;
|
||||
}
|
||||
LOG.info("Key agreement started");
|
||||
LOG.info("Limiting started");
|
||||
eventBus.broadcast(new CloseSyncConnectionsEvent(ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyAgreementEnded() {
|
||||
public void endLimiting() {
|
||||
synchronized (lock) {
|
||||
keyAgreementInProgress = false;
|
||||
limitingInProgress--;
|
||||
if (limitingInProgress < 0) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
LOG.info("Key agreement ended");
|
||||
LOG.info("Limiting ended");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOpenContactConnection() {
|
||||
synchronized (lock) {
|
||||
if (keyAgreementInProgress) {
|
||||
LOG.info("Can't open contact connection during key agreement");
|
||||
if (limitingInProgress > 0) {
|
||||
LOG.info("Can't open contact connection while limiting");
|
||||
return false;
|
||||
} else {
|
||||
LOG.info("Can open contact connection");
|
||||
|
||||
@@ -11,6 +11,10 @@ public interface BluetoothPlugin extends DuplexPlugin {
|
||||
|
||||
boolean isDiscovering();
|
||||
|
||||
void disablePolling();
|
||||
|
||||
void enablePolling();
|
||||
|
||||
@Nullable
|
||||
DuplexTransportConnection discoverAndConnectForSetup(String uuid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user