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