summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-03-31 05:44:44 +0000
committerNick Mathewson <nickm@torproject.org>2005-03-31 05:44:44 +0000
commit13bd755ae65c5978243ad6e7028a478dc51b7547 (patch)
treead94cc742e9335ef0d779497bb35a701e1b93791
parentc7ef516c43928853795f3dab6858ad065220618b (diff)
downloadtor-13bd755ae65c5978243ad6e7028a478dc51b7547.tar.gz
tor-13bd755ae65c5978243ad6e7028a478dc51b7547.zip
checkpoint fixes to TorControl
svn:r3923
-rwxr-xr-xcontrib/TorControl.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/contrib/TorControl.py b/contrib/TorControl.py
index 60ef345827..5a63ad4187 100755
--- a/contrib/TorControl.py
+++ b/contrib/TorControl.py
@@ -114,7 +114,6 @@ def parseHostAndPort(h):
return host, port
-
def _unpack_msg(msg):
"return None, minLength, body or type,body,rest"
if len(msg) < 4:
@@ -173,6 +172,14 @@ def unpack_msg(msg):
minLength = _minLengthToPack(inOtherPackets)
return None, len(msg)+leftInPacket+inOtherPackets, msg
+def _receive_msg(s):
+ body = ""
+ header = s.recv(4)
+ length,type = struct.unpack("!HH",header)
+ if length:
+ body = s.recv(length)
+ return length,type,body
+
def receive_message(s):
length, tp, body = _receive_msg(s)
if tp != MSG_TYPE.FRAGMENTHEADER:
@@ -295,10 +302,16 @@ def extend_circuit(s, circid, hops):
tp, body = receive_reply(s,[MSG_TYPE.DONE])
if len(body) != 4:
raise ProtocolError("Extendcircuit reply too short or long")
- return struct.unpack("!L",body)
+ return struct.unpack("!L",body)[0]
def redirect_stream(s, streamid, newtarget):
msg = struct.pack("!L",streamid) + newtarget + "\0"
+ send_message(s,MSG_TYPE.REDIRECTSTREAM,msg)
+ tp,body = receive_reply(s,[MSG_TYPE.DONE])
+
+def attach_stream(s, streamid, circid):
+ msg = struct.pack("!LL",streamid, circid)
+ send_message(s,MSG_TYPE.ATTACHSTREAM,msg)
tp,body = receive_reply(s,[MSG_TYPE.DONE])
def _unterminate(s):
@@ -310,9 +323,9 @@ def _unterminate(s):
def unpack_event(body):
if len(body)<2:
raise ProtocolError("EVENT body too short.")
- evtype = struct.unpack("!H", body[:2])
+ evtype, = struct.unpack("!H", body[:2])
body = body[2:]
- if evtype == EVENT_TYPE.CIRCUITSTATUS:
+ if evtype == EVENT_TYPE.CIRCSTATUS:
if len(body)<5:
raise ProtocolError("CIRCUITSTATUS event too short.")
status,ident = struct.unpack("!BL", body[:5])