]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Avoid errors in updateFallbackDirs.py when there are no fallbacks
authorteor (Tim Wilson-Brown) <teor2345@gmail.com>
Wed, 22 Jun 2016 01:04:54 +0000 (11:04 +1000)
committerteor (Tim Wilson-Brown) <teor2345@gmail.com>
Wed, 22 Jun 2016 01:56:31 +0000 (11:56 +1000)
scripts/maint/updateFallbackDirs.py

index 7fcb3658c469d295a4a5904ba23b9ea9534b44c0..d17e702b6fd52c991cc99a82607cd8165a8fc8be 100755 (executable)
@@ -1408,7 +1408,11 @@ class CandidateList(dict):
   def calculate_measured_bandwidth(self):
     self.sort_fallbacks_by_cw_to_bw_factor()
     median_fallback = self.fallback_median(True)
-    median_cw_to_bw_factor = median_fallback.cw_to_bw_factor()
+    if median_fallback is not None:
+      median_cw_to_bw_factor = median_fallback.cw_to_bw_factor()
+    else:
+      # this will never be used, because there are no fallbacks
+      median_cw_to_bw_factor = None
     for f in self.fallbacks:
       f.set_measured_bandwidth(median_cw_to_bw_factor)
 
@@ -1593,7 +1597,11 @@ class CandidateList(dict):
   # return a string that describes a/b as a percentage
   @staticmethod
   def describe_percentage(a, b):
-    return '%d/%d = %.0f%%'%(a, b, (a*100.0)/b)
+    if b != 0:
+      return '%d/%d = %.0f%%'%(a, b, (a*100.0)/b)
+    else:
+      # technically, 0/0 is undefined, but 0.0% is a sensible result
+      return '%d/%d = %.0f%%'%(a, b, 0.0)
 
   # return a dictionary of lists of fallbacks by IPv4 netblock
   # the dictionary is keyed by the fingerprint of an arbitrary fallback