[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Finish making new (v1) controller logic and multiplexing lo...



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

Modified Files:
	Bytes.java PasswordDigest.java TorControlCommands.java 
	TorControlConnection.java TorControlConnection0.java 
	TorControlConnection1.java TorControlError.java 
	TorControlSyntaxError.java 
Log Message:
Finish making new (v1) controller logic and multiplexing logic work in Python and Java controllers. Try out example code a bit.

Index: Bytes.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/Bytes.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Bytes.java	23 Jun 2005 21:22:04 -0000	1.3
+++ Bytes.java	24 Jun 2005 18:03:27 -0000	1.4
@@ -111,3 +111,4 @@
 
     private Bytes() {};
 }
+

Index: PasswordDigest.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/PasswordDigest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- PasswordDigest.java	23 Jun 2005 21:22:04 -0000	1.2
+++ PasswordDigest.java	24 Jun 2005 18:03:27 -0000	1.3
@@ -56,7 +56,6 @@
         return hashedKey;
     }
 
-
     /** Parameter used by RFC2440's s2k algorithm. */
     private static final int EXPBIAS = 6;
 
@@ -100,4 +99,5 @@
         return Bytes.hex(ba);
     }
 
-}
\ No newline at end of file
+}
+

Index: TorControlCommands.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlCommands.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TorControlCommands.java	4 Jun 2005 02:42:55 -0000	1.1
+++ TorControlCommands.java	24 Jun 2005 18:03:27 -0000	1.2
@@ -130,4 +130,5 @@
         "No such OR",
     };
 
-}
\ No newline at end of file
+}
+

Index: TorControlConnection.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlConnection.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- TorControlConnection.java	23 Jun 2005 21:22:04 -0000	1.3
+++ TorControlConnection.java	24 Jun 2005 18:03:27 -0000	1.4
@@ -37,6 +37,41 @@
         }
     }
 
+    protected static int detectVersion(java.io.InputStream input,
+                                       java.io.OutputStream output)
+        throws IOException
+    {
+        java.io.DataInputStream dInput = new java.io.DataInputStream(input);
+        byte out[] = { 0, 0, 13, 10 };
+        output.write(out);
+
+        int len = dInput.readUnsignedShort();
+        int tp = dInput.readUnsignedShort();
+        if (tp == 0) {
+            byte err[] = new byte[len];
+            dInput.readFully(err);
+            return 0;
+        } else if ((len & 0xff00) != 0x0a00 &&
+                   (len & 0x00ff) != 0x000a &&
+                   (tp  & 0xff00) != 0x0a00 &&
+                   (tp  & 0x00ff) != 0x000a) {
+            while (input.read() != '\n')
+                ;
+        }
+        return 1;
+    }
+
+    public static TorControlConnection getConnection(java.net.Socket sock)
+        throws IOException
+    {
+        int version = detectVersion(sock.getInputStream(),
+                                    sock.getOutputStream());
+        if (version == 0)
+            return new TorControlConnection0(sock);
+        else
+            return new TorControlConnection1(sock);
+    }
+
     protected TorControlConnection() {
         this.waiters = new LinkedList();
     }
@@ -71,7 +106,6 @@
 
     protected abstract void react() throws IOException;
 
-
     /** Change the value of the configuration option 'key' to 'val'.
      */
     public void setConf(String key, String value) throws IOException {
@@ -180,3 +214,4 @@
     public abstract void closeCircuit(String circID, boolean ifUnused) throws IOException;
 
 }
+

Index: TorControlConnection0.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlConnection0.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TorControlConnection0.java	23 Jun 2005 21:22:04 -0000	1.2
+++ TorControlConnection0.java	24 Jun 2005 18:03:27 -0000	1.3
@@ -166,7 +166,6 @@
         return sendAndWaitForResponse(type, cmd, CMD_DONE, CMD_DONE, CMD_DONE, CMD_DONE);
     }
 
-
     protected Cmd sendAndWaitForResponse(short type, byte[] cmd, short exType1)
         throws IOException {
         return sendAndWaitForResponse(type, cmd, exType1, exType1, exType1,
@@ -180,7 +179,6 @@
                                       exType2);
     }
 
-
     protected Cmd sendAndWaitForResponse(short type, byte[] cmd,
                                    short exType1, short exType2, short exType3)
         throws IOException {
@@ -250,7 +248,6 @@
         sendAndWaitForResponse(CMD_SETCONF, b.toString().getBytes());
     }
 
-
     public Map getConf(Collection keys) throws IOException {
         StringBuffer s = new StringBuffer();
         for (Iterator it = keys.iterator(); it.hasNext(); ) {
@@ -360,7 +357,7 @@
         return Integer.toString(Bytes.getU32(c.body, 0));
     }
 
-    public void attachStream(String streamID, String circID) 
+    public void attachStream(String streamID, String circID)
         throws IOException {
         byte[] ba = new byte[8];
         Bytes.setU32(ba, 0, (int)Long.parseLong(streamID));
@@ -406,3 +403,4 @@
     }
 
 }
+

Index: TorControlConnection1.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlConnection1.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TorControlConnection1.java	23 Jun 2005 21:22:04 -0000	1.1
+++ TorControlConnection1.java	24 Jun 2005 18:03:27 -0000	1.2
@@ -120,7 +120,6 @@
         return reply;
     }
 
-
     /** helper: implement the main background loop. */
     protected void react() throws IOException {
         while (true) {
@@ -142,6 +141,7 @@
         Waiter w = new Waiter();
         synchronized (waiters) {
             output.write(s);
+            output.flush();
             if (rest != null)
                 writeEscaped(rest);
             waiters.addLast(w);
@@ -227,7 +227,7 @@
         ArrayList lst = sendAndWaitForResponse(sb.toString(), null);
         Map result = new HashMap();
         for (Iterator it = lst.iterator(); it.hasNext(); ) {
-            String kv = (String) it.next();
+            String kv = ((ReplyLine) it.next()).msg;
             int idx = kv.indexOf('=');
             result.put(kv.substring(0, idx),
                        kv.substring(idx+1));
@@ -344,3 +344,4 @@
     }
 
 }
+

Index: TorControlError.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlError.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TorControlError.java	23 Jun 2005 21:22:04 -0000	1.2
+++ TorControlError.java	24 Jun 2005 18:03:27 -0000	1.3
@@ -27,4 +27,5 @@
             return "Unrecongized error #"+errorType;
         }
     }
-}
\ No newline at end of file
+}
+

Index: TorControlSyntaxError.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlSyntaxError.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TorControlSyntaxError.java	4 Jun 2005 02:42:55 -0000	1.1
+++ TorControlSyntaxError.java	24 Jun 2005 18:03:27 -0000	1.2
@@ -5,4 +5,5 @@
  */
 public class TorControlSyntaxError extends RuntimeException {
     public TorControlSyntaxError(String s) { super(s); }
-}
\ No newline at end of file
+}
+