[tor-commits] [sbws/master] relaylist: add property is_unmeasured

juga at torproject.org juga at torproject.org
Mon Dec 3 21:27:35 UTC 2018


commit 9e089b72d8abfb2b2a6c2ec9a66cb01d115205a6
Author: juga0 <juga at riseup.net>
Date:   Sat Dec 1 10:25:01 2018 +0000

    relaylist: add property is_unmeasured
---
 sbws/core/scanner.py                    | 8 ++++----
 sbws/lib/destination.py                 | 3 ++-
 sbws/lib/relaylist.py                   | 9 ++++++++-
 sbws/util/stem.py                       | 6 +++---
 tests/integration/lib/test_relaylist.py | 2 +-
 5 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index 6188a19..e065666 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -143,7 +143,7 @@ def _pick_ideal_second_hop(relay, dest, rl, cont, is_exit):
     log.debug('Picking a 2nd hop to measure %s from %d choices. is_exit=%s',
               relay.nickname, len(candidates), is_exit)
     for min_bw_factor in [2, 1.75, 1.5, 1.25, 1]:
-        min_bw = relay.bandwidth * min_bw_factor
+        min_bw = relay.consensus_bandwidth * min_bw_factor
         new_candidates = stem_utils.only_relays_with_bandwidth(
             cont, candidates, min_bw=min_bw)
         if len(new_candidates) > 0:
@@ -152,15 +152,15 @@ def _pick_ideal_second_hop(relay, dest, rl, cont, is_exit):
                 'Found %d candidate 2nd hops with at least %sx the bandwidth '
                 'of %s. Returning %s (bw=%s).',
                 len(new_candidates), min_bw_factor, relay.nickname,
-                chosen.nickname, chosen.bandwidth)
+                chosen.nickname, chosen.consensus_bandwidth)
             return chosen
     candidates = sorted(candidates, key=lambda r: r.bandwidth, reverse=True)
     chosen = candidates[0]
     log.debug(
         'Didn\'t find any 2nd hops at least as fast as %s (bw=%s). It\'s '
         'probably really fast. Returning %s (bw=%s), the fastest '
-        'candidate we have.', relay.nickname, relay.bandwidth,
-        chosen.nickname, chosen.bandwidth)
+        'candidate we have.', relay.nickname, relay.consensus_bandwidth,
+        chosen.nickname, chosen.consensus_bandwidth)
     return chosen
 
 
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index d01fd04..cfa6cda 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -184,7 +184,8 @@ class DestinationList:
             # Keep the fastest 10% of exits, or 3, whichever is larger
             num_keep = int(max(3, len(possible_exits) * 0.1))
             possible_exits = sorted(
-                possible_exits, key=lambda e: e.bandwidth, reverse=True)
+                possible_exits, key=lambda e: e.consensus_bandwidth,
+                reverse=True)
             exits = possible_exits[0:num_keep]
             if len(exits) < 1:
                 log.warning("There are no exits to perform usability tests.")
diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index 5ec9252..c61e24e 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -83,10 +83,17 @@ class Relay:
         return self._from_desc('observed_bandwidth')
 
     @property
-    def bandwidth(self):
+    def consensus_bandwidth(self):
         return self._from_ns('bandwidth')
 
     @property
+    def consensus_bandwidth_is_unmeasured(self):
+        # measured appears only votes, unmeasured appears in consensus
+        # therefore is_unmeasured is needed to know whether the bandwidth
+        # value in consensus is comming from bwauth measurements or not.
+        return self._from_ns('is_unmeasured')
+
+    @property
     def address(self):
         return self._from_ns('address')
 
diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 232be2a..c3fffd1 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -230,10 +230,10 @@ def only_relays_with_bandwidth(controller, relays, min_bw=None, max_bw=None):
     assert max_bw is None or max_bw >= 0
     ret = []
     for relay in relays:
-        assert hasattr(relay, 'bandwidth')
-        if min_bw is not None and relay.bandwidth < min_bw:
+        assert hasattr(relay, 'consensus_bandwidth')
+        if min_bw is not None and relay.consensus_bandwidth < min_bw:
             continue
-        if max_bw is not None and relay.bandwidth > max_bw:
+        if max_bw is not None and relay.consensus_bandwidth > max_bw:
             continue
         ret.append(relay)
     return ret
diff --git a/tests/integration/lib/test_relaylist.py b/tests/integration/lib/test_relaylist.py
index 8488c8b..a1a5efb 100644
--- a/tests/integration/lib/test_relaylist.py
+++ b/tests/integration/lib/test_relaylist.py
@@ -11,7 +11,7 @@ def test_relay_properties(persistent_launch_tor):
     assert 'Authority' in relay.flags
     assert not relay.exit_policy or not relay.exit_policy.is_exiting_allowed()
     assert relay.average_bandwidth == 1073741824
-    assert relay.bandwidth == 0
+    assert relay.consensus_bandwidth == 0
     assert relay.address == '127.10.0.1'
     assert relay.master_key_ed25519 == \
         'wLglSEw9/DHfpNrlrqjVRSnGLVWfnm0vYxkryH4aT6Q'





More information about the tor-commits mailing list