[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r18138: {torctl} Change NodeGenerator.rebuild() to take an optional sorted_r (torctl/trunk/python/TorCtl)
Author: mikeperry
Date: 2009-01-16 19:17:59 -0500 (Fri, 16 Jan 2009)
New Revision: 18138
Modified:
torctl/trunk/python/TorCtl/PathSupport.py
torctl/trunk/python/TorCtl/StatsSupport.py
Log:
Change NodeGenerator.rebuild() to take an optional sorted_r
argument to replace the generators' router list. Also allow
StatsHandler to take a new router class.
Modified: torctl/trunk/python/TorCtl/PathSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/PathSupport.py 2009-01-17 00:15:57 UTC (rev 18137)
+++ torctl/trunk/python/TorCtl/PathSupport.py 2009-01-17 00:17:59 UTC (rev 18138)
@@ -138,8 +138,7 @@
"""Constructor. Takes a bandwidth-sorted list of Routers 'sorted_r'
and a NodeRestrictionList 'rstr_list'"""
self.rstr_list = rstr_list # Check me before you yield!
- self.sorted_r = sorted_r
- self.rebuild()
+ self.rebuild(sorted_r)
def reset_restriction(self, rstr_list):
"Reset the restriction list to a new list"
@@ -153,9 +152,11 @@
plog("ERROR", "No routers left after restrictions applied!")
raise RestrictionError()
- def rebuild(self):
+ def rebuild(self, sorted_r=None):
""" Extra step to be performed when new routers are added or when
the restrictions change. """
+ if sorted_r:
+ self.sorted_r = sorted_r
self.rstr_routers = filter(lambda r: self.rstr_list.r_is_ok(r), self.sorted_r)
if not self.rstr_routers:
plog("ERROR", "No routers left after restrictions applied!")
@@ -576,8 +577,8 @@
self.pathlen = pathlen
NodeGenerator.__init__(self, sorted_r, rstr_list)
- def rebuild(self):
- NodeGenerator.rebuild(self)
+ def rebuild(self, sorted_r=None):
+ NodeGenerator.rebuild(self, sorted_r)
NodeGenerator.rewind(self)
# Set the exit_weight
# We are choosing a non-exit
@@ -684,6 +685,12 @@
self.exit_gen = exit_gen
self.path_restrict = path_restrict
+ def rebuild_gens(self, sorted_r):
+ "Rebuild the 3 generators with a new sorted router list"
+ self.entry_gen.rebuild(sorted_r)
+ self.mid_gen.rebuild(sorted_r)
+ self.exit_gen.rebuild(sorted_r)
+
def build_path(self, pathlen):
"""Creates a path of 'pathlen' hops, and returns it as a list of
Router instances"""
@@ -1160,9 +1167,7 @@
self.sorted_r.remove(self.routers[r.idhex])
del self.routers[r.idhex]
for i in xrange(len(self.sorted_r)): self.sorted_r[i].list_rank = i
- self.selmgr.path_selector.entry_gen.rebuild()
- self.selmgr.path_selector.mid_gen.rebuild()
- self.selmgr.path_selector.exit_gen.rebuild()
+ self.selmgr.path_selector.rebuild_gens(self.sorted_r)
del self.circuits[c.circ_id]
for stream in circ.pending_streams:
plog("DEBUG", "Finding new circ for " + str(stream.strm_id))
@@ -1289,21 +1294,14 @@
def ns_event(self, n):
self.read_routers(n.nslist)
- # FIXME: Hrmm.. this is poor encapsulation..
- # Maybe also pass in sorted_r?
- self.selmgr.path_selector.entry_gen.rebuild()
- self.selmgr.path_selector.mid_gen.rebuild()
- self.selmgr.path_selector.exit_gen.rebuild()
+ self.selmgr.path_selector.rebuild_gens(self.sorted_r)
plog("DEBUG", "Read " + str(len(n.nslist))+" NS => "
+ str(len(self.sorted_r)) + " routers")
def new_desc_event(self, d):
for i in d.idlist: # Is this too slow?
self.read_routers(self.c.get_network_status("id/"+i))
- # FIXME: Hrmm.. this is poor encapsulation..
- self.selmgr.path_selector.entry_gen.rebuild()
- self.selmgr.path_selector.mid_gen.rebuild()
- self.selmgr.path_selector.exit_gen.rebuild()
+ self.selmgr.path_selector.rebuild_gens(self.sorted_r)
plog("DEBUG", "Read " + str(len(d.idlist))+" Desc => "
+ str(len(self.sorted_r)) + " routers")
Modified: torctl/trunk/python/TorCtl/StatsSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/StatsSupport.py 2009-01-17 00:15:57 UTC (rev 18137)
+++ torctl/trunk/python/TorCtl/StatsSupport.py 2009-01-17 00:17:59 UTC (rev 18138)
@@ -340,8 +340,8 @@
class StatsHandler(PathSupport.PathBuilder):
"""An extension of PathSupport.PathBuilder that keeps track of
router statistics for every circuit and stream"""
- def __init__(self, c, slmgr):
- PathBuilder.__init__(self, c, slmgr, StatsRouter)
+ def __init__(self, c, slmgr, RouterClass=StatsRouter):
+ PathBuilder.__init__(self, c, slmgr, RouterClass)
self.circ_count = 0
self.strm_count = 0
self.strm_failed = 0
@@ -675,7 +675,6 @@
PathBuilder.stream_status_event(self, s)
def ns_event(self, n):
- # XXX: Non-Running routers are stripped here..
PathBuilder.ns_event(self, n)
now = n.arrived_at
for ns in n.nslist: