mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 06:48:05 +01:00
Avoid errors in updateFallbackDirs.py when there are no fallbacks
This commit is contained in:
parent
6ce53668f4
commit
4090612246
1 changed files with 10 additions and 2 deletions
|
@ -1408,7 +1408,11 @@ class CandidateList(dict):
|
||||||
def calculate_measured_bandwidth(self):
|
def calculate_measured_bandwidth(self):
|
||||||
self.sort_fallbacks_by_cw_to_bw_factor()
|
self.sort_fallbacks_by_cw_to_bw_factor()
|
||||||
median_fallback = self.fallback_median(True)
|
median_fallback = self.fallback_median(True)
|
||||||
|
if median_fallback is not None:
|
||||||
median_cw_to_bw_factor = median_fallback.cw_to_bw_factor()
|
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:
|
for f in self.fallbacks:
|
||||||
f.set_measured_bandwidth(median_cw_to_bw_factor)
|
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
|
# return a string that describes a/b as a percentage
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def describe_percentage(a, b):
|
def describe_percentage(a, b):
|
||||||
|
if b != 0:
|
||||||
return '%d/%d = %.0f%%'%(a, b, (a*100.0)/b)
|
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
|
# return a dictionary of lists of fallbacks by IPv4 netblock
|
||||||
# the dictionary is keyed by the fingerprint of an arbitrary fallback
|
# the dictionary is keyed by the fingerprint of an arbitrary fallback
|
||||||
|
|
Loading…
Add table
Reference in a new issue