aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-03-31 06:05:36 +0000
committerNick Mathewson <nickm@torproject.org>2005-03-31 06:05:36 +0000
commit5062c49c76fa8b1a44128f5252291d9463d5bc7d (patch)
tree63ddac0b546fd64bcb5cf4446e1f36506ec4a30d /contrib
parent14296cd49c66cc6ad2f0158c1d657aba66975e50 (diff)
downloadtor-5062c49c76fa8b1a44128f5252291d9463d5bc7d.tar
tor-5062c49c76fa8b1a44128f5252291d9463d5bc7d.tar.gz
Make ExercieseServer actually work.
svn:r3925
Diffstat (limited to 'contrib')
-rw-r--r--contrib/ExerciseServer.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/contrib/ExerciseServer.py b/contrib/ExerciseServer.py
index 06c9a6a40..9657d5347 100644
--- a/contrib/ExerciseServer.py
+++ b/contrib/ExerciseServer.py
@@ -27,12 +27,14 @@ def runSocks4A(nonce, targetHost, targetPort, targetURL):
while 1:
r = s.recv(1024)
if not r:
+ print "WOOT! Got a web page."
s.close()
return 1
-HOSTS_TO_TEST = [ "moria1", "mordor", "tor26"]
+HOSTS_TO_TEST = [ "moria1", "ned", "tor26"]
EXITS_TO_TEST = [ "pvt", ]
-TARGETS = [ ("www.seul.org", "/"), ]
+TARGETS = [ ("belegost.mit.edu", "/"),
+ ("seul.org", "/")]
CIRCS_AT_A_TIME = 3
CIRC_LEN = 3
@@ -46,9 +48,9 @@ def launchCirc(s):
def runControl(s):
circs = {}
- streams = {}
- _h = lambda body,circs=circs,streams=streams,s=s:handleEvent(s,body,
- circs,streams)
+ s1,s2 = {},{}
+ _h = lambda body,circs=circs,s1=s1,s2=s2,s=s:handleEvent(s,body,
+ circs,s1,s2)
TorControl._event_handler = _h
TorControl.set_events(s,
[TorControl.EVENT_TYPE.CIRCSTATUS,
@@ -61,9 +63,9 @@ def runControl(s):
circs[c]=p
_, tp, body = TorControl.receive_message(s)
if tp == TorControl.MSG_TYPE.EVENT:
- handleEvent(s, body, circs, streams)
+ handleEvent(s, body, circs, s1,s2)
-def handleEvent(s, body, circs, streams):
+def handleEvent(s, body, circs, streamsByNonce, streamsByIdent):
event, args = TorControl.unpack_event(body)
if event == TorControl.EVENT_TYPE.STREAMSTATUS:
status, ident, target = args
@@ -72,12 +74,20 @@ def handleEvent(s, body, circs, streams):
if status in (TorControl.STREAM_STATUS.NEW_CONNECT,
TorControl.STREAM_STATUS.NEW_RESOLVE,
TorControl.STREAM_STATUS.DETACHED):
+ target,port=target.split(":")
if not target.endswith(".exnonce"):
TorControl.attach_stream(s, ident, 0)
else:
- circid, (host,url) = streams[target]
+ circid, (host,url) = streamsByNonce[target]
+ streamsByIdent[ident] = circid,(host,url)
+ print "Redirecting circuit",circid,"to",host
TorControl.redirect_stream(s, ident, host)
TorControl.attach_stream(s, ident, circid)
+ elif status in (TorControl.STREAM_STATUS.CLOSED,
+ TorControl.STREAM_STATUS.FAILED):
+ circid, (host,url) = streamsByIdent[ident]
+ del circs[circid]
+ del streamsByIdent[ident]
elif event == TorControl.EVENT_TYPE.CIRCSTATUS:
status, ident, path = args
print "Got circuit event",TorControl.CIRC_STATUS.nameOf[status],\
@@ -91,7 +101,7 @@ def handleEvent(s, body, circs, streams):
nonce = random.randint(1,100000000)
nonce = "%s.exnonce" % nonce
host,url = random.choice(TARGETS)
- streams[nonce] = ident, (host,url)
+ streamsByNonce[nonce] = ident, (host,url)
print "Launching socks4a connection"
t = threading.Thread(target=runSocks4A, args=(nonce, host, 80, url))
t.setDaemon(1)