[or-cvs] r23832: {arm} Bumping arm's copy of torctl to the current git. (in arm/resources: . TorCtl)
Damian Johnson
atagar1 at gmail.com
Fri Nov 19 05:29:54 UTC 2010
Author: atagar
Date: 2010-11-19 05:29:53 +0000 (Fri, 19 Nov 2010)
New Revision: 23832
Added:
arm/resources/TorCtl/LICENSE
Modified:
arm/resources/TorCtl/GeoIPSupport.py
arm/resources/TorCtl/PathSupport.py
arm/resources/TorCtl/SQLSupport.py
arm/resources/TorCtl/ScanSupport.py
arm/resources/TorCtl/TorCtl.py
arm/resources/TorCtl/TorUtil.py
arm/resources/notes.txt
Log:
Bumping arm's copy of torctl to the current git.
Modified: arm/resources/TorCtl/GeoIPSupport.py
===================================================================
--- arm/resources/TorCtl/GeoIPSupport.py 2010-11-18 19:51:18 UTC (rev 23831)
+++ arm/resources/TorCtl/GeoIPSupport.py 2010-11-19 05:29:53 UTC (rev 23832)
@@ -1,4 +1,5 @@
#!/usr/bin/python
+# Copyright 2007 Johannes Renner and Mike Perry. See LICENSE file.
import struct
import socket
Added: arm/resources/TorCtl/LICENSE
===================================================================
--- arm/resources/TorCtl/LICENSE (rev 0)
+++ arm/resources/TorCtl/LICENSE 2010-11-19 05:29:53 UTC (rev 23832)
@@ -0,0 +1,33 @@
+===============================================================================
+The Python Tor controller code is distributed under this license:
+
+Copyright 2005, Nick Mathewson, Roger Dingledine
+Copyright 2007-2010, Mike Perry
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+
+ * Neither the names of the copyright owners nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Modified: arm/resources/TorCtl/PathSupport.py
===================================================================
--- arm/resources/TorCtl/PathSupport.py 2010-11-18 19:51:18 UTC (rev 23831)
+++ arm/resources/TorCtl/PathSupport.py 2010-11-19 05:29:53 UTC (rev 23832)
@@ -1,4 +1,5 @@
#!/usr/bin/python
+# Copyright 2007-2010 Mike Perry. See LICENSE file.
"""
Support classes for path construction
Modified: arm/resources/TorCtl/SQLSupport.py
===================================================================
--- arm/resources/TorCtl/SQLSupport.py 2010-11-18 19:51:18 UTC (rev 23831)
+++ arm/resources/TorCtl/SQLSupport.py 2010-11-19 05:29:53 UTC (rev 23832)
@@ -1,4 +1,5 @@
#!/usr/bin/python
+# Copyright 2009-2010 Mike Perry. See LICENSE file.
"""
Modified: arm/resources/TorCtl/ScanSupport.py
===================================================================
--- arm/resources/TorCtl/ScanSupport.py 2010-11-18 19:51:18 UTC (rev 23831)
+++ arm/resources/TorCtl/ScanSupport.py 2010-11-19 05:29:53 UTC (rev 23832)
@@ -1,12 +1,16 @@
+#!/usr/bin/python
+# Copyright 2009-2010 Mike Perry. See LICENSE file.
import PathSupport
-import SQLSupport
import threading
import copy
import time
import shutil
+import TorCtl
from TorUtil import plog
+SQLSupport = None
+
# Note: be careful writing functions for this class. Remember that
# the PathBuilder has its own thread that it recieves events on
# independent from your thread that calls into here.
@@ -169,6 +173,14 @@
cond.release()
class SQLScanHandler(ScanHandler):
+ def __init__(self, c, selmgr, RouterClass=TorCtl.Router,
+ strm_selector=PathSupport.StreamSelector):
+ # Only require sqlalchemy if we really need it.
+ global SQLSupport
+ if SQLSupport is None:
+ import SQLSupport
+ ScanHandler.__init__(self, c, selmgr, RouterClass, strm_selector)
+
def attach_sql_listener(self, db_uri):
plog("DEBUG", "Got sqlite: "+db_uri)
SQLSupport.setup_db(db_uri, echo=False, drop=True)
Modified: arm/resources/TorCtl/TorCtl.py
===================================================================
--- arm/resources/TorCtl/TorCtl.py 2010-11-18 19:51:18 UTC (rev 23831)
+++ arm/resources/TorCtl/TorCtl.py 2010-11-19 05:29:53 UTC (rev 23832)
@@ -1,7 +1,7 @@
#!/usr/bin/python
# TorCtl.py -- Python module to interface with Tor Control interface.
# Copyright 2005 Nick Mathewson
-# Copyright 2007 Mike Perry. See LICENSE file.
+# Copyright 2007-2010 Mike Perry. See LICENSE file.
"""
Library to control Tor processes.
@@ -510,7 +510,7 @@
plog("INFO", "Hibernating router "+ns.nickname+" is running, flags: "+" ".join(ns.flags))
if router != ns.nickname:
- plog("NOTICE", "Got different names " + ns.nickname + " vs " +
+ plog("INFO", "Got different names " + ns.nickname + " vs " +
router + " for " + ns.idhex)
if not bw_observed and not dead and ("Valid" in ns.flags):
plog("INFO", "No bandwidth for live router "+ns.nickname+", flags: "+" ".join(ns.flags))
@@ -527,11 +527,9 @@
'new' """
if self.idhex != new.idhex:
plog("ERROR", "Update of router "+self.nickname+"changes idhex!")
- plog("DEBUG", "Updating refcount "+str(self.refcount)+" for "+self.idhex)
for i in new.__dict__.iterkeys():
if i == "refcount" or i == "_generated": continue
self.__dict__[i] = new.__dict__[i]
- plog("DEBUG", "Updated refcount "+str(self.refcount)+" for "+self.idhex)
def will_exit_to(self, ip, port):
""" Check the entire exitpolicy to see if the router will allow
@@ -811,6 +809,10 @@
self.set_event_handler(EventHandler())
self._handler.add_event_listener(listener)
+ def block_until_close(self):
+ """ Blocks until the connection to the Tor process is interrupted"""
+ return self._eventThread.join()
+
def _read_reply(self):
lines = []
while 1:
@@ -1012,6 +1014,11 @@
"""
self.sendAndRecv("RESETCONF %s\r\n"%(" ".join(keylist)))
+ def get_consensus(self):
+ """Get the pristine Tor Consensus. Returns a list of
+ TorCtl.NetworkStatus instances."""
+ return parse_ns_body(self.sendAndRecv("GETINFO dir/status-vote/current/consensus\r\n")[0][2])
+
def get_network_status(self, who="all"):
"""Get the entire network status list. Returns a list of
TorCtl.NetworkStatus instances."""
@@ -1556,8 +1563,15 @@
"""
A ConsensusTracker is an EventHandler that tracks the current
consensus of Tor in self.ns_map, self.routers and self.sorted_r
+
+ Users must subscribe to "NEWCONSENSUS" and "NEWDESC" events.
+
+ If you also wish to track the Tor client's opinion on the Running flag
+ based on reachability tests, you must subscribe to "NS" events,
+ and you should set the constructor parameter "consensus_only" to
+ False.
"""
- def __init__(self, c, RouterClass=Router):
+ def __init__(self, c, RouterClass=Router, consensus_only=True):
EventHandler.__init__(self)
c.set_event_handler(self)
self.ns_map = {}
@@ -1566,6 +1580,7 @@
self.name_to_key = {}
self.RouterClass = RouterClass
self.consensus_count = 0
+ self.consensus_only = consensus_only
self.update_consensus()
# XXX: If there were a potential memory leak through perpetually referenced
@@ -1646,7 +1661,10 @@
self.name_to_key[n.nickname] = "$"+n.idhex
def update_consensus(self):
- self._update_consensus(self.c.get_network_status())
+ if self.consensus_only:
+ self._update_consensus(self.c.get_consensus())
+ else:
+ self._update_consensus(self.c.get_network_status())
self._read_routers(self.ns_map.values())
def new_consensus_event(self, n):
@@ -1660,7 +1678,11 @@
for i in d.idlist:
r = None
try:
- ns = self.c.get_network_status("id/"+i)
+ if i in self.ns_map:
+ ns = (self.ns_map[i],)
+ else:
+ plog("WARN", "Need to getinfo ns/id for router desc: "+i)
+ ns = self.c.get_network_status("id/"+i)
r = self.c.read_routers(ns)
except ErrorReply, e:
plog("WARN", "Error reply for "+i+" after NEWDESC: "+str(e))
@@ -1698,6 +1720,31 @@
self._sanity_check(self.sorted_r)
return update
+ def ns_event(self, ev):
+ update = False
+ for ns in ev.nslist:
+ # Check current consensus.. If present, check flags
+ if ns.idhex in self.ns_map and ns.idhex in self.routers and \
+ ns.orhash == self.ns_map[ns.idhex].orhash:
+ if "Running" in ns.flags and \
+ "Running" not in self.ns_map[ns.idhex].flags:
+ plog("INFO", "Router "+ns.nickname+"="+ns.idhex+" is now up.")
+ update = True
+ self.routers[ns.idhex].flags = ns.flags
+ self.routers[ns.idhex].down = False
+
+ if "Running" not in ns.flags and \
+ "Running" in self.ns_map[ns.idhex].flags:
+ plog("INFO", "Router "+ns.nickname+"="+ns.idhex+" is now down.")
+ update = True
+ self.routers[ns.idhex].flags = ns.flags
+ self.routers[ns.idhex].down = True
+ if update:
+ self.sorted_r = filter(lambda r: not r.down, self.routers.itervalues())
+ self.sorted_r.sort(lambda x, y: cmp(y.bw, x.bw))
+ for i in xrange(len(self.sorted_r)): self.sorted_r[i].list_rank = i
+ self._sanity_check(self.sorted_r)
+
def current_consensus(self):
return Consensus(self.ns_map, self.sorted_r, self.routers,
self.name_to_key, self.consensus_count)
Modified: arm/resources/TorCtl/TorUtil.py
===================================================================
--- arm/resources/TorCtl/TorUtil.py 2010-11-18 19:51:18 UTC (rev 23831)
+++ arm/resources/TorCtl/TorUtil.py 2010-11-19 05:29:53 UTC (rev 23832)
@@ -1,7 +1,7 @@
#!/usr/bin/python
# TorCtl.py -- Python module to interface with Tor Control interface.
-# Copyright 2007 Mike Perry -- See LICENSE for licensing information.
-# Portions Copyright 2005 Nick Matthewson
+# Copyright 2007-2010 Mike Perry -- See LICENSE for licensing information.
+# Portions Copyright 2005 Nick Mathewson
"""
TorUtil -- Support functions for TorCtl.py and metatroller
Modified: arm/resources/notes.txt
===================================================================
--- arm/resources/notes.txt 2010-11-18 19:51:18 UTC (rev 23831)
+++ arm/resources/notes.txt 2010-11-19 05:29:53 UTC (rev 23832)
@@ -8,7 +8,7 @@
- dump /release/ChangeLog into /resources/build/debian/changelog
TorCtl (dependency) -
- Last Updated: 8/22/10 (c514a0a7105cebe7cc5fa199750b90369b820bfb):
+ Last Updated: 11/18/10 (https://gitweb.torproject.org/pytorctl.git):
To update run the following:
git clone git://git.torproject.org/pytorctl.git
cd pytorctl
More information about the tor-commits
mailing list