commit cc14d90d7537ac1266cb3bc1b631a8a5da35284a Author: juga0 juga@riseup.net Date: Thu Feb 7 20:05:40 2019 +0000
new: scanner: Return the new possible errors
when mesuring the relay.
Part of #28567. --- sbws/core/scanner.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py index 73d0b0e..98fa305 100644 --- a/sbws/core/scanner.py +++ b/sbws/core/scanner.py @@ -11,8 +11,10 @@ from multiprocessing.context import TimeoutError
from ..lib.circuitbuilder import GapsCircuitBuilder as CB from ..lib.resultdump import ResultDump -from ..lib.resultdump import ResultSuccess, ResultErrorCircuit -from ..lib.resultdump import ResultErrorStream +from ..lib.resultdump import ( + ResultSuccess, ResultErrorCircuit, ResultErrorStream, + ResultErrorSecondRelay, ResultError, # ResultErrorDestination + ) from ..lib.relaylist import RelayList from ..lib.relayprioritizer import RelayPrioritizer from ..lib.destination import (DestinationList, @@ -240,11 +242,22 @@ def measure_relay(args, conf, destinations, cb, rl, relay):
""" log.debug('Measuring %s %s', relay.nickname, relay.fingerprint) + our_nick = conf['scanner']['nickname'] s = requests_utils.make_session( cb.controller, conf.getfloat('general', 'http_timeout')) # Probably because the scanner is stopping. if s is None: - return None + if settings.end_event.is_set(): + return None + else: + # In future refactor this should be returned from the make_session + reason = "Unable to get proxies." + log.debug(reason + ' to measure %s %s', + relay.nickname, relay.fingerprint) + return [ + ResultError(relay, [], '', our_nick, + msg=reason), + ] # Pick a destionation dest = destinations.next() # If there is no any destination at this point, it can not continue. @@ -256,6 +269,14 @@ def measure_relay(args, conf, destinations, cb, rl, relay): "the scanner can continue if one fails.") # Exit the scanner with error stopping threads first. stop_threads(signal.SIGTERM, None, 1) + # When the destinations can recover would be implemented; + # reason = 'Unable to get destination' + # log.debug(reason + ' to measure %s %s', + # relay.nickname, relay.fingerprint) + # return [ + # ResultErrorDestination(relay, [], dest.url, our_nick, + # msg=reason), + # ] # Pick a relay to help us measure the given relay. If the given relay is an # exit, then pick a non-exit. Otherwise pick an exit. helper = None @@ -274,14 +295,15 @@ def measure_relay(args, conf, destinations, cb, rl, relay): circ_fps = [relay.fingerprint, helper.fingerprint] nicknames = [relay.nickname, helper.nickname] if not helper: - # TODO: Return ResultError of some sort - log.debug('Unable to pick a 2nd relay to help measure %s (%s)', + reason = 'Unable to select a second relay' + log.debug(reason + ' to help measure %s (%s)', relay.fingerprint, relay.nickname) - return None - assert helper - assert circ_fps is not None and len(circ_fps) == 2 + return [ + ResultErrorSecondRelay(relay, [], dest.url, our_nick, + msg=reason), + ] + # Build the circuit - our_nick = conf['scanner']['nickname'] circ_id, reason = cb.build_circuit(circ_fps) if not circ_id: log.debug('Could not build circuit with path %s (%s): %s ',
tor-commits@lists.torproject.org