[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r10048: Patch to torctl from Karsten Loesing to handle shutdown a li (in torctl/trunk: . java/net/freehaven/tor/control java/net/freehaven/tor/control/examples)
- To: or-cvs@xxxxxxxxxxxxx
- Subject: [or-cvs] r10048: Patch to torctl from Karsten Loesing to handle shutdown a li (in torctl/trunk: . java/net/freehaven/tor/control java/net/freehaven/tor/control/examples)
- From: nickm@xxxxxxxx
- Date: Sun, 29 Apr 2007 22:31:09 -0400 (EDT)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Sun, 29 Apr 2007 22:31:19 -0400
- Reply-to: or-talk@xxxxxxxxxxxxx
- Sender: owner-or-cvs@xxxxxxxxxxxxx
Author: nickm
Date: 2007-04-29 22:31:08 -0400 (Sun, 29 Apr 2007)
New Revision: 10048
Modified:
torctl/trunk/
torctl/trunk/java/net/freehaven/tor/control/PasswordDigest.java
torctl/trunk/java/net/freehaven/tor/control/TorControlConnection.java
torctl/trunk/java/net/freehaven/tor/control/TorControlConnection1.java
torctl/trunk/java/net/freehaven/tor/control/TorControlError.java
torctl/trunk/java/net/freehaven/tor/control/TorControlSyntaxError.java
torctl/trunk/java/net/freehaven/tor/control/examples/Main.java
Log:
r12549@catbus: nickm | 2007-04-29 22:31:04 -0400
Patch to torctl from Karsten Loesing to handle shutdown a little better; also fix some warnings from javac.
Property changes on: torctl/trunk
___________________________________________________________________
svk:merge ticket from /torctl/trunk [r12549] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: torctl/trunk/java/net/freehaven/tor/control/PasswordDigest.java
===================================================================
--- torctl/trunk/java/net/freehaven/tor/control/PasswordDigest.java 2007-04-30 01:27:47 UTC (rev 10047)
+++ torctl/trunk/java/net/freehaven/tor/control/PasswordDigest.java 2007-04-30 02:31:08 UTC (rev 10048)
@@ -88,11 +88,6 @@
return key;
}
- private static final char[] NYBBLES = {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
- };
-
/** Return a hexadecimal encoding of a byte array. */
// XXX There must be a better way to do this in Java.
private static final String encodeBytes(byte[] ba) {
Modified: torctl/trunk/java/net/freehaven/tor/control/TorControlConnection.java
===================================================================
--- torctl/trunk/java/net/freehaven/tor/control/TorControlConnection.java 2007-04-30 01:27:47 UTC (rev 10047)
+++ torctl/trunk/java/net/freehaven/tor/control/TorControlConnection.java 2007-04-30 02:31:08 UTC (rev 10048)
@@ -4,6 +4,7 @@
package net.freehaven.tor.control;
import java.io.IOException;
+import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -19,7 +20,7 @@
protected LinkedList waiters;
- protected Thread thread;
+ protected ControlParseThread thread;
static class Waiter {
Object response;
@@ -91,15 +92,7 @@
* responses that arrive independantly over the same socket.
*/
public Thread launchThread(boolean daemon) {
- Thread th = new Thread() {
- public void run() {
- try {
- react();
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- }
- };
+ ControlParseThread th = new ControlParseThread();
if (daemon)
th.setDaemon(true);
th.start();
@@ -107,6 +100,25 @@
return th;
}
+ protected class ControlParseThread extends Thread {
+ boolean stopped = false;
+ public void run() {
+ try {
+ react();
+ } catch (SocketException ex) {
+ if (stopped) // we expected this exception
+ return;
+ else
+ throw new RuntimeException(ex);
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ public void stopListening() {
+ this.stopped = true;
+ }
+ }
+
protected final void checkThread() {
if (thread == null)
launchThread(true);
Modified: torctl/trunk/java/net/freehaven/tor/control/TorControlConnection1.java
===================================================================
--- torctl/trunk/java/net/freehaven/tor/control/TorControlConnection1.java 2007-04-30 01:27:47 UTC (rev 10047)
+++ torctl/trunk/java/net/freehaven/tor/control/TorControlConnection1.java 2007-04-30 02:31:08 UTC (rev 10048)
@@ -406,6 +406,9 @@
String s = "SIGNAL " + signal + "\r\n";
if (debugOutput != null)
debugOutput.print(">> "+s);
+ if (this.thread != null) {
+ this.thread.stopListening();
+ }
synchronized (waiters) {
output.write(s);
output.flush();
Modified: torctl/trunk/java/net/freehaven/tor/control/TorControlError.java
===================================================================
--- torctl/trunk/java/net/freehaven/tor/control/TorControlError.java 2007-04-30 01:27:47 UTC (rev 10047)
+++ torctl/trunk/java/net/freehaven/tor/control/TorControlError.java 2007-04-30 02:31:08 UTC (rev 10048)
@@ -7,6 +7,8 @@
* An exception raised when Tor tells us about an error.
*/
public class TorControlError extends RuntimeException {
+ static final long serialVersionUID = 2;
+
int errorType;
public TorControlError(int type, String s) {
super(s);
Modified: torctl/trunk/java/net/freehaven/tor/control/TorControlSyntaxError.java
===================================================================
--- torctl/trunk/java/net/freehaven/tor/control/TorControlSyntaxError.java 2007-04-30 01:27:47 UTC (rev 10047)
+++ torctl/trunk/java/net/freehaven/tor/control/TorControlSyntaxError.java 2007-04-30 02:31:08 UTC (rev 10048)
@@ -4,6 +4,8 @@
* An exception raised when Tor behaves in an unexpected way.
*/
public class TorControlSyntaxError extends RuntimeException {
+ static final long serialVersionUID = 2;
+
public TorControlSyntaxError(String s) { super(s); }
}
Modified: torctl/trunk/java/net/freehaven/tor/control/examples/Main.java
===================================================================
--- torctl/trunk/java/net/freehaven/tor/control/examples/Main.java 2007-04-30 01:27:47 UTC (rev 10047)
+++ torctl/trunk/java/net/freehaven/tor/control/examples/Main.java 2007-04-30 02:31:08 UTC (rev 10048)
@@ -56,7 +56,7 @@
// System.err.println("Debugging");
// ((TorControlConnection1)conn).setDebugging(System.err);
//}
- Thread th = conn.launchThread(daemon);
+ conn.launchThread(daemon);
conn.authenticate(new byte[0]);
return conn;
}