commit f2d231ef1325653967ba34c67fc95a17fe9b7c8f Author: juga0 juga@riseup.net Date: Fri Feb 8 09:13:12 2019 +0000
new: resultdump: Store relay consensus count
for every result that is stored.
Part of #28566. --- sbws/lib/resultdump.py | 32 ++++++++++++++++++++++++-------- tests/unit/conftest.py | 4 +++- 2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/sbws/lib/resultdump.py b/sbws/lib/resultdump.py index 39aeda4..c081b61 100644 --- a/sbws/lib/resultdump.py +++ b/sbws/lib/resultdump.py @@ -204,7 +204,8 @@ class Result: def __init__(self, fingerprint, nickname, address, master_key_ed25519, average_bandwidth=None, burst_bandwidth=None, observed_bandwidth=None, consensus_bandwidth=None, - consensus_bandwidth_is_unmeasured=None): + consensus_bandwidth_is_unmeasured=None, + consensus_count=None): self.fingerprint = fingerprint self.nickname = nickname self.address = address @@ -215,15 +216,19 @@ class Result: self.consensus_bandwidth = consensus_bandwidth self.consensus_bandwidth_is_unmeasured = \ consensus_bandwidth_is_unmeasured + # The number of times the relay was in a consensus. + self.consensus_count = consensus_count
- def __init__(self, relay, circ, dest_url, scanner_nick, t=None): + def __init__(self, relay, circ, dest_url, scanner_nick, t=None, + consensus_count=None): self._relay = Result.Relay(relay.fingerprint, relay.nickname, relay.address, relay.master_key_ed25519, relay.average_bandwidth, relay.burst_bandwidth, relay.observed_bandwidth, relay.consensus_bandwidth, - relay.consensus_bandwidth_is_unmeasured) + relay.consensus_bandwidth_is_unmeasured, + relay.consensus_count) self._circ = circ self._dest_url = dest_url self._scanner = scanner_nick @@ -270,6 +275,11 @@ class Result: return self._relay.master_key_ed25519
@property + def consensus_count(self): + """Number of times the relay was in a consensus.""" + return self._relay.consensus_count + + @property def circ(self): return self._circ
@@ -301,6 +311,7 @@ class Result: 'type': self.type, 'scanner': self.scanner, 'version': self.version, + 'consensus_count': self.consensus_count, }
@staticmethod @@ -368,7 +379,8 @@ class ResultError(Result): return ResultError( Result.Relay( d['fingerprint'], d['nickname'], d['address'], - d['master_key_ed25519']), + d['master_key_ed25519'], + consensus_count=d.get('consensus_count', None)), d['circ'], d['dest_url'], d['scanner'], msg=d['msg'], t=d['time'])
@@ -409,7 +421,8 @@ class ResultErrorCircuit(ResultError): return ResultErrorCircuit( Result.Relay( d['fingerprint'], d['nickname'], d['address'], - d['master_key_ed25519']), + d['master_key_ed25519'], + consensus_count=d.get('consensus_count', None)), d['circ'], d['dest_url'], d['scanner'], msg=d['msg'], t=d['time'])
@@ -432,7 +445,8 @@ class ResultErrorStream(ResultError): return ResultErrorStream( Result.Relay( d['fingerprint'], d['nickname'], d['address'], - d['master_key_ed25519']), + d['master_key_ed25519'], + consensus_count=d.get('consensus_count', None)), d['circ'], d['dest_url'], d['scanner'], msg=d['msg'], t=d['time'])
@@ -468,7 +482,8 @@ class ResultErrorAuth(ResultError): return ResultErrorAuth( Result.Relay( d['fingerprint'], d['nickname'], d['address'], - d['master_key_ed25519']), + d['master_key_ed25519'], + consensus_count=d.get('consensus_count', None)), d['circ'], d['dest_url'], d['scanner'], msg=d['msg'], t=d['time'])
@@ -505,7 +520,8 @@ class ResultSuccess(Result): d['master_key_ed25519'], d['relay_average_bandwidth'], d.get('relay_burst_bandwidth'), d['relay_observed_bandwidth'], d.get('consensus_bandwidth'), - d.get('consensus_bandwidth_is_unmeasured')), + d.get('consensus_bandwidth_is_unmeasured'), + consensus_count=d.get('consensus_count', None)), d['circ'], d['dest_url'], d['scanner'], t=d['time'])
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index ada1b9b..f5d3d05 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -71,7 +71,8 @@ UNMEASURED = False 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_bandwidth_is_unmeasured=UNMEASURED, + consensus_count=2) RELAY2 = Result.Relay(FP2, NICK2, IP2, ED25519)
RESULT = Result(RELAY1, CIRC12, DEST_URL, SCANNER, t=TIME1) @@ -95,6 +96,7 @@ RELAY_DICT = { "relay_observed_bandwidth": OBS_BW, "consensus_bandwidth": BW, "consensus_bandwidth_is_unmeasured": UNMEASURED, + "consensus_count": 2, }
BASE_RESULT_NO_RELAY_DICT = {
tor-commits@lists.torproject.org