Commit 3d47a3b0 authored by Matt Traudt's avatar Matt Traudt Committed by juga
Browse files

Remove unnecessary fp_or_nick_to_relay function

parent c56eeaa9
......@@ -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
......
......@@ -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 '''
......
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
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