[or-cvs] r19632: {torflow} Add Alpha weighting support described in proposal 161 to agg (torflow/trunk/NetworkScanners/BwAuthority)

mikeperry at seul.org mikeperry at seul.org
Fri Jun 5 12:22:36 UTC 2009


Author: mikeperry
Date: 2009-06-05 08:22:36 -0400 (Fri, 05 Jun 2009)
New Revision: 19632

Modified:
   torflow/trunk/NetworkScanners/BwAuthority/aggregate.py
Log:

Add Alpha weighting support described in proposal 161 to
aggregator script.



Modified: torflow/trunk/NetworkScanners/BwAuthority/aggregate.py
===================================================================
--- torflow/trunk/NetworkScanners/BwAuthority/aggregate.py	2009-06-05 12:21:02 UTC (rev 19631)
+++ torflow/trunk/NetworkScanners/BwAuthority/aggregate.py	2009-06-05 12:22:36 UTC (rev 19632)
@@ -3,16 +3,17 @@
 import re
 import math
 import sys
+import socket
 
+sys.path.append("../../")
+from TorCtl.TorUtil import plog
+from TorCtl import TorCtl,TorUtil
+
 bw_files = {}
 nodes = {}
+prev_consensus = {}
+ALPHA = 0.3333 # Prev consensus values count for 1/3 of the avg 
 
-# XXX: Alpha smoothing, here or in tor?
-#      - Tor, because we want to be able to opine about stuff
-#        we did not measure this round
-#      - Or maybe that's an argument for reading the whole consensus
-#        and doing it here.. but that will always be one behind..
-
 def base10_round(bw_val):
   # This keeps the first 3 decimal digits of the bw value only
   # to minimize changes for consensus diffs.
@@ -79,6 +80,20 @@
     self.ns_bw = int(re.search("[\s]*ns_bw=([\S]+)[\s]*", line).group(1))
 
 def main(argv):
+  TorUtil.read_config(argv[1]+"/scanner.1/bwauthority.cfg")
+ 
+  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+  s.connect((TorUtil.control_host,TorUtil.control_port))
+  c = TorCtl.Connection(s)
+  c.authenticate_cookie(file(argv[1]+"/scanner.1/tor-data/control_auth_cookie",
+                              "r"))
+  ns_list = c.get_network_status()
+  for n in ns_list:
+    if n.bandwidth == None:
+      plog("ERROR", "Your Tor is not providing NS w bandwidths!")
+      sys.exit(0)
+    prev_consensus["$"+n.idhex] = n
+
   for da in argv[1:-1]:
     # First, create a list of the most recent files in the
     # scan dirs that are recent enough
@@ -138,9 +153,11 @@
     if closest_to_one((n.sbw_ratio, n.fbw_ratio)) == 0:
       n.ratio = n.sbw_ratio
       n.new_bw = n.ns_bw[n.chosen_sbw]*n.ratio
-    else: 
+    else:
       n.ratio = n.fbw_ratio
       n.new_bw = n.ns_bw[n.chosen_fbw]*n.ratio
+    if n.idhex in prev_consensus:
+      n.new_bw = ((prev_consensus[n.idhex].bandwidth*ALPHA + n.new_bw)/(ALPHA + 1))/1024.0
 
   n_print = nodes.values()
   n_print.sort(lambda x,y: int(x.new_bw) - int(y.new_bw))



More information about the tor-commits mailing list