Loading sbws/core/scanner.py +10 −3 Original line number Diff line number Diff line Loading @@ -240,6 +240,9 @@ def measure_relay(args, conf, destinations, cb, rl, relay): log.debug('Measuring %s %s', relay.nickname, relay.fingerprint) s = requests_utils.make_session( cb.controller, conf.getfloat('general', 'http_timeout')) # Probably because the scanner is stopping. if s is None: return None # Pick a destionation dest = destinations.next() # If there is no any destination at this point, it can not continue. Loading Loading @@ -401,13 +404,17 @@ def result_putter_error(target): measurement -- and return that function so it can be used by someone else ''' def closure(object): if settings.end_event.is_set(): return # The only object that can be here if there is not any uncatched # exception is stem.SocketClosed when stopping sbws # An exception here means that the worker thread finished. log.warning(FILLUP_TICKET_MSG) # To print the traceback that happened in the thread, not here in the # main process traceback.print_exception(type(object), object, object.__traceback__) # To print the traceback that happened in the thread, not here in # the main process. log.warning("".join(traceback.format_exception( type(object), object, object.__traceback__)) ) return closure Loading sbws/lib/circuitbuilder.py +1 −1 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ class CircuitBuilder: circ_id = c.new_circuit( path, await_build=True, timeout=timeout) except (InvalidRequest, CircuitExtensionFailed, ProtocolError, Timeout) as e: ProtocolError, Timeout, SocketClosed) as e: return None, str(e) return circ_id, None Loading sbws/util/requests.py +3 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ def make_session(controller, timeout): """ s = TimedSession() socks_info = stem_utils.get_socks_info(controller) # Probably because scanner is stopping. if socks_info is None: return None s.proxies = { 'http': 'socks5h://{}:{}'.format(*socks_info), 'https': 'socks5h://{}:{}'.format(*socks_info), Loading sbws/util/stem.py +12 −2 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import os from sbws.globals import fail_hard from sbws.globals import (TORRC_STARTING_POINT, TORRC_RUNTIME_OPTIONS, TORRC_OPTIONS_CAN_FAIL) from sbws import settings log = logging.getLogger(__name__) stream_building_lock = RLock() Loading Loading @@ -50,6 +51,11 @@ def add_event_listener(controller, func, event): def remove_event_listener(controller, func): try: controller.remove_event_listener(func) except SocketClosed as e: if not settings.end_event.is_set(): log.debug(e) else: log.exception(e) except ProtocolError as e: log.exception("Exception trying to remove event %s", e) Loading Loading @@ -245,9 +251,13 @@ def get_socks_info(controller): try: socks_ports = controller.get_listeners(Listener.SOCKS) return socks_ports[0] except SocketClosed as e: if not settings.end_event.is_set(): log.debug(e) # This might need to return the eception if this happen in other cases # than when stopping the scanner. except ControllerError as e: log.exception("Exception trying to get socks info: %e.", e) exit(1) log.debug(e) def only_relays_with_bandwidth(controller, relays, min_bw=None, max_bw=None): Loading Loading
sbws/core/scanner.py +10 −3 Original line number Diff line number Diff line Loading @@ -240,6 +240,9 @@ def measure_relay(args, conf, destinations, cb, rl, relay): log.debug('Measuring %s %s', relay.nickname, relay.fingerprint) s = requests_utils.make_session( cb.controller, conf.getfloat('general', 'http_timeout')) # Probably because the scanner is stopping. if s is None: return None # Pick a destionation dest = destinations.next() # If there is no any destination at this point, it can not continue. Loading Loading @@ -401,13 +404,17 @@ def result_putter_error(target): measurement -- and return that function so it can be used by someone else ''' def closure(object): if settings.end_event.is_set(): return # The only object that can be here if there is not any uncatched # exception is stem.SocketClosed when stopping sbws # An exception here means that the worker thread finished. log.warning(FILLUP_TICKET_MSG) # To print the traceback that happened in the thread, not here in the # main process traceback.print_exception(type(object), object, object.__traceback__) # To print the traceback that happened in the thread, not here in # the main process. log.warning("".join(traceback.format_exception( type(object), object, object.__traceback__)) ) return closure Loading
sbws/lib/circuitbuilder.py +1 −1 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ class CircuitBuilder: circ_id = c.new_circuit( path, await_build=True, timeout=timeout) except (InvalidRequest, CircuitExtensionFailed, ProtocolError, Timeout) as e: ProtocolError, Timeout, SocketClosed) as e: return None, str(e) return circ_id, None Loading
sbws/util/requests.py +3 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ def make_session(controller, timeout): """ s = TimedSession() socks_info = stem_utils.get_socks_info(controller) # Probably because scanner is stopping. if socks_info is None: return None s.proxies = { 'http': 'socks5h://{}:{}'.format(*socks_info), 'https': 'socks5h://{}:{}'.format(*socks_info), Loading
sbws/util/stem.py +12 −2 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import os from sbws.globals import fail_hard from sbws.globals import (TORRC_STARTING_POINT, TORRC_RUNTIME_OPTIONS, TORRC_OPTIONS_CAN_FAIL) from sbws import settings log = logging.getLogger(__name__) stream_building_lock = RLock() Loading Loading @@ -50,6 +51,11 @@ def add_event_listener(controller, func, event): def remove_event_listener(controller, func): try: controller.remove_event_listener(func) except SocketClosed as e: if not settings.end_event.is_set(): log.debug(e) else: log.exception(e) except ProtocolError as e: log.exception("Exception trying to remove event %s", e) Loading Loading @@ -245,9 +251,13 @@ def get_socks_info(controller): try: socks_ports = controller.get_listeners(Listener.SOCKS) return socks_ports[0] except SocketClosed as e: if not settings.end_event.is_set(): log.debug(e) # This might need to return the eception if this happen in other cases # than when stopping the scanner. except ControllerError as e: log.exception("Exception trying to get socks info: %e.", e) exit(1) log.debug(e) def only_relays_with_bandwidth(controller, relays, min_bw=None, max_bw=None): Loading