GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit d4fe347c authored by juga  's avatar juga
Browse files

chg: v3bwfile: Percentage difference with consensus

parent d72fe2ee
...@@ -1077,7 +1077,9 @@ class V3BWFile(object): ...@@ -1077,7 +1077,9 @@ class V3BWFile(object):
bw_lines = cls.bw_kb(bw_lines_raw) bw_lines = cls.bw_kb(bw_lines_raw)
# log.debug(bw_lines[-1]) # log.debug(bw_lines[-1])
# Not using the result for now, just warning # Not using the result for now, just warning
cls.is_max_bw_diff_perc_reached(bw_lines, max_bw_diff_perc) cls.is_max_bw_diff_perc_reached(
bw_lines, max_bw_diff_perc, router_statuses_d
)
header.add_time_report_half_network() header.add_time_report_half_network()
f = cls(header, bw_lines + bw_lines_excluded) f = cls(header, bw_lines + bw_lines_excluded)
return f return f
...@@ -1159,18 +1161,22 @@ class V3BWFile(object): ...@@ -1159,18 +1161,22 @@ class V3BWFile(object):
@staticmethod @staticmethod
def is_max_bw_diff_perc_reached(bw_lines, def is_max_bw_diff_perc_reached(bw_lines,
max_bw_diff_perc=MAX_BW_DIFF_PERC): max_bw_diff_perc=MAX_BW_DIFF_PERC,
# Since old versions were not storing consensus bandwidth, use getattr. router_statuses_d=None):
sum_consensus_bw = sum([l.consensus_bandwidth for l in bw_lines if router_statuses_d:
if getattr(l, 'consensus_bandwidth', None)]) sum_consensus_bw = sum(list(map(
lambda x: x.bandwidth * 1000,
router_statuses_d.values()
)))
else:
sum_consensus_bw = sum([
l.consensus_bandwidth for l in bw_lines
if getattr(l, 'consensus_bandwidth', None)
])
# Because the scaled bandwidth is in KB, but not the stored consensus # Because the scaled bandwidth is in KB, but not the stored consensus
# bandwidth, multiply by 1000. # bandwidth, multiply by 1000.
# Do not count 1 bandwidths for the relays that were excluded # Do not count the bandwidths for the relays that were excluded
# and exclude also the bw of the relays that did not stored consensus, sum_bw = sum([l.bw for l in bw_lines if getattr(l, "vote", 1)]) * 1000
# since they are not included either in the sum of the consensus.
sum_bw = sum([l.bw for l in bw_lines
if getattr(l, 'consensus_bandwidth', None)
and getattr(l, 'unmeasured', 0) == 0]) * 1000
# Percentage difference # Percentage difference
diff_perc = ( diff_perc = (
abs(sum_consensus_bw - sum_bw) abs(sum_consensus_bw - sum_bw)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment