[or-cvs] [torperf/master] Add a script to print the chosen path
sebastian at torproject.org
sebastian at torproject.org
Fri Jan 28 07:49:21 UTC 2011
commit f59100c6ee87cec248fd9d66c3201898c3df5846
Author: Sebastian Hahn <sebastian at torproject.org>
Date: Thu Sep 9 21:43:32 2010 +0200
Add a script to print the chosen path
This script prints out the relays used to fetch a resource, so that the
resulting speed can be correlated with the relays that were picked while
measuering.
---
extra_stats.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
measurements-HOWTO | 41 +++++++++++++++++++++++++++++++++-
2 files changed, 103 insertions(+), 1 deletions(-)
diff --git a/extra_stats.py b/extra_stats.py
new file mode 100644
index 0000000..3da4c4e
--- /dev/null
+++ b/extra_stats.py
@@ -0,0 +1,63 @@
+import sys, time, math
+import TorCtl.TorCtl as TorCtl
+
+HOST = "127.0.0.1"
+
+class WriteStats(TorCtl.PostEventListener):
+ def __init__(self, port, filename):
+ TorCtl.PostEventListener.__init__(self)
+ self._port = int(port)
+ self._filename = filename
+ self._conn = None
+
+
+ def connect(self):
+ self._conn = TorCtl.connect(HOST, self._port)
+
+ def setup_listener(self):
+ self._conn.set_events(["Stream"])
+ self._conn.add_event_listener(self)
+
+ def stream_status_event(self, event):
+ if event.source == 'EXIT' or \
+ event.status == 'DETACHED':
+ for circs in self._conn.get_info( "circuit-status").itervalues():
+ for circ in circs.split("\n"):
+ entry = circ.split(" ")
+ if entry[0] == str(event.circ_id):
+ if event.source == 'EXIT':
+ self.write_result(True, event.arrived_at, entry[2].split(","))
+ else:
+ self.write_result(False, event.arrived_at, entry[2].split(","))
+
+ def write_result(self, successful, now, relays):
+ success = ""
+ if successful:
+ success = "ok"
+ else:
+ success = "error"
+
+ statsfile = open(self._filename, 'a')
+ statsfile.write("%s %d %s\n" % (success, math.floor(now), " ".join(relays)))
+ statsfile.close()
+
+def main():
+ if len(sys.argv) < 3:
+ print "Bad arguments"
+ sys.exit(1)
+
+ port = sys.argv[1]
+ filename = sys.argv[2]
+
+ stats = WriteStats(port, filename)
+ stats.connect()
+ stats.setup_listener()
+ try:
+ while True:
+ time.sleep(500)
+ except:
+ pass
+
+if __name__ == '__main__':
+ main()
+
diff --git a/measurements-HOWTO b/measurements-HOWTO
index 3c6bf8a..bb236b8 100644
--- a/measurements-HOWTO
+++ b/measurements-HOWTO
@@ -49,6 +49,8 @@ MaxCircuitDirtiness 1 minute
UseEntryGuards 0
RunAsDaemon 1
Log notice file log
+ControlPort 10020
+CookieAuthentication 1
EOF
$ cat <<EOF >> torclient1mb/torrc
@@ -57,6 +59,8 @@ SocksPort 9021
UseEntryGuards 0
RunAsDaemon 1
Log notice file log
+ControlPort 10021
+CookieAuthentication 1
EOF
$ cat <<EOF >> torclient5mb/torrc
@@ -65,15 +69,29 @@ SocksPort 9022
UseEntryGuards 0
RunAsDaemon 1
Log notice file log
+ControlPort 10022
+CookieAuthentication 1
EOF
-Write a start script to start the Tor clients and execute it:
+ControlPort is configured so that we can attach a small controller
+that is used to write additional statistics about the chosen paths
+
+Now we need to get TorCtl:
+
+$ git clone git://git.torproject.org/pytorctl TorCtl
+
+Write a start script to start the Tor clients and the controllers,
+and execute it:
$ cat <<EOF >> start-tors
#!/bin/bash
cd ~/torperf/torclient50kb && tor -f ~/torperf/torclient50kb/torrc
cd ~/torperf/torclient1mb && tor -f ~/torperf/torclient1mb/torrc
cd ~/torperf/torclient5mb && tor -f ~/torperf/torclient5mb/torrc
+sleep 5
+cd ~/torperf/torclient50kb && python ../extra_stats.py 10020 ~/torperf/50kb.extradata
+cd ~/torperf/torclient1mb && python ../extra_stats.py 10021 ~/torperf/1mb.extradata
+cd ~/torperf/torclient5mb && python ../extra_stats.py 10022 ~/torperf/5mb.extradata
EOF
$ chmod a+x start-tors
@@ -126,6 +144,27 @@ startsec startusec
datacompletesec datacompleteusec
writebytes readbytes
+The 50kb.extradata, 1mb.extradata, and 5mb.extradata files should
+accumulate lines like this (linebreaks for formatting reasons):
+
+ok 1284059486 $ED16C4DD8E9BCACDE829E6B6571B58095383897A=PPrivCom030
+ $80818E35A46DEED6889818ADC596404AB94E392A=Pandora14
+ $4C23C8C30C66C87E1C875A949B4841E4305FFC57~Amunet11
+
+with column headers:
+
+ok|error timestamp firsthop secondhop thirdhop [fourthhop ...]
+
+The first column indicates if this circuit was actually used to fetch
+the data or if Tor chose a different one because this one was
+problematic. For every error entry there should be a following ok
+entry, unless the network of the torperf instance is totally dead or
+the resource it wants to fetch is unavailable.
+
+The timestamp will NOT necessarily match one from the .data file
+exactly, because additional processing is necessary. You should allow
+for up to a minute of slack when matching the two files up.
+
If everything works, you might want to let your system start these Tor
clients on system startup. On Debian, this can be done using a crontab
entry, too:
More information about the tor-commits
mailing list