[or-cvs] r15297: Rename NodeGenerator.next_r() to generate(), which makes a l (torflow/branches/gsoc2008/TorCtl)

mikeperry at seul.org mikeperry at seul.org
Mon Jun 16 02:25:49 UTC 2008


Author: mikeperry
Date: 2008-06-15 22:25:49 -0400 (Sun, 15 Jun 2008)
New Revision: 15297

Modified:
   torflow/branches/gsoc2008/TorCtl/PathSupport.py
Log:

Rename NodeGenerator.next_r() to generate(), which makes a
lot more sense. Hopefully not too many people have custom
node generators out there. I imagine not.



Modified: torflow/branches/gsoc2008/TorCtl/PathSupport.py
===================================================================
--- torflow/branches/gsoc2008/TorCtl/PathSupport.py	2008-06-16 02:08:30 UTC (rev 15296)
+++ torflow/branches/gsoc2008/TorCtl/PathSupport.py	2008-06-16 02:25:49 UTC (rev 15297)
@@ -157,8 +157,8 @@
     "Return true if all the routers have been marked as chosen"
     return not self.routers
 
-  def next_r(self):
-    "Yield the next router according to the policy"
+  def generate(self):
+    "Return a python generator that yields routers according to the policy"
     raise NotImplemented()
 
 class Connection(TorCtl.Connection):
@@ -495,7 +495,7 @@
 
 class UniformGenerator(NodeGenerator):
   """NodeGenerator that produces nodes in the uniform distribution"""
-  def next_r(self):
+  def generate(self):
     while not self.all_chosen():
       r = random.choice(self.routers)
       if self.rstr_list.r_is_ok(r): yield r
@@ -525,7 +525,7 @@
   def all_chosen(self):
     return self.last_idx == self.next_exit_by_port[self.to_port]
 
-  def next_r(self):
+  def generate(self):
     while True: # A do..while would be real nice here..
       if self.next_exit_by_port[self.to_port] >= len(self.sorted_r):
         self.next_exit_by_port[self.to_port] = 0
@@ -635,7 +635,7 @@
           +". The exit-weight is: "+str(self.exit_weight)
           + ", guard weight is: "+str(self.guard_weight))
 
-  def next_r(self):
+  def generate(self):
     while True:
       # Choose a suitable random int
       i = random.randint(0, self.total_weighted_bw)
@@ -683,9 +683,9 @@
     self.entry_gen.rewind()
     self.mid_gen.rewind()
     self.exit_gen.rewind()
-    entry = self.entry_gen.next_r()
-    mid = self.mid_gen.next_r()
-    ext = self.exit_gen.next_r()
+    entry = self.entry_gen.generate()
+    mid = self.mid_gen.generate()
+    ext = self.exit_gen.generate()
 
     while True:
       path = []
@@ -708,9 +708,9 @@
         self.entry_gen.rewind()
         self.mid_gen.rewind()
         self.exit_gen.rewind()
-        entry = self.entry_gen.next_r()
-        mid = self.entry_gen.next_r()
-        ext = self.entry_gen.next_r()
+        entry = self.entry_gen.generate()
+        mid = self.entry_gen.generate()
+        ext = self.entry_gen.generate()
     return path
 
 class SelectionManager:
@@ -1557,7 +1557,7 @@
   TorUtil.loglevel = "INFO"
 
   #gen.rewind() - Just overhead if we create a fresh generator each time
-  rtrs = gen.next_r()
+  rtrs = gen.generate()
   for i in xrange(1, trials):
     r = rtrs.next()
     r.chosen += 1
@@ -1681,7 +1681,7 @@
   ug = UniformGenerator(sorted_rlist, exit_rstr)
 
   rlist = []
-  for r in ug.next_r():
+  for r in ug.generate():
     print "Checking: " + r.nickname
     for rs in rl:
       if not rs.r_is_ok(r):



More information about the tor-commits mailing list