mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 15:49:53 +01:00
Consider Tor to have started when it's bootstrapped and built a circuit.
This commit is contained in:
@@ -81,9 +81,10 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
private final long maxLatency, pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
private final File torDirectory, torFile, geoIpFile, configFile, doneFile;
|
private final File torDirectory, torFile, geoIpFile, configFile, doneFile;
|
||||||
private final File cookieFile, pidFile, hostnameFile;
|
private final File cookieFile, pidFile, hostnameFile;
|
||||||
private final AtomicBoolean firstCircuit;
|
private final AtomicBoolean circuitBuilt;
|
||||||
|
|
||||||
private volatile boolean running = false, networkEnabled = false;
|
private volatile boolean running = false, networkEnabled = false;
|
||||||
|
private volatile boolean bootstrapped = false;
|
||||||
private volatile Process tor = null;
|
private volatile Process tor = null;
|
||||||
private volatile int pid = -1;
|
private volatile int pid = -1;
|
||||||
private volatile ServerSocket socket = null;
|
private volatile ServerSocket socket = null;
|
||||||
@@ -111,7 +112,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
cookieFile = new File(torDirectory, ".tor/control_auth_cookie");
|
cookieFile = new File(torDirectory, ".tor/control_auth_cookie");
|
||||||
pidFile = new File(torDirectory, ".tor/pid");
|
pidFile = new File(torDirectory, ".tor/pid");
|
||||||
hostnameFile = new File(torDirectory, "hostname");
|
hostnameFile = new File(torDirectory, "hostname");
|
||||||
firstCircuit = new AtomicBoolean(true);
|
circuitBuilt = new AtomicBoolean(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
@@ -133,9 +134,12 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
|
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
|
||||||
LOG.info("Tor is already running");
|
LOG.info("Tor is already running");
|
||||||
if(readPidFile() == -1) {
|
if(readPidFile() == -1) {
|
||||||
|
LOG.info("Could not read PID of Tor process");
|
||||||
controlSocket.close();
|
controlSocket.close();
|
||||||
killZombieProcess();
|
killZombieProcess();
|
||||||
startProcess = true;
|
startProcess = true;
|
||||||
|
} else {
|
||||||
|
bootstrapped = true;
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
LOG.info("Tor is not running");
|
LOG.info("Tor is not running");
|
||||||
@@ -548,9 +552,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
private void enableNetwork(boolean enable) throws IOException {
|
private void enableNetwork(boolean enable) throws IOException {
|
||||||
if(!running) return;
|
if(!running) return;
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Enabling network: " + enable);
|
if(LOG.isLoggable(INFO)) LOG.info("Enabling network: " + enable);
|
||||||
if(!enable) firstCircuit.set(true);
|
if(!enable) circuitBuilt.set(false);
|
||||||
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
|
||||||
networkEnabled = enable;
|
networkEnabled = enable;
|
||||||
|
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() throws IOException {
|
public void stop() throws IOException {
|
||||||
@@ -577,7 +581,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return running && networkEnabled;
|
return running && networkEnabled && bootstrapped && circuitBuilt.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldPoll() {
|
public boolean shouldPoll() {
|
||||||
@@ -648,9 +652,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
if(!path.isEmpty()) msg += ", path: " + shortenPath(path);
|
if(!path.isEmpty()) msg += ", path: " + shortenPath(path);
|
||||||
LOG.info(msg);
|
LOG.info(msg);
|
||||||
}
|
}
|
||||||
if("BUILT".equals(status) && firstCircuit.getAndSet(false)) {
|
if(status.equals("BUILT") && !circuitBuilt.getAndSet(true)) {
|
||||||
LOG.info("First circuit built");
|
LOG.info("First circuit built");
|
||||||
callback.pollNow();
|
if(isRunning()) callback.pollNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -675,6 +679,10 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
|
|
||||||
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(severity.equals("NOTICE") && msg.startsWith("Bootstrapped 100%")) {
|
||||||
|
bootstrapped = true;
|
||||||
|
if(isRunning()) callback.pollNow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unrecognized(String type, String msg) {
|
public void unrecognized(String type, String msg) {
|
||||||
@@ -690,6 +698,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
this.latch = latch;
|
this.latch = latch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onEvent(int event, String path) {
|
public void onEvent(int event, String path) {
|
||||||
stopWatching();
|
stopWatching();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
|||||||
Reference in New Issue
Block a user