[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/master] Remove unnecessary fp_or_nick_to_relay function



commit 3d47a3b02c7eb1dc91d019493edf9bc96440e7bb
Author: Matt Traudt <sirmatt@xxxxxxx>
Date:   Thu Jun 7 20:59:22 2018 -0400

    Remove unnecessary fp_or_nick_to_relay function
---
 sbws/lib/circuitbuilder.py          | 23 +++++------------------
 sbws/util/stem.py                   | 11 -----------
 tests/integration/util/test_stem.py | 32 --------------------------------
 3 files changed, 5 insertions(+), 61 deletions(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index ac5603b..3c6c0fd 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -2,7 +2,7 @@ from stem import CircuitExtensionFailed, InvalidRequest, ProtocolError, Timeout
 from stem import InvalidArguments
 import random
 import sbws.util.stem as stem_utils
-from .relaylist import RelayList
+from .relaylist import Relay, RelayList
 import logging
 
 log = logging.getLogger(__name__)
@@ -125,9 +125,9 @@ class GapsCircuitBuilder(CircuitBuilder):
             if not fp:
                 new_path.append(None)
                 continue
-            relay = stem_utils.fp_or_nick_to_relay(self.controller, fp)
-            if not relay:
-                log.debug('Failed to get descriptor for relay %s', fp)
+            relay = Relay(fp, self.controller)
+            if not relay.fingerprint:
+                log.debug('Tor seems to no longer think %s is a relay', fp)
                 return None
             new_path.append(relay)
         return new_path
@@ -147,20 +147,7 @@ class GapsCircuitBuilder(CircuitBuilder):
                 continue
             chosen_fps.append(choice)
             black_fps.append(choice)
-        relays = []
-        for fp in chosen_fps:
-            relay = stem_utils.fp_or_nick_to_relay(self.controller, fp)
-            if not relay:
-                log.warning(
-                    'We\'re selecting a handful of random relays and stem '
-                    'doesn\'t think one of the fingerprints we gave it goes '
-                    'to a relay. Maybe we got a new consensus since the last '
-                    'time we refreshed our list of relays. In any case, we '
-                    'could try to recover. But failing inside '
-                    '_random_sample_relays is easier. Sorry.')
-                return None
-            relays.append(relay)
-        return relays
+        return [Relay(fp, self.controller) for fp in chosen_fps]
 
     def build_circuit(self, path):
         ''' <path> is a list of relays and Falsey values. Relays can be
diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 0341d74..8a92673 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -14,17 +14,6 @@ log = logging.getLogger(__name__)
 stream_building_lock = RLock()
 
 
-def fp_or_nick_to_relay(controller, fp_nick):
-    ''' Takes a string that could be either a relay's fingerprint or nickname.
-    Return the relay's descriptor if found. Otherwise return None.
-
-    Note that if a nickname is given and multiple relays have that nickname,
-    only one of them will be returned. '''
-    assert isinstance(fp_nick, str)
-    assert is_controller_okay(controller)
-    return controller.get_network_status(fp_nick, default=None)
-
-
 def attach_stream_to_circuit_listener(controller, circ_id):
     ''' Returns a function that should be given to add_event_listener(). It
     looks for newly created streams and attaches them to the given circ_id '''
diff --git a/tests/integration/util/test_stem.py b/tests/integration/util/test_stem.py
index 1591d2d..203cf5d 100644
--- a/tests/integration/util/test_stem.py
+++ b/tests/integration/util/test_stem.py
@@ -1,39 +1,7 @@
 import sbws.util.stem as stem_utils
-from stem.descriptor.router_status_entry import RouterStatusEntryV3
 
 
 def test_launch_and_okay(persistent_launch_tor):
     cont = persistent_launch_tor
     assert stem_utils.is_controller_okay(cont)
     assert stem_utils.is_bootstrapped(cont)
-
-
-def test_get_relay_from_fp(persistent_launch_tor):
-    cont = persistent_launch_tor
-    # AA45C13025C037F056E734169891878ED0880231 is auth1
-    relay = stem_utils.fp_or_nick_to_relay(
-        cont, 'AA45C13025C037F056E734169891878ED0880231')
-    assert isinstance(relay, RouterStatusEntryV3)
-    assert relay.fingerprint == 'AA45C13025C037F056E734169891878ED0880231'
-    assert relay.nickname == 'auth1'
-
-
-def test_get_relay_from_nick(persistent_launch_tor):
-    cont = persistent_launch_tor
-    # AA45C13025C037F056E734169891878ED0880231 is auth1
-    relay = stem_utils.fp_or_nick_to_relay(cont, 'auth1')
-    assert isinstance(relay, RouterStatusEntryV3)
-    assert relay.fingerprint == 'AA45C13025C037F056E734169891878ED0880231'
-    assert relay.nickname == 'auth1'
-
-
-def test_get_relay_from_bad_nick(persistent_launch_tor):
-    cont = persistent_launch_tor
-    relay = stem_utils.fp_or_nick_to_relay(cont, 'notarelaynick')
-    assert relay is None
-
-
-def test_get_relay_from_bad_fp(persistent_launch_tor):
-    cont = persistent_launch_tor
-    relay = stem_utils.fp_or_nick_to_relay(cont, 'A'*40)
-    assert relay is None



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits