Skip to content
Snippets Groups Projects
Commit 5ea0cce2 authored by akwizgran's avatar akwizgran
Browse files

Tell Tor to shut down when control socket is closed; more Tor logging.

Patched jtorctl to pass more information about circuit events to the
controller to help us debug connection problems.
parent 458d52e7
No related branches found
No related tags found
Loading
No preview for this file type
......@@ -61,7 +61,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
static final TransportId ID = new TransportId("tor");
private static final String[] EVENTS = {
"CIRC", "STREAM", "ORCONN", "NOTICE", "WARN", "ERR"
"CIRC", "ORCONN", "NOTICE", "WARN", "ERR"
};
private static final int SOCKS_PORT = 59050, CONTROL_PORT = 59051;
private static final int COOKIE_TIMEOUT = 3000; // Milliseconds
......@@ -210,6 +210,8 @@ class TorPlugin implements DuplexPlugin, EventHandler {
// Open a control connection and authenticate using the cookie file
controlConnection = new TorControlConnection(controlSocket);
controlConnection.authenticate(read(cookieFile));
// Tell Tor to exit when the control connection is closed
controlConnection.takeOwnership();
// Register to receive events from the Tor process
controlConnection.setEventHandler(this);
controlConnection.setEvents(Arrays.asList(EVENTS));
......@@ -632,10 +634,14 @@ class TorPlugin implements DuplexPlugin, EventHandler {
throw new UnsupportedOperationException();
}
public void circuitStatus(String status, String id, String path) {
public void circuitStatus(String status, String id, String path,
String flags, String purpose, String hsState) {
if(LOG.isLoggable(INFO)) {
if(!"EXTENDED".equals(status))
LOG.info("Circuit " + id + " " + status);
String msg = "Circuit " + id + " " + status;
if(flags.length() > 0) msg += ", flags: " + flags;
if(purpose.length() > 0) msg += ", purpose: " + purpose;
if(hsState.length() > 0) msg += ", state: " + hsState;
LOG.info(msg);
}
if("BUILT".equals(status) && firstCircuit.getAndSet(false)) {
LOG.info("First circuit built");
......@@ -643,9 +649,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
}
}
public void streamStatus(String status, String id, String target) {
if(LOG.isLoggable(INFO)) LOG.info("Stream " + id + " " + status);
}
public void streamStatus(String status, String id, String target) {}
public void orConnStatus(String status, String orName) {
if(LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
......@@ -659,7 +663,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
if(LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
}
public void unrecognized(String type, String msg) {}
public void unrecognized(String type, String msg) {
if(LOG.isLoggable(INFO)) LOG.info(type + " " + msg);
}
private static class WriteObserver extends FileObserver {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment