diff --git a/jtorctl.patch b/jtorctl.patch index cc027d633cae0a8fabf05922bc3bdf346d5b0977..b1f32cb776c1ebaf6fa8bbd61f8a3e590d0f5a12 100644 --- a/jtorctl.patch +++ b/jtorctl.patch @@ -1,3 +1,25 @@ +diff -Bbur jtorctl/net/freehaven/tor/control/EventHandler.java jtorctl-briar/net/freehaven/tor/control/EventHandler.java +--- jtorctl/net/freehaven/tor/control/EventHandler.java 2014-04-02 11:26:56.000000000 +0100 ++++ jtorctl-briar/net/freehaven/tor/control/EventHandler.java 2014-05-14 14:30:46.932545643 +0100 +@@ -20,10 +20,15 @@ + * <li>"CLOSED" : circuit closed (was built)</li> + * </ul> + * +- * <b>circID</b> is the alphanumeric identifier of the affected circuit, +- * and <b>path</b> is a comma-separated list of alphanumeric ServerIDs. ++ * <b>circID</b> is the alphanumeric identifier of the affected circuit. ++ * <b>path</b> is a comma-separated list of alphanumeric ServerIDs. ++ * <b>flags</b> is a comma-separated list of the circuit's build flags. ++ * <b>purpose</b> describes the purpose of the circuit. ++ * <b>hsState</b> describes the state of the circuit if it is a hidden ++ * service circuit. + */ +- public void circuitStatus(String status, String circID, String path); ++ public void circuitStatus(String status, String circID, String path, ++ String flags, String purpose, String hsState); + /** + * Invoked when a stream's status has changed. + * Possible values for <b>status</b> are: diff -Bbur jtorctl/net/freehaven/tor/control/examples/DebuggingEventHandler.java jtorctl-briar/net/freehaven/tor/control/examples/DebuggingEventHandler.java --- jtorctl/net/freehaven/tor/control/examples/DebuggingEventHandler.java 2014-04-02 11:26:56.000000000 +0100 +++ jtorctl-briar/net/freehaven/tor/control/examples/DebuggingEventHandler.java 2014-04-02 11:31:48.000000000 +0100 @@ -151,6 +173,19 @@ diff -Bbur jtorctl/net/freehaven/tor/control/examples/Main.java jtorctl-briar/ne conn.launchThread(true); conn.authenticate(pwd.getSecret()); } +diff -Bbur jtorctl/net/freehaven/tor/control/NullEventHandler.java jtorctl-briar/net/freehaven/tor/control/NullEventHandler.java +--- jtorctl/net/freehaven/tor/control/NullEventHandler.java 2014-04-02 11:26:56.000000000 +0100 ++++ jtorctl-briar/net/freehaven/tor/control/NullEventHandler.java 2014-05-14 14:33:04.821229388 +0100 +@@ -7,7 +7,8 @@ + * when you only want to override one method. + */ + public class NullEventHandler implements EventHandler { +- public void circuitStatus(String status, String circID, String path) {} ++ public void circuitStatus(String status, String circID, String path, ++ String flags, String purpose, String hsState) {} + public void streamStatus(String status, String streamID, String target) {} + public void orConnStatus(String status, String orName) {} + public void bandwidthUsed(long read, long written) {} diff -Bbur jtorctl/net/freehaven/tor/control/PasswordDigest.java jtorctl-briar/net/freehaven/tor/control/PasswordDigest.java --- jtorctl/net/freehaven/tor/control/PasswordDigest.java 2014-04-02 11:26:56.000000000 +0100 +++ jtorctl-briar/net/freehaven/tor/control/PasswordDigest.java 2014-04-02 12:29:20.000000000 +0100 @@ -206,7 +241,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/PasswordDigest.java jtorctl-briar/n diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-briar/net/freehaven/tor/control/TorControlConnection.java --- jtorctl/net/freehaven/tor/control/TorControlConnection.java 2014-04-02 11:26:56.000000000 +0100 -+++ jtorctl-briar/net/freehaven/tor/control/TorControlConnection.java 2014-04-02 12:29:34.000000000 +0100 ++++ jtorctl-briar/net/freehaven/tor/control/TorControlConnection.java 2014-05-14 15:25:20.908780406 +0100 @@ -2,96 +2,93 @@ // See LICENSE file for copying information package net.freehaven.tor.control; @@ -294,18 +329,18 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b ReplyLine(String status, String msg, String rest) { - this.status = status; this.msg = msg; this.rest = rest; -- } + this.status = status; + this.msg = msg; + this.rest = rest; + } } -- + - public static TorControlConnection getConnection(java.net.Socket sock) - throws IOException - { - return new TorControlConnection(sock); - } - +- } +- /** Create a new TorControlConnection to communicate with Tor over * a given socket. After calling this constructor, it is typical to * call launchThread and authenticate. */ @@ -389,11 +424,11 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b - throws IOException { + private synchronized List<ReplyLine> sendAndWaitForResponse(String s, + String rest) throws IOException { -+ if(parseThreadException != null) throw parseThreadException; ++ if (parseThreadException != null) throw parseThreadException; checkThread(); Waiter w = new Waiter(); if (debugOutput != null) -@@ -185,38 +182,38 @@ +@@ -185,38 +182,55 @@ output.flush(); waiters.addLast(w); } @@ -426,19 +461,36 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b - ReplyLine line = i.next(); + for (ReplyLine line : events) { int idx = line.msg.indexOf(' '); ++ if (idx == -1) ++ continue; String tp = line.msg.substring(0, idx).toUpperCase(); String rest = line.msg.substring(idx+1); if (tp.equals("CIRC")) { ++ String path = "", flags = "", purpose = "", hsState = ""; List<String> lst = Bytes.splitStr(null, rest); - handler.circuitStatus(lst.get(1), - lst.get(0), - lst.get(1).equals("LAUNCHED") - || lst.size() < 2 ? "" - : lst.get(2)); -+ String path; -+ if (lst.get(1).equals("LAUNCHED") || lst.size() < 3) path = ""; -+ else path = lst.get(2); -+ handler.circuitStatus(lst.get(1), lst.get(0), path); ++ for(int i = 2; i < lst.size(); i++) { ++ String arg = lst.get(i); ++ idx = arg.indexOf('='); ++ if (idx == -1) { ++ path = arg; ++ } else { ++ String key = arg.substring(0, idx).toUpperCase(); ++ String value = arg.substring(idx+1); ++ if (key.equals("BUILDFLAGS")) ++ flags = value; ++ else if (key.equals("PURPOSE")) ++ purpose = value; ++ else if (key.equals("HS_STATE")) ++ hsState = value; ++ } ++ } ++ handler.circuitStatus(lst.get(1), lst.get(0), path, flags, ++ purpose, hsState); } else if (tp.equals("STREAM")) { List<String> lst = Bytes.splitStr(null, rest); - handler.streamStatus(lst.get(1), @@ -448,7 +500,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b // XXXX circID. } else if (tp.equals("ORCONN")) { List<String> lst = Bytes.splitStr(null, rest); -@@ -240,23 +237,22 @@ +@@ -240,23 +254,22 @@ } } @@ -479,7 +531,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b } /** Set the EventHandler object that will be notified of any -@@ -271,50 +267,43 @@ +@@ -271,50 +284,43 @@ * This is necessary to handle asynchronous events and synchronous * responses that arrive independantly over the same socket. */ @@ -508,12 +560,12 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b - throw new RuntimeException(ex); } catch (IOException ex) { - throw new RuntimeException(ex); +- } + parseThreadException = ex; - } } - public void stopListening() { - this.stopped = true; -- } + } } - protected final void checkThread() { @@ -539,7 +591,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b Waiter w; synchronized (waiters) { w = waiters.removeFirst(); -@@ -324,20 +313,16 @@ +@@ -324,20 +330,16 @@ } } @@ -564,7 +616,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b } setConf(lst); } -@@ -345,34 +330,33 @@ +@@ -345,34 +347,33 @@ /** Changes the values of the configuration options stored in * <b>kvList</b>. Each list element in <b>kvList</b> is expected to be * String of the format "key value". @@ -606,7 +658,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b } b.append("\r\n"); sendAndWaitForResponse(b.toString(), null); -@@ -384,9 +368,8 @@ +@@ -384,9 +385,8 @@ public void resetConf(Collection<String> keys) throws IOException { if (keys.size() == 0) return; @@ -618,7 +670,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b b.append(" ").append(key); } b.append("\r\n"); -@@ -402,10 +385,10 @@ +@@ -402,10 +402,10 @@ /** Requests the values of the configuration variables listed in <b>keys</b>. * Results are returned as a list of ConfigEntry objects. @@ -631,7 +683,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b * Some options are context-sensitive, and depend on other options with * different keywords. These cannot be fetched directly. Currently there * is only one such option: clients should use the "HiddenServiceOptions" -@@ -413,23 +396,24 @@ +@@ -413,61 +413,63 @@ * HiddenServiceNodes, and HiddenServiceExcludeNodes option settings. */ public List<ConfigEntry> getConf(Collection<String> keys) throws IOException { @@ -665,11 +717,13 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b return result; } -@@ -437,37 +421,38 @@ + /** Request that the server inform the client about interesting events. * Each element of <b>events</b> is one of the following Strings: - * ["CIRC" | "STREAM" | "ORCONN" | "BW" | "DEBUG" | - * "INFO" | "NOTICE" | "WARN" | "ERR" | "NEWDESC" | "ADDRMAP"] . +- * ["CIRC" | "STREAM" | "ORCONN" | "BW" | "DEBUG" | +- * "INFO" | "NOTICE" | "WARN" | "ERR" | "NEWDESC" | "ADDRMAP"] . - * ++ * ["CIRC" | "STREAM" | "ORCONN" | "BW" | "DEBUG" | "INFO" | "NOTICE" | ++ * "WARN" | "ERR" | "NEWDESC" | "ADDRMAP"] . + * <p> * Any events not listed in the <b>events</b> are turned off; thus, calling * setEvents with an empty <b>events</b> argument turns off all event reporting. @@ -713,7 +767,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b * To authenticate under this scheme, the controller sends Tor the original * secret that was used to generate the password. */ -@@ -505,9 +490,6 @@ +@@ -505,9 +507,6 @@ Waiter w = new Waiter(); if (debugOutput != null) debugOutput.print(">> "+s); @@ -723,7 +777,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b synchronized (waiters) { output.write(s); output.flush(); -@@ -519,7 +501,7 @@ +@@ -519,7 +518,7 @@ * addresses should be replaced with connections to the specified replacement * addresses. Each element of <b>kvLines</b> is a String of the form * "old-address new-address". This function returns the new address mapping. @@ -732,7 +786,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b * The client may decline to provide a body for the original address, and * instead send a special null address ("0.0.0.0" for IPv4, "::0" for IPv6, or * "." for hostname), signifying that the server should choose the original -@@ -527,56 +509,52 @@ +@@ -527,56 +526,52 @@ * should ensure that it returns an element of address space that is unlikely * to be in actual use. If there is already an address mapped to the * destination address, the server may reuse that mapping. @@ -802,7 +856,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b * Recognized keys include: * <ul> * <li>"version" : The version of the server's software, including the name -@@ -605,15 +583,14 @@ +@@ -605,17 +600,16 @@ * </ul> */ public Map<String,String> getInfo(Collection<String> keys) throws IOException { @@ -820,9 +874,12 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b - ReplyLine line = it.next(); + for (ReplyLine line : lst) { int idx = line.msg.indexOf('='); - if (idx<0) +- if (idx<0) ++ if (idx == -1) break; -@@ -629,13 +606,9 @@ + String k = line.msg.substring(0,idx); + String v; +@@ -629,13 +623,9 @@ return m; } @@ -838,7 +895,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b return m.get(key); } -@@ -644,40 +617,39 @@ +@@ -644,40 +634,39 @@ * to the specified path, or the <b>circID</b> is nonzero, in which case it is a * request for the server to extend an existing circuit with that ID according * to the specified <b>path</b>. @@ -886,7 +943,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b * The descriptor, when parsed, must contain a number of well-specified * fields, including fields for its nickname and identity. */ -@@ -685,12 +657,12 @@ +@@ -685,12 +674,12 @@ // No need for return value? control-spec.txt says reply is merely "250 OK" on success... public String postDescriptor(String desc) throws IOException { List<ReplyLine> lst = sendAndWaitForResponse("+POSTDESCRIPTOR\r\n", desc); @@ -901,7 +958,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b * To be sure that the modified address will be used, this event must be sent * after a new stream event is received, and before attaching this stream to * a circuit. -@@ -720,8 +692,7 @@ +@@ -720,8 +709,7 @@ * * Tor may hold the stream open for a while to flush any data that is pending. */ @@ -911,7 +968,7 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b sendAndWaitForResponse("CLOSESTREAM "+streamID+" "+reason+"\r\n",null); } -@@ -729,8 +700,8 @@ +@@ -729,8 +717,15 @@ * If <b>ifUnused</b> is true, do not close the circuit unless it is unused. */ public void closeCircuit(String circID, boolean ifUnused) throws IOException { @@ -919,6 +976,13 @@ diff -Bbur jtorctl/net/freehaven/tor/control/TorControlConnection.java jtorctl-b - (ifUnused?" IFUNUSED":"")+"\r\n", null); + String arg = ifUnused ? " IFUNUSED" : ""; + sendAndWaitForResponse("CLOSECIRCUIT "+circID+arg+"\r\n", null); ++ } ++ ++ /** Tells Tor to exit when this control connection is closed. This command ++ * was added in Tor 0.2.2.28-beta. ++ */ ++ public void takeOwnership() throws IOException { ++ sendAndWaitForResponse("TAKEOWNERSHIP\r\n", null); } }