Newer
Older
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 @@
* <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> contains the alphanumeric ServerIDs of the circuit's routers.
+ * <b>info</b> may include some or all of the following entries:
+ * <ul>
+ * <li>BUILD_FLAGS: a comma-separated list of the circuit's build
+ * flags.</li>
+ * <li>PURPOSE: the purpose of the circuit.</li>
+ * <li>HS_STATE: the state of the circuit if it is a hidden service
+ * circuit.</li>
+ * <li>REND_QUERY: the hidden service address if the circuit is a
+ * hidden service circuit.</li>
+ * </ul>
*/
- public void circuitStatus(String status, String circID, String path);
+ public void circuitStatus(String status, String circID, List<String> path,
+ Map<String, String> info);
/**
* 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
@@ -3,12 +3,12 @@
package net.freehaven.tor.control.examples;
import java.io.PrintWriter;
-import java.util.Iterator;
+import java.util.List;
import net.freehaven.tor.control.EventHandler;
public class DebuggingEventHandler implements EventHandler {
- protected PrintWriter out;
+ private final PrintWriter out;
public DebuggingEventHandler(PrintWriter p) {
out = p;
@@ -27,11 +30,13 @@
out.println("Bandwidth usage: "+read+" bytes read; "+
written+" bytes written.");
}
- public void newDescriptors(java.util.List<String> orList) {
+
+ public void newDescriptors(List<String> orList) {
out.println("New descriptors for routers:");
- for (Iterator<String> i = orList.iterator(); i.hasNext(); )
- out.println(" "+i.next());
+ for (String or : orList)
+ out.println(" "+or);
}
+
public void message(String type, String msg) {
out.println("["+type+"] "+msg.trim());
}
diff -Bbur jtorctl/net/freehaven/tor/control/examples/Main.java jtorctl-briar/net/freehaven/tor/control/examples/Main.java
--- jtorctl/net/freehaven/tor/control/examples/Main.java 2014-04-02 11:26:56.000000000 +0100
+++ jtorctl-briar/net/freehaven/tor/control/examples/Main.java 2014-04-02 11:56:39.000000000 +0100
@@ -2,14 +2,17 @@
// See LICENSE file for copying information
package net.freehaven.tor.control.examples;
-import net.freehaven.tor.control.*;
import java.io.PrintWriter;
+import java.io.EOFException;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.Socket;
import java.util.ArrayList;
-import java.util.List;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
-import java.util.Iterator;
+
+import net.freehaven.tor.control.*;
public class Main implements TorControlCommands {
} else {
System.err.println("Unrecognized command: "+args[0]);
}
- } catch (java.io.EOFException ex) {
+ } catch (EOFException ex) {
System.out.println("Control socket closed by Tor.");
+ } catch (TorControlError ex) {
+ System.err.println("Error from Tor process: "+
+ ex+" ["+ex.getErrorMsg()+"]");
} catch (IOException ex) {
System.err.println("IO exception when talking to Tor process: "+
ex);
ex.printStackTrace(System.err);
- } catch (TorControlError ex) {
- System.err.println("Error from Tor process: "+
- ex+" ["+ex.getErrorMsg()+"]");
}
}
private static TorControlConnection getConnection(String[] args,
- boolean daemon)
- 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);
- //}
+ boolean daemon) throws IOException {
+ Socket s = new Socket("127.0.0.1", 9100);
+ TorControlConnection conn = new TorControlConnection(s);
conn.launchThread(daemon);
conn.authenticate(new byte[0]);
return conn;
public static void getConfig(String[] args) throws IOException {
// Usage: get-config key key key
TorControlConnection conn = getConnection(args);
- List<ConfigEntry> lst = conn.getConf(Arrays.asList(args).subList(1,args.length));
- for (Iterator<ConfigEntry> i = lst.iterator(); i.hasNext(); ) {
- ConfigEntry e = i.next();
+ List<String> keys = Arrays.asList(args).subList(1, args.length);
+ List<ConfigEntry> lst = conn.getConf(keys);
+ for (ConfigEntry e : lst) {
System.out.println("KEY: "+e.key);
System.out.println("VAL: "+e.value);
public static void getInfo(String[] args) throws IOException {
TorControlConnection conn = getConnection(args);
- Map<String,String> m = conn.getInfo(Arrays.asList(args).subList(1,args.length));
- for (Iterator<Map.Entry<String, String>> i = m.entrySet().iterator(); i.hasNext(); ) {
- Map.Entry<String,String> e = i.next();
+ List<String> keys = Arrays.asList(args).subList(1, args.length);
+ Map<String,String> m = conn.getInfo(keys);
+ for (Map.Entry<String,String> e : m.entrySet()) {
System.out.println("KEY: "+e.getKey());
System.out.println("VAL: "+e.getValue());
@@ -108,10 +106,7 @@
public static void listenForEvents(String[] args) throws IOException {
// Usage: listen [circ|stream|orconn|bw|newdesc|info|notice|warn|error]*
TorControlConnection conn = getConnection(args, false);
- ArrayList<String> lst = new ArrayList<String>();
- for (int i = 1; i < args.length; ++i) {
- lst.add(args[i]);
- }
+ List<String> lst = Arrays.asList(args).subList(1, args.length);
conn.setEventHandler(
new DebuggingEventHandler(new PrintWriter(System.out, true)));
conn.setEvents(lst);
@@ -130,17 +125,13 @@
}
public static void authDemo(String[] args) throws IOException {
-
PasswordDigest pwd = PasswordDigest.generateDigest();
- java.net.Socket s = new java.net.Socket("127.0.0.1", 9100);
- TorControlConnection conn = TorControlConnection.getConnection(s);
+ Socket s = new java.net.Socket("127.0.0.1", 9100);
+ TorControlConnection conn = new TorControlConnection(s);
conn.launchThread(true);
conn.authenticate(new byte[0]);
-
conn.setConf("HashedControlPassword", pwd.getHashedPassword());
-
- conn = TorControlConnection.getConnection(
- new java.net.Socket("127.0.0.1", 9100));
+ conn = new TorControlConnection(new Socket("127.0.0.1", 9100));
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 16:54:43.219370671 +0100
@@ -2,12 +2,16 @@
// See LICENSE file for copying information
package net.freehaven.tor.control;
+import java.util.List;
+import java.util.Map;
Loading
Loading full blame...