[tor-commits] [sbws/master] destination, scanner: choose exits with same flags

juga at torproject.org juga at torproject.org
Mon Dec 3 22:33:03 UTC 2018


commit b2eeda230bbcd82eaee419f9aced709274da2012
Author: juga0 <juga at riseup.net>
Date:   Thu Nov 22 14:25:50 2018 +0000

    destination, scanner: choose exits with same flags
    
    The flags are: not having a badflag and the policy allows to exit
    to a port.
---
 sbws/core/scanner.py    | 7 +++----
 sbws/lib/destination.py | 3 +--
 sbws/lib/relaylist.py   | 1 -
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index 6188a19..6c63b68 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -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:
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index d01fd04..ddbe6c8 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -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(
diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index 28802a1..17761a6 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -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)]





More information about the tor-commits mailing list