Commit b2eeda23 authored by juga's avatar juga
Browse files

destination, scanner: choose exits with same flags

The flags are: not having a badflag and the policy allows to exit
to a port.
parent 2e100e81
......@@ -136,8 +136,8 @@ def _pick_ideal_second_hop(relay, dest, rl, cont, is_exit):
destination **dest**, pick a second relay that is or is not an exit
according to **is_exit**.
candidates = []
candidates.extend(rl.exits if is_exit else rl.non_exits)
candidates = rl.exits_not_bad_allowing_port(dest.port) if is_exit \
else rl.non_exits
if not len(candidates):
return None
log.debug('Picking a 2nd hop to measure %s from %d choices. is_exit=%s',
......@@ -177,8 +177,7 @@ def measure_relay(args, conf, destinations, cb, rl, relay):
# exit, then pick a non-exit. Otherwise pick an exit.
helper = None
circ_fps = None
if relay.can_exit_to(dest.hostname, dest.port) and \
relay not in rl.bad_exits:
if relay.is_exit_not_bad_allowing_port(dest.port):
helper = _pick_ideal_second_hop(
relay, dest, rl, cb.controller, is_exit=False)
if helper:
......@@ -179,8 +179,7 @@ class DestinationList:
session = requests_utils.make_session(cont, timeout)
usable_dests = []
for dest in self._all_dests:
possible_exits = [e for e in self._rl.exits
if e.can_exit_to(dest.hostname, dest.port)]
possible_exits = self._rl.exits_not_bad_allowing_port(dest.port)
# Keep the fastest 10% of exits, or 3, whichever is larger
num_keep = int(max(3, len(possible_exits) * 0.1))
possible_exits = sorted(
......@@ -231,7 +231,6 @@ class RelayList:
self._relays = self._init_relays()
self._last_refresh = time.time()
def exits_not_bad_allowing_port(self, port):
return [r for r in self.exits
if r.is_exit_not_bad_allowing_port(port)]
Supports Markdown
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