Skip to content
Snippets Groups Projects
Commit 2d7aff42 authored by Nick Mathewson's avatar Nick Mathewson :family:
Browse files

fix debugging and listenforevents API a little

parent 23e3c558
No related branches found
Tags tbb-8.0.1-build2
No related merge requests found
......@@ -65,6 +65,21 @@ public interface TorControlCommands {
public static final short EVENT_MSG_WARN = 0x000A;
public static final short EVENT_MSG_ERROR = 0x000B;
public static final String[] EVENT_NAMES = {
"(0)",
"CIRC",
"STREAM",
"ORCONN",
"BW",
"OLDLOG",
"NEWDESC",
"DEBUG",
"INFO",
"NOTICE",
"WARN",
"ERR",
};
public static final byte CIRC_STATUS_LAUNCHED = 0x01;
public static final byte CIRC_STATUS_BUILT = 0x02;
public static final byte CIRC_STATUS_EXTENDED = 0x03;
......
......@@ -70,10 +70,12 @@ public class TorControlConnection1 extends TorControlConnection
else
line += "\r\n";
if (debugOutput != null)
debugOutput.print("<< "+line);
debugOutput.print(">> "+line);
output.write(line);
}
output.write(".\r\n");
if (debugOutput != null)
debugOutput.print(">> .\n");
}
protected static final String quote(String s) {
......@@ -100,7 +102,7 @@ public class TorControlConnection1 extends TorControlConnection
do {
String line = input.readLine();
if (debugOutput != null)
debugOutput.print(">> "+line);
debugOutput.println("<< "+line);
if (line.length() < 4)
throw new TorControlSyntaxError("Line (\""+line+"\") too short");
String status = line.substring(0,3);
......@@ -112,7 +114,7 @@ public class TorControlConnection1 extends TorControlConnection
while (true) {
line = input.readLine();
if (debugOutput != null)
debugOutput.print(">> "+line);
debugOutput.print("<< "+line);
if (line.equals("."))
break;
else if (line.startsWith("."))
......@@ -148,7 +150,7 @@ public class TorControlConnection1 extends TorControlConnection
checkThread();
Waiter w = new Waiter();
if (debugOutput != null)
debugOutput.println("<< "+s);
debugOutput.print(">> "+s);
synchronized (waiters) {
output.write(s);
output.flush();
......@@ -231,10 +233,10 @@ public class TorControlConnection1 extends TorControlConnection
if (w instanceof java.io.PrintWriter)
debugOutput = (java.io.PrintWriter) w;
else
debugOutput = new java.io.PrintWriter(w);
debugOutput = new java.io.PrintWriter(w, true);
}
public void setDebugging(java.io.PrintStream s) {
debugOutput = new java.io.PrintWriter(s);
debugOutput = new java.io.PrintWriter(s, true);
}
public List getConf(Collection keys) throws IOException {
......@@ -258,8 +260,13 @@ public class TorControlConnection1 extends TorControlConnection
public void setEvents(List events) throws IOException {
StringBuffer sb = new StringBuffer("SETEVENTS");
for (Iterator it = events.iterator(); it.hasNext(); ) {
String event = (String) it.next();
sb.append(" ").append(event);
Object event = it.next();
if (event instanceof String) {
sb.append(" ").append((String)event);
} else {
int i = ((Number) event).intValue();
sb.append(" ").append(EVENT_NAMES[i]);
}
}
sb.append("\r\n");
sendAndWaitForResponse(sb.toString(), null);
......
......@@ -52,6 +52,10 @@ public class Main implements TorControlCommands {
throws IOException {
TorControlConnection conn = TorControlConnection.getConnection(
new java.net.Socket("127.0.0.1", 9100));
if (conn instanceof TorControlConnection1) {
System.err.println("Debugging");
((TorControlConnection1)conn).setDebugging(System.err);
}
Thread th = conn.launchThread(daemon);
conn.authenticate(new byte[0]);
return conn;
......
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