[or-cvs] Add a new (untested) set of debugging functions

Nick Mathewson nickm at seul.org
Wed Jul 20 22:31:00 UTC 2005


Update of /home/or/cvsroot/control/java/net/freehaven/tor/control
In directory moria:/tmp/cvs-serv10986/java/net/freehaven/tor/control

Modified Files:
	TorControlConnection1.java 
Log Message:
Add a new (untested) set of debugging functions

Index: TorControlConnection1.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlConnection1.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- TorControlConnection1.java	14 Jul 2005 20:26:11 -0000	1.4
+++ TorControlConnection1.java	20 Jul 2005 22:30:58 -0000	1.5
@@ -19,6 +19,7 @@
 {
     protected java.io.BufferedReader input;
     protected java.io.Writer output;
+    protected java.io.PrintWriter debugOutput;
 
     static class ReplyLine {
         public String status;
@@ -63,12 +64,14 @@
         while (st.hasMoreTokens()) {
             String line = st.nextToken();
             if (line.startsWith("."))
-                output.write(".");
-            output.write(line);
+                line = "."+line;
             if (line.endsWith("\r"))
-                output.write("\n");
+                line += "\n";
             else
-                output.write("\r\n");
+                line += "\r\n";
+            if (debugOutput != null)
+                debugOutput.print("<< "+line);
+            output.write(line);
         }
         output.write(".\r\n");
     }
@@ -96,8 +99,10 @@
         char c;
         do {
             String line = input.readLine();
+            if (debugOutput != null)
+                debugOutput.print(">> "+line);
             if (line.length() < 4)
-                throw new TorControlSyntaxError("Line too short");
+                throw new TorControlSyntaxError("Line (\""+line+"\") too short");
             String status = line.substring(0,3);
             c = line.charAt(3);
             String msg = line.substring(4);
@@ -106,6 +111,8 @@
                 StringBuffer data = new StringBuffer();
                 while (true) {
                     line = input.readLine();
+                    if (debugOutput != null)
+                        debugOutput.print(">> "+line);
                     if (line.equals("."))
                         break;
                     else if (line.startsWith("."))
@@ -140,6 +147,8 @@
         throws IOException {
         checkThread();
         Waiter w = new Waiter();
+        if (debugOutput != null)
+            debugOutput.println("<< "+s);
         synchronized (waiters) {
             output.write(s);
             output.flush();
@@ -218,6 +227,16 @@
         sendAndWaitForResponse(b.toString(), null);
     }
 
+    public void setDebugging(java.io.PrintWriter w) {
+        if (w instanceof java.io.PrintWriter)
+            debugOutput = (java.io.PrintWriter) w;
+        else
+            debugOutput = new java.io.PrintWriter(w);
+    }
+    public void setDebugging(java.io.PrintStream s) {
+        debugOutput = new java.io.PrintWriter(s);
+    }
+
     public List getConf(Collection keys) throws IOException {
         StringBuffer sb = new StringBuffer("GETCONF");
         for (Iterator it = keys.iterator(); it.hasNext(); ) {



More information about the tor-commits mailing list