Conform tor setup to the restrictions for incoming and outgoing connections;

don't start the tor service with --no-incoming if there is a system one.
This commit is contained in:
Lee Miller 2023-10-26 03:32:55 +03:00
parent a0537a9e66
commit c5a1310083
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 14 additions and 9 deletions

View File

@ -271,21 +271,21 @@ def main():
'Error while creating data directory in: %s', 'Error while creating data directory in: %s',
shared.data_directory, exc_info=True) shared.data_directory, exc_info=True)
if shared.socks_proxy: if shared.socks_proxy and shared.send_outgoing_connections:
try: try:
socks.PROXY_TYPES[shared.socks_proxy.scheme.upper()] socks.PROXY_TYPES[shared.socks_proxy.scheme.upper()]
except KeyError: except KeyError:
logging.error('Unsupported proxy schema!') logging.error('Unsupported proxy schema!')
return return
if shared.tor: if shared.tor:
try: try:
from . import tor # pylint: disable=import-outside-toplevel from . import tor # pylint: disable=import-outside-toplevel
except ImportError: except ImportError:
logging.info('Failed to import tor module.', exc_info=True) logging.info('Failed to import tor module.', exc_info=True)
else: else:
if not tor.start_tor_service(): if not tor.start_tor_service():
logging.warning('Failed to start tor service.') logging.warning('The tor service has not started.')
if shared.ip_enabled and not shared.trusted_peer and not shared.tor: if shared.ip_enabled and not shared.trusted_peer and not shared.tor:
bootstrap_from_dns() bootstrap_from_dns()

View File

@ -63,6 +63,8 @@ def start_tor_service():
init_msg_handler=logwrite) init_msg_handler=logwrite)
except OSError: except OSError:
if not attempt: if not attempt:
if not shared.listen_for_connections:
return
try: try:
stem.version.get_system_tor_version() stem.version.get_system_tor_version()
except IOError: except IOError:
@ -75,6 +77,9 @@ def start_tor_service():
logging.debug('Failed to start tor.') logging.debug('Failed to start tor.')
return return
if not shared.listen_for_connections:
return True
try: try:
controller = stem.control.Controller.from_socket_file(control_socket) controller = stem.control.Controller.from_socket_file(control_socket)
controller.authenticate() controller.authenticate()