mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Merge branch 'tor-state-enabling-when-zero-onion-router-connections' into 'master'
Fix OR connection counts, set Tor status to ENABLING when not connected to any ORs See merge request briar/briar!1646
This commit is contained in:
@@ -746,18 +746,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
public void orConnStatus(String status, String orName) {
|
public void orConnStatus(String status, String orName) {
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
|
if (LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
|
||||||
|
|
||||||
//noinspection IfCanBeSwitch
|
if (status.equals("CONNECTED")) state.onOrConnectionConnected();
|
||||||
if (status.equals("LAUNCHED")) state.onOrConnectionLaunched();
|
|
||||||
else if (status.equals("FAILED")) state.onOrConnectionFailed();
|
|
||||||
else if (status.equals("CONNECTED")) state.onOrConnectionConnected();
|
|
||||||
else if (status.equals("CLOSED")) state.onOrConnectionClosed();
|
else if (status.equals("CLOSED")) state.onOrConnectionClosed();
|
||||||
|
|
||||||
if ((status.equals("FAILED") || status.equals("CLOSED")) &&
|
|
||||||
state.getNumOrConnections() == 0) {
|
|
||||||
// Check whether we've lost connectivity
|
|
||||||
updateConnectionStatus(networkManager.getNetworkStatus(),
|
|
||||||
batteryManager.isCharging());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -771,9 +761,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void message(String severity, String msg) {
|
public void message(String severity, String msg) {
|
||||||
if (LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
|
if (LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
|
||||||
if (msg.startsWith("Switching to guard context")) {
|
|
||||||
state.onSwitchingGuardContext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -855,11 +842,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
if (s.getNamespace().equals(ID.getString())) {
|
if (s.getNamespace().equals(ID.getString())) {
|
||||||
LOG.info("Tor settings updated");
|
LOG.info("Tor settings updated");
|
||||||
settings = s.getSettings();
|
settings = s.getSettings();
|
||||||
// Works around a bug introduced in Tor 0.3.4.8.
|
|
||||||
// https://trac.torproject.org/projects/tor/ticket/28027
|
|
||||||
// Could be replaced with callback.transportDisabled()
|
|
||||||
// when fixed.
|
|
||||||
disableNetwork();
|
|
||||||
updateConnectionStatus(networkManager.getNetworkStatus(),
|
updateConnectionStatus(networkManager.getNetworkStatus(),
|
||||||
batteryManager.isCharging());
|
batteryManager.isCharging());
|
||||||
}
|
}
|
||||||
@@ -872,16 +854,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableNetwork() {
|
|
||||||
connectionStatusExecutor.execute(() -> {
|
|
||||||
try {
|
|
||||||
if (state.isTorRunning()) enableNetwork(false);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
logException(LOG, WARNING, ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateConnectionStatus(NetworkStatus status,
|
private void updateConnectionStatus(NetworkStatus status,
|
||||||
boolean charging) {
|
boolean charging) {
|
||||||
connectionStatusExecutor.execute(() -> {
|
connectionStatusExecutor.execute(() -> {
|
||||||
@@ -1007,13 +979,14 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
private ServerSocket serverSocket = null;
|
private ServerSocket serverSocket = null;
|
||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private int orConnectionsPending = 0, orConnectionsConnected = 0;
|
private int orConnectionsConnected = 0;
|
||||||
|
|
||||||
private synchronized void setStarted() {
|
private synchronized void setStarted() {
|
||||||
started = true;
|
started = true;
|
||||||
callback.pluginStateChanged(getState());
|
callback.pluginStateChanged(getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
private synchronized boolean isTorRunning() {
|
private synchronized boolean isTorRunning() {
|
||||||
return started && !stopped;
|
return started && !stopped;
|
||||||
}
|
}
|
||||||
@@ -1071,63 +1044,38 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
if (reasonsDisabled != 0) return DISABLED;
|
if (reasonsDisabled != 0) return DISABLED;
|
||||||
if (!networkInitialised) return ENABLING;
|
if (!networkInitialised) return ENABLING;
|
||||||
if (!networkEnabled) return INACTIVE;
|
if (!networkEnabled) return INACTIVE;
|
||||||
return bootstrapped && circuitBuilt ? ACTIVE : ENABLING;
|
return bootstrapped && circuitBuilt && orConnectionsConnected > 0
|
||||||
|
? ACTIVE : ENABLING;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized int getReasonsDisabled() {
|
private synchronized int getReasonsDisabled() {
|
||||||
return getState() == DISABLED ? reasonsDisabled : 0;
|
return getState() == DISABLED ? reasonsDisabled : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void onOrConnectionLaunched() {
|
|
||||||
orConnectionsPending++;
|
|
||||||
logOrConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void onOrConnectionFailed() {
|
|
||||||
orConnectionsPending--;
|
|
||||||
if (orConnectionsPending < 0) {
|
|
||||||
LOG.warning("Count was zero before connection failed");
|
|
||||||
orConnectionsPending = 0;
|
|
||||||
}
|
|
||||||
logOrConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void onOrConnectionConnected() {
|
private synchronized void onOrConnectionConnected() {
|
||||||
orConnectionsPending--;
|
int oldConnected = orConnectionsConnected;
|
||||||
if (orConnectionsPending < 0) {
|
|
||||||
LOG.warning("Count was zero before connection connected");
|
|
||||||
orConnectionsPending = 0;
|
|
||||||
}
|
|
||||||
orConnectionsConnected++;
|
orConnectionsConnected++;
|
||||||
logOrConnections();
|
logOrConnections();
|
||||||
|
if (oldConnected == 0) callback.pluginStateChanged(getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void onOrConnectionClosed() {
|
private synchronized void onOrConnectionClosed() {
|
||||||
|
int oldConnected = orConnectionsConnected;
|
||||||
orConnectionsConnected--;
|
orConnectionsConnected--;
|
||||||
if (orConnectionsConnected < 0) {
|
if (orConnectionsConnected < 0) {
|
||||||
LOG.warning("Count was zero before connection closed");
|
LOG.warning("Count was zero before connection closed");
|
||||||
orConnectionsConnected = 0;
|
orConnectionsConnected = 0;
|
||||||
}
|
}
|
||||||
logOrConnections();
|
logOrConnections();
|
||||||
}
|
if (orConnectionsConnected == 0 && oldConnected != 0) {
|
||||||
|
callback.pluginStateChanged(getState());
|
||||||
private synchronized void onSwitchingGuardContext() {
|
}
|
||||||
// Tor doesn't seem to report events for connections belonging to
|
|
||||||
// the old guard context, so we have to reset the counters
|
|
||||||
orConnectionsPending = 0;
|
|
||||||
orConnectionsConnected = 0;
|
|
||||||
logOrConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized int getNumOrConnections() {
|
|
||||||
return orConnectionsPending + orConnectionsConnected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private void logOrConnections() {
|
private void logOrConnections() {
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info("OR connections: " + orConnectionsPending
|
LOG.info(orConnectionsConnected + "OR connections connected");
|
||||||
+ " pending, " + orConnectionsConnected + " connected");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user