Commit 9e089b72 authored by juga  's avatar juga
Browse files

relaylist: add property is_unmeasured

parent 7bb7c738
......@@ -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]
'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
......@@ -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,
exits = possible_exits[0:num_keep]
if len(exits) < 1:
log.warning("There are no exits to perform usability tests.")
......@@ -83,9 +83,16 @@ class Relay:
return self._from_desc('observed_bandwidth')
def bandwidth(self):
def consensus_bandwidth(self):
return self._from_ns('bandwidth')
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')
def address(self):
return self._from_ns('address')
......@@ -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:
if max_bw is not None and relay.bandwidth > max_bw:
if max_bw is not None and relay.consensus_bandwidth > max_bw:
return ret
......@@ -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 == ''
assert relay.master_key_ed25519 == \
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