commit 7a802e22fa12398ab33207f67414dbc1c7d4c223
Author: juga0 <juga(a)riseup.net>
Date: Fri Mar 8 16:06:41 2019 +0000
chg: !minor Replace consensus count by the name
used in the bandwidth file, so that it is less confusing and less
prone to errors.
---
sbws/lib/relaylist.py | 8 ++++----
sbws/lib/resultdump.py | 31 +++++++++++++++++++------------
sbws/lib/v3bwfile.py | 15 ++++++++-------
tests/unit/conftest.py | 4 ++--
4 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index 3857718..880f88e 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -206,7 +206,7 @@ class Relay:
self._remove_old_consensus_timestamps()
@property
- def consensus_count(self):
+ def relay_in_recent_consensus_count(self):
"""Number of times the relay was in a conensus."""
return len(self._consensus_timestamps)
@@ -371,13 +371,13 @@ class RelayList:
log.info("Number of consensuses obtained in the last %s days: %s.",
int(self._measurements_period / 24 / 60 / 60),
- self.consensus_count)
+ self.recent_consensus_count)
# NOTE: blocking, writes to file!
if self._state is not None:
- self._state['consensus_count'] = self.consensus_count
+ self._state['recent_consensus_count'] = self.recent_consensus_count
@property
- def consensus_count(self):
+ def recent_consensus_count(self):
"""Number of times a new consensus was obtained."""
return len(self._consensus_timestamps)
diff --git a/sbws/lib/resultdump.py b/sbws/lib/resultdump.py
index c081b61..f904925 100644
--- a/sbws/lib/resultdump.py
+++ b/sbws/lib/resultdump.py
@@ -205,7 +205,7 @@ class Result:
average_bandwidth=None, burst_bandwidth=None,
observed_bandwidth=None, consensus_bandwidth=None,
consensus_bandwidth_is_unmeasured=None,
- consensus_count=None):
+ relay_in_recent_consensus_count=None):
self.fingerprint = fingerprint
self.nickname = nickname
self.address = address
@@ -217,10 +217,11 @@ class Result:
self.consensus_bandwidth_is_unmeasured = \
consensus_bandwidth_is_unmeasured
# The number of times the relay was in a consensus.
- self.consensus_count = consensus_count
+ self.relay_in_recent_consensus_count = \
+ relay_in_recent_consensus_count
def __init__(self, relay, circ, dest_url, scanner_nick, t=None,
- consensus_count=None):
+ relay_in_recent_consensus_count=None):
self._relay = Result.Relay(relay.fingerprint, relay.nickname,
relay.address, relay.master_key_ed25519,
relay.average_bandwidth,
@@ -228,7 +229,7 @@ class Result:
relay.observed_bandwidth,
relay.consensus_bandwidth,
relay.consensus_bandwidth_is_unmeasured,
- relay.consensus_count)
+ relay.relay_in_recent_consensus_count)
self._circ = circ
self._dest_url = dest_url
self._scanner = scanner_nick
@@ -275,9 +276,9 @@ class Result:
return self._relay.master_key_ed25519
@property
- def consensus_count(self):
+ def relay_in_recent_consensus_count(self):
"""Number of times the relay was in a consensus."""
- return self._relay.consensus_count
+ return self._relay.relay_in_recent_consensus_count
@property
def circ(self):
@@ -311,7 +312,8 @@ class Result:
'type': self.type,
'scanner': self.scanner,
'version': self.version,
- 'consensus_count': self.consensus_count,
+ 'relay_in_recent_consensus_count':
+ self.relay_in_recent_consensus_count,
}
@staticmethod
@@ -380,7 +382,8 @@ class ResultError(Result):
Result.Relay(
d['fingerprint'], d['nickname'], d['address'],
d['master_key_ed25519'],
- consensus_count=d.get('consensus_count', None)),
+ relay_in_recent_consensus_count= # noqa
+ d.get('relay_in_recent_consensus_count', None)), # noqa
d['circ'], d['dest_url'], d['scanner'],
msg=d['msg'], t=d['time'])
@@ -422,7 +425,8 @@ class ResultErrorCircuit(ResultError):
Result.Relay(
d['fingerprint'], d['nickname'], d['address'],
d['master_key_ed25519'],
- consensus_count=d.get('consensus_count', None)),
+ relay_in_recent_consensus_count= # noqa
+ d.get('relay_in_recent_consensus_count', None)), # noqa
d['circ'], d['dest_url'], d['scanner'],
msg=d['msg'], t=d['time'])
@@ -446,7 +450,8 @@ class ResultErrorStream(ResultError):
Result.Relay(
d['fingerprint'], d['nickname'], d['address'],
d['master_key_ed25519'],
- consensus_count=d.get('consensus_count', None)),
+ relay_in_recent_consensus_count= # noqa
+ d.get('relay_in_recent_consensus_count', None)), # noqa
d['circ'], d['dest_url'], d['scanner'],
msg=d['msg'], t=d['time'])
@@ -483,7 +488,8 @@ class ResultErrorAuth(ResultError):
Result.Relay(
d['fingerprint'], d['nickname'], d['address'],
d['master_key_ed25519'],
- consensus_count=d.get('consensus_count', None)),
+ relay_in_recent_consensus_count= # noqa
+ d.get('relay_in_recent_consensus_count', None)), # noqa
d['circ'], d['dest_url'], d['scanner'],
msg=d['msg'], t=d['time'])
@@ -521,7 +527,8 @@ class ResultSuccess(Result):
d.get('relay_burst_bandwidth'), d['relay_observed_bandwidth'],
d.get('consensus_bandwidth'),
d.get('consensus_bandwidth_is_unmeasured'),
- consensus_count=d.get('consensus_count', None)),
+ relay_in_recent_consensus_count= # noqa
+ d.get('relay_in_recent_consensus_count', None)), # noqa
d['circ'], d['dest_url'], d['scanner'],
t=d['time'])
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index fa05fbc..997e35c 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -231,7 +231,7 @@ class V3BWHeader(object):
earliest_bandwidth = cls.earliest_bandwidth_from_results(results)
# NOTE: Blocking, reads file
generator_started = cls.generator_started_from_file(state_fpath)
- consensus_count = cls.consensus_count_from_file(state_fpath)
+ recent_consensus_count = cls.consensus_count_from_file(state_fpath)
timestamp = str(latest_bandwidth)
kwargs['latest_bandwidth'] = unixts_to_isodt_str(latest_bandwidth)
kwargs['earliest_bandwidth'] = unixts_to_isodt_str(earliest_bandwidth)
@@ -242,8 +242,8 @@ class V3BWHeader(object):
kwargs['scanner_country'] = scanner_country
if destinations_countries is not None:
kwargs['destinations_countries'] = destinations_countries
- if consensus_count is not None:
- kwargs['recent_consensus_count'] = str(consensus_count)
+ if recent_consensus_count is not None:
+ kwargs['recent_consensus_count'] = str(recent_consensus_count)
h = cls(timestamp, **kwargs)
return h
@@ -303,8 +303,8 @@ class V3BWHeader(object):
@staticmethod
def consensus_count_from_file(state_fpath):
state = State(state_fpath)
- if 'consensus_count' in state:
- return state['consensus_count']
+ if 'recent_consensus_count' in state:
+ return state['recent_consensus_count']
else:
return None
@@ -416,8 +416,9 @@ class V3BWLine(object):
kwargs['master_key_ed25519'] = results[0].master_key_ed25519
kwargs['time'] = cls.last_time_from_results(results)
kwargs.update(cls.result_types_from_results(results))
- consensuses_count = [r.consensus_count for r in results
- if getattr(r, 'consensus_count', None)]
+ consensuses_count = \
+ [r.relay_in_recent_consensus_count for r in results
+ if getattr(r, 'relay_in_recent_consensus_count', None)]
if consensuses_count:
consensus_count = max(consensuses_count)
kwargs['relay_in_recent_consensus_count'] = consensus_count
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
index f5d3d05..fa1143d 100644
--- a/tests/unit/conftest.py
+++ b/tests/unit/conftest.py
@@ -72,7 +72,7 @@ RELAY1 = Result.Relay(FP1, NICK1, IP1, ED25519,
average_bandwidth=AVG_BW, burst_bandwidth=BUR_BW,
observed_bandwidth=OBS_BW, consensus_bandwidth=BW,
consensus_bandwidth_is_unmeasured=UNMEASURED,
- consensus_count=2)
+ relay_in_recent_consensus_count=2)
RELAY2 = Result.Relay(FP2, NICK2, IP2, ED25519)
RESULT = Result(RELAY1, CIRC12, DEST_URL, SCANNER, t=TIME1)
@@ -96,7 +96,7 @@ RELAY_DICT = {
"relay_observed_bandwidth": OBS_BW,
"consensus_bandwidth": BW,
"consensus_bandwidth_is_unmeasured": UNMEASURED,
- "consensus_count": 2,
+ "relay_in_recent_consensus_count": 2,
}
BASE_RESULT_NO_RELAY_DICT = {