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 16:54:29.291301601 +0100 @@ -2,6 +2,9 @@ // See LICENSE file for copying information package net.freehaven.tor.control; +import java.util.List; +import java.util.Map; + /** * Abstract interface whose methods are invoked when Tor sends us an event. * @@ -20,10 +23,21 @@ *
* Tor behaves as though it had just read each of the key-value pairs * from its configuration file. Keywords with no corresponding values have * their configuration values reset to their defaults. setConf is * all-or-nothing: if there is an error in any of the configuration settings, * Tor sets none of them. - * + *
* When a configuration option takes multiple values, or when multiple * configuration keys form a context-sensitive group (see getConf below), then * setting any of the options in a setConf command is taken to reset all of * the others. For example, if two ORBindAddress values are configured, and a * command arrives containing a single ORBindAddress value, the new * command's value replaces the two old values. - * + *
* To remove all settings for a given option entirely (and go back to its
* default value), include a String in kvList containing the key and no value.
*/
public void setConf(Collection
* If an option appears multiple times in the configuration, all of its
* key-value pairs are returned in order.
- *
+ *
* 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,61 +417,63 @@
* HiddenServiceNodes, and HiddenServiceExcludeNodes option settings.
*/
public List
* Any events not listed in the events are turned off; thus, calling
* setEvents with an empty events argument turns off all event reporting.
*/
public void setEvents(List
* By default, the current Tor implementation trusts all local users, and
* the controller can authenticate itself by calling authenticate(new byte[0]).
- *
+ *
* If the 'CookieAuthentication' option is true, Tor writes a "magic cookie"
* file named "control_auth_cookie" into its data directory. To authenticate,
* the controller must send the contents of this file in auth.
- *
+ *
* If the 'HashedControlPassword' option is set, auth must contain the salted
* hash of a secret password. The salted hash is computed according to the
* S2K algorithm in RFC 2440 (OpenPGP), and prefixed with the s2k specifier.
* This is then encoded in hexadecimal, prefixed by the indicator sequence
* "16:".
- *
+ *
* You can generate the salt of a password by calling
- * 'tor --hash-password
* To authenticate under this scheme, the controller sends Tor the original
* secret that was used to generate the password.
*/
@@ -505,9 +511,6 @@
Waiter w = new Waiter();
if (debugOutput != null)
debugOutput.print(">> "+s);
- if (this.thread != null) {
- this.thread.stopListening();
- }
synchronized (waiters) {
output.write(s);
output.flush();
@@ -519,7 +522,7 @@
* addresses should be replaced with connections to the specified replacement
* addresses. Each element of kvLines is a String of the form
* "old-address new-address". This function returns the new address mapping.
- *
+ *
* 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 +530,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.
- *
+ *
* If the original address is already mapped to a different address, the old
* mapping is removed. If the original address and the destination address
* are the same, the server removes any mapping in place for the original
* address.
- *
+ *
* Mappings set by the controller last until the Tor process exits:
* they never expire. If the controller wants the mapping to last only
* a certain time, then it must explicitly un-map the address when that
* time has elapsed.
*/
public Map
* Recognized keys include:
*
* If successful, returns the Circuit ID of the (maybe newly created) circuit.
*/
public String extendCircuit(String circID, String path) throws IOException {
List
* Each stream may be associated with
* at most one circuit, and multiple streams may share the same circuit.
* Streams can only be attached to completed circuits (that is, circuits that
* have sent a circuit status "BUILT" event or are listed as built in a
* getInfo circuit-status request).
- *
+ *
* If circID is 0, responsibility for attaching the given stream is
* returned to Tor.
- *
+ *
* By default, Tor automatically attaches streams to
* circuits itself, unless the configuration variable
* "__LeaveStreamsUnattached" is set to "1". Attempting to attach streams
* via TC when "__LeaveStreamsUnattached" is false may cause a race between
* Tor and the controller, as both attempt to attach streams to circuits.
*/
- public void attachStream(String streamID, String circID)
- throws IOException {
+ public void attachStream(String streamID, String circID) throws IOException {
sendAndWaitForResponse("ATTACHSTREAM "+streamID+" "+circID+"\r\n", null);
}
/** Tells Tor about the server descriptor in desc.
- *
+ *
* The descriptor, when parsed, must contain a number of well-specified
* fields, including fields for its nickname and identity.
*/
@@ -685,12 +678,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
* 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 +713,7 @@
*
* Tor may hold the stream open for a while to flush any data that is pending.
*/
- public void closeStream(String streamID, byte reason)
- throws IOException {
+ public void closeStream(String streamID, byte reason) throws IOException {
sendAndWaitForResponse("CLOSESTREAM "+streamID+" "+reason+"\r\n",null);
}
@@ -729,8 +721,15 @@
* If ifUnused is true, do not close the circuit unless it is unused.
*/
public void closeCircuit(String circID, boolean ifUnused) throws IOException {
- sendAndWaitForResponse("CLOSECIRCUIT "+circID+
- (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);
}
}
diff -Bbur jtorctl/net/freehaven/tor/control/TorControlError.java jtorctl-briar/net/freehaven/tor/control/TorControlError.java
--- jtorctl/net/freehaven/tor/control/TorControlError.java 2014-04-02 11:26:56.000000000 +0100
+++ jtorctl-briar/net/freehaven/tor/control/TorControlError.java 2014-04-02 12:28:01.000000000 +0100
@@ -2,13 +2,17 @@
// See LICENSE file for copying information
package net.freehaven.tor.control;
+import java.io.IOException;
+
/**
* An exception raised when Tor tells us about an error.
*/
-public class TorControlError extends RuntimeException {
- static final long serialVersionUID = 2;
+public class TorControlError extends IOException {
+
+ private static final long serialVersionUID = 3;
+
+ private final int errorType;
- int errorType;
public TorControlError(int type, String s) {
super(s);
errorType = type;
diff -Bbur jtorctl/net/freehaven/tor/control/TorControlSyntaxError.java jtorctl-briar/net/freehaven/tor/control/TorControlSyntaxError.java
--- jtorctl/net/freehaven/tor/control/TorControlSyntaxError.java 2014-04-02 11:26:56.000000000 +0100
+++ jtorctl-briar/net/freehaven/tor/control/TorControlSyntaxError.java 2014-04-02 12:27:52.000000000 +0100
@@ -2,12 +2,16 @@
// See LICENSE file for copying information
package net.freehaven.tor.control;
+import java.io.IOException;
+
/**
* An exception raised when Tor behaves in an unexpected way.
*/
-public class TorControlSyntaxError extends RuntimeException {
- static final long serialVersionUID = 2;
+public class TorControlSyntaxError extends IOException {
- public TorControlSyntaxError(String s) { super(s); }
-}
+ private static final long serialVersionUID = 3;
+ public TorControlSyntaxError(String s) {
+ super(s);
+ }
+}
*
*/
public Map