mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Move to enabling state earlier in Tor startup.
This commit is contained in:
@@ -75,7 +75,7 @@ class AndroidTorPlugin extends TorPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enableNetwork(boolean enable) throws IOException {
|
protected void enableNetwork(boolean enable) throws IOException {
|
||||||
if (!state.isRunning()) return;
|
if (!state.isTorRunning()) return;
|
||||||
if (enable) wakeLock.acquire();
|
if (enable) wakeLock.acquire();
|
||||||
super.enableNetwork(enable);
|
super.enableNetwork(enable);
|
||||||
if (!enable) wakeLock.release();
|
if (!enable) wakeLock.release();
|
||||||
|
|||||||
@@ -193,6 +193,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
@Override
|
@Override
|
||||||
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();
|
||||||
|
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.");
|
||||||
@@ -280,8 +282,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PluginException(e);
|
throw new PluginException(e);
|
||||||
}
|
}
|
||||||
state.setStarted();
|
state.setTorStarted();
|
||||||
callback.pluginStateChanged(getState());
|
|
||||||
// Check whether we're online
|
// Check whether we're online
|
||||||
updateConnectionStatus(networkManager.getNetworkStatus(),
|
updateConnectionStatus(networkManager.getNetworkStatus(),
|
||||||
batteryManager.isCharging());
|
batteryManager.isCharging());
|
||||||
@@ -423,7 +424,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void publishHiddenService(String port) {
|
private void publishHiddenService(String port) {
|
||||||
if (!state.isRunning()) return;
|
if (!state.isTorRunning()) return;
|
||||||
LOG.info("Creating hidden service");
|
LOG.info("Creating hidden service");
|
||||||
String privKey = settings.get(HS_PRIVKEY);
|
String privKey = settings.get(HS_PRIVKEY);
|
||||||
Map<Integer, String> portLines = singletonMap(80, "127.0.0.1:" + port);
|
Map<Integer, String> portLines = singletonMap(80, "127.0.0.1:" + port);
|
||||||
@@ -479,7 +480,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void enableNetwork(boolean enable) throws IOException {
|
protected void enableNetwork(boolean enable) throws IOException {
|
||||||
if (!state.isRunning()) return;
|
if (!state.isTorRunning()) return;
|
||||||
state.enableNetwork(enable);
|
state.enableNetwork(enable);
|
||||||
callback.pluginStateChanged(getState());
|
callback.pluginStateChanged(getState());
|
||||||
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
||||||
@@ -763,7 +764,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
private void updateConnectionStatus(NetworkStatus status,
|
private void updateConnectionStatus(NetworkStatus status,
|
||||||
boolean charging) {
|
boolean charging) {
|
||||||
connectionStatusExecutor.execute(() -> {
|
connectionStatusExecutor.execute(() -> {
|
||||||
if (!state.isRunning()) return;
|
if (!state.isTorRunning()) return;
|
||||||
NetworkConfig config = getNetworkConfig(status, charging);
|
NetworkConfig config = getNetworkConfig(status, charging);
|
||||||
state.setDisabledBySettings(config.disabledBySettings,
|
state.setDisabledBySettings(config.disabledBySettings,
|
||||||
config.reasonDisabled);
|
config.reasonDisabled);
|
||||||
@@ -856,7 +857,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enableConnectionPadding(boolean enable) throws IOException {
|
private void enableConnectionPadding(boolean enable) throws IOException {
|
||||||
if (!state.isRunning()) return;
|
if (!state.isTorRunning()) return;
|
||||||
controlConnection.setConf("ConnectionPadding", enable ? "1" : "0");
|
controlConnection.setConf("ConnectionPadding", enable ? "1" : "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -887,6 +888,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private boolean started = false,
|
private boolean started = false,
|
||||||
stopped = false,
|
stopped = false,
|
||||||
|
torStarted = false,
|
||||||
networkInitialised = false,
|
networkInitialised = false,
|
||||||
networkEnabled = false,
|
networkEnabled = false,
|
||||||
bootstrapped = false,
|
bootstrapped = false,
|
||||||
@@ -904,8 +906,13 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized boolean isRunning() {
|
synchronized void setTorStarted() {
|
||||||
return started && !stopped;
|
torStarted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
|
synchronized boolean isTorRunning() {
|
||||||
|
return torStarted && !stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
Reference in New Issue
Block a user