[tor-commits] [metrics-tasks/master] Treat unresolved AS numbers correctly (#6232).

karsten at torproject.org karsten at torproject.org
Tue Jul 24 10:11:21 UTC 2012


commit 4275170f5cbcd7332df77f7ca7a36618c27c269c
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Tue Jul 24 10:12:07 2012 +0200

    Treat unresolved AS numbers correctly (#6232).
    
    So far, relays that couldn't be found in the AS database were ignored in
    the AS entropy calculation.  That's not correct.  We have to treat them as
    "other" AS, similar to how we handle relays for which we couldn't find the
    country code.  Otherwise the probability of all ASes wouldn't sum up to 1.
---
 task-6232/pyentropy.py |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/task-6232/pyentropy.py b/task-6232/pyentropy.py
index dd5e343..8e28210 100644
--- a/task-6232/pyentropy.py
+++ b/task-6232/pyentropy.py
@@ -56,7 +56,7 @@ class Router:
             value = as_db.org_by_addr(str(ip)).split()
             return value[0]
         except:
-            return None
+            return ""
     
     def get_advertised_bw(self, hex_digest):
         try:
@@ -132,11 +132,10 @@ def run(file_name):
             bw_countries[router.country] += router.bandwidth
         else:
             bw_countries[router.country] = router.bandwidth        
-        if router.as_no:
-            if bw_as.has_key(router.as_no):
-                bw_as[router.as_no] += router.bandwidth
-            else:
-                bw_as[router.as_no] = router.bandwidth
+        if bw_as.has_key(router.as_no):
+            bw_as[router.as_no] += router.bandwidth
+        else:
+            bw_as[router.as_no] = router.bandwidth
     
     entropy, entropy_exit, entropy_guard, entropy_country, entropy_as = 0.0, 0.0, 0.0, 0.0, 0.0
     for router in routers:





More information about the tor-commits mailing list