mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Notify callback of state changes while holding lock.
This commit is contained in:
@@ -84,7 +84,6 @@ class AndroidLanTcpPlugin extends LanTcpPlugin implements EventListener {
|
||||
public void start() {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
state.setStarted();
|
||||
callback.pluginStateChanged(getState());
|
||||
updateConnectionStatus();
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,6 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
}
|
||||
updateProperties();
|
||||
state.setStarted();
|
||||
callback.pluginStateChanged(getState());
|
||||
loadSettings(callback.getSettings());
|
||||
if (shouldAllowContactConnections()) {
|
||||
if (isAdapterEnabled()) bind();
|
||||
@@ -199,7 +198,6 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
return;
|
||||
}
|
||||
backoff.reset();
|
||||
callback.pluginStateChanged(getState());
|
||||
acceptContactConnections(ss);
|
||||
});
|
||||
}
|
||||
@@ -250,7 +248,6 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
@Override
|
||||
public void stop() {
|
||||
SS ss = state.setStopped();
|
||||
callback.pluginStateChanged(getState());
|
||||
tryToClose(ss);
|
||||
disableAdapterIfEnabledByUs();
|
||||
}
|
||||
@@ -492,6 +489,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
|
||||
synchronized void setStarted() {
|
||||
started = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -499,12 +497,14 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
stopped = true;
|
||||
SS ss = serverSocket;
|
||||
serverSocket = null;
|
||||
callback.pluginStateChanged(getState());
|
||||
return ss;
|
||||
}
|
||||
|
||||
synchronized boolean setServerSocket(SS ss) {
|
||||
if (stopped || serverSocket != null) return false;
|
||||
serverSocket = ss;
|
||||
callback.pluginStateChanged(getState());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,6 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
public void start() {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
state.setStarted();
|
||||
callback.pluginStateChanged(getState());
|
||||
bind();
|
||||
}
|
||||
|
||||
@@ -154,7 +153,6 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
setLocalSocketAddress(local);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Listening on " + scrubSocketAddress(local));
|
||||
callback.pluginStateChanged(getState());
|
||||
acceptContactConnections(ss);
|
||||
});
|
||||
}
|
||||
@@ -176,7 +174,6 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
// This is expected when the server socket is closed
|
||||
LOG.info("Server socket closed");
|
||||
state.clearServerSocket(ss);
|
||||
callback.pluginStateChanged(getState());
|
||||
return;
|
||||
}
|
||||
if (LOG.isLoggable(INFO))
|
||||
@@ -190,7 +187,6 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
@Override
|
||||
public void stop() {
|
||||
ServerSocket ss = state.setStopped();
|
||||
callback.pluginStateChanged(getState());
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
}
|
||||
|
||||
@@ -337,7 +333,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
protected static class PluginState {
|
||||
protected class PluginState {
|
||||
|
||||
@GuardedBy("this")
|
||||
private boolean started = false, stopped = false;
|
||||
@@ -347,6 +343,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
|
||||
synchronized void setStarted() {
|
||||
started = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -354,6 +351,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
stopped = true;
|
||||
ServerSocket ss = serverSocket;
|
||||
serverSocket = null;
|
||||
callback.pluginStateChanged(getState());
|
||||
return ss;
|
||||
}
|
||||
|
||||
@@ -365,11 +363,13 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
synchronized boolean setServerSocket(ServerSocket ss) {
|
||||
if (stopped || serverSocket != null) return false;
|
||||
serverSocket = ss;
|
||||
callback.pluginStateChanged(getState());
|
||||
return true;
|
||||
}
|
||||
|
||||
synchronized void clearServerSocket(ServerSocket ss) {
|
||||
if (serverSocket == ss) serverSocket = null;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized State getState() {
|
||||
|
||||
@@ -193,7 +193,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
public void start() throws PluginException {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
state.setStarted();
|
||||
callback.pluginStateChanged(getState());
|
||||
if (!torDirectory.exists()) {
|
||||
if (!torDirectory.mkdirs()) {
|
||||
LOG.warning("Could not create Tor directory.");
|
||||
@@ -480,7 +479,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
protected void enableNetwork(boolean enable) throws IOException {
|
||||
state.enableNetwork(enable);
|
||||
callback.pluginStateChanged(getState());
|
||||
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
||||
}
|
||||
|
||||
@@ -506,7 +504,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
@Override
|
||||
public void stop() {
|
||||
ServerSocket ss = state.setStopped();
|
||||
callback.pluginStateChanged(getState());
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
if (controlSocket != null && controlConnection != null) {
|
||||
try {
|
||||
@@ -682,7 +679,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
state.getAndSetCircuitBuilt()) {
|
||||
LOG.info("First circuit built");
|
||||
backoff.reset();
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -715,7 +711,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
if (severity.equals("NOTICE") && msg.startsWith("Bootstrapped 100%")) {
|
||||
state.setBootstrapped();
|
||||
backoff.reset();
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -830,7 +825,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
|
||||
state.setDisabledBySettings(disabledBySettings, reasonDisabled);
|
||||
callback.pluginStateChanged(getState());
|
||||
|
||||
try {
|
||||
enableBridges(enableBridges, useMeek);
|
||||
@@ -848,7 +842,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
protected static class PluginState {
|
||||
protected class PluginState {
|
||||
|
||||
@GuardedBy("this")
|
||||
private boolean started = false,
|
||||
@@ -869,6 +863,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
synchronized void setStarted() {
|
||||
started = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized void setTorStarted() {
|
||||
@@ -885,16 +880,19 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
stopped = true;
|
||||
ServerSocket ss = serverSocket;
|
||||
serverSocket = null;
|
||||
callback.pluginStateChanged(getState());
|
||||
return ss;
|
||||
}
|
||||
|
||||
synchronized void setBootstrapped() {
|
||||
bootstrapped = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized boolean getAndSetCircuitBuilt() {
|
||||
boolean firstCircuit = !circuitBuilt;
|
||||
circuitBuilt = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
return firstCircuit;
|
||||
}
|
||||
|
||||
@@ -902,12 +900,14 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
networkInitialised = true;
|
||||
networkEnabled = enable;
|
||||
if (!enable) circuitBuilt = false;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized void setDisabledBySettings(boolean disabledBySettings,
|
||||
int reasonDisabled) {
|
||||
this.disabledBySettings = disabledBySettings;
|
||||
this.reasonDisabled = reasonDisabled;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized boolean setServerSocket(ServerSocket ss) {
|
||||
|
||||
@@ -84,7 +84,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
public void start() throws PluginException {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
state.setStarted();
|
||||
callback.pluginStateChanged(getState());
|
||||
for (String portName : serialPortList.getPortNames()) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Trying to initialise modem on " + portName);
|
||||
@@ -94,7 +93,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Initialised modem on " + portName);
|
||||
state.setInitialised();
|
||||
callback.pluginStateChanged(getState());
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
@@ -102,14 +100,12 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
}
|
||||
LOG.warning("Failed to initialised modem");
|
||||
state.setFailed();
|
||||
callback.pluginStateChanged(getState());
|
||||
throw new PluginException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
state.setStopped();
|
||||
callback.pluginStateChanged(getState());
|
||||
if (modem != null) {
|
||||
try {
|
||||
modem.stop();
|
||||
@@ -162,7 +158,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
}
|
||||
LOG.warning("Failed to initialise modem");
|
||||
state.setFailed();
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -256,7 +251,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
private static class PluginState {
|
||||
private class PluginState {
|
||||
|
||||
@GuardedBy("this")
|
||||
private boolean started = false,
|
||||
@@ -266,18 +261,22 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
|
||||
private synchronized void setStarted() {
|
||||
started = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
private synchronized void setStopped() {
|
||||
stopped = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
private synchronized void setInitialised() {
|
||||
initialised = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
private synchronized void setFailed() {
|
||||
failed = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
private State getState() {
|
||||
|
||||
Reference in New Issue
Block a user