catch and log when cannot reach non-managed tor

This commit is contained in:
Kevin Froman 2020-08-23 22:26:54 -05:00
parent 8d54519771
commit 39650a4ca0
3 changed files with 22 additions and 4 deletions

View File

@ -2,9 +2,13 @@
Create an ephemeral onion service Create an ephemeral onion service
""" """
import stem
from .torcontroller import get_controller from .torcontroller import get_controller
from filepaths import ephemeral_services_file from filepaths import ephemeral_services_file
import logger
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -22,7 +26,11 @@ from filepaths import ephemeral_services_file
def create_onion_service(port=80, record_to_service_removal_file=True): def create_onion_service(port=80, record_to_service_removal_file=True):
controller = get_controller() try:
controller = get_controller()
except stem.SocketError:
logger.error("Could not connect to Tor control")
raise
hs = controller.create_ephemeral_hidden_service( hs = controller.create_ephemeral_hidden_service(
{80: port}, {80: port},
key_type='NEW', key_type='NEW',

View File

@ -8,6 +8,7 @@ import platform
from threading import Thread from threading import Thread
from stem.connection import IncorrectPassword from stem.connection import IncorrectPassword
import stem
import toomanyobjs import toomanyobjs
import filenuke import filenuke
from deadsimplekv import DeadSimpleKV from deadsimplekv import DeadSimpleKV
@ -73,9 +74,11 @@ def _show_info_messages():
(logger.colors.underline + (logger.colors.underline +
getourkeypair.get_keypair()[0][:52])) getourkeypair.get_keypair()[0][:52]))
def _setup_online_mode(use_existing_tor: bool,
net: NetController, def _setup_online_mode(
security_level: int): use_existing_tor: bool,
net: NetController,
security_level: int):
if config.get('transports.tor', True): if config.get('transports.tor', True):
# If we are using tor, check if we are using an existing tor instance # If we are using tor, check if we are using an existing tor instance
# if we are, we need to create an onion service on it and set attrs on our NetController # if we are, we need to create an onion service on it and set attrs on our NetController
@ -89,6 +92,12 @@ def _setup_online_mode(use_existing_tor: bool,
try: try:
net.myID = create_onion_service( net.myID = create_onion_service(
port=net.apiServerIP + ':' + str(net.hsPort))[0] port=net.apiServerIP + ':' + str(net.hsPort))[0]
except stem.SocketError:
logger.error(
"Could not connect to existing Tor service", terminal=True)
localcommand.local_command('shutdown')
cleanup.delete_run_files()
sys.exit(1)
except IncorrectPassword: except IncorrectPassword:
# Exit if we cannot connect to the existing Tor instance # Exit if we cannot connect to the existing Tor instance
logger.error('Invalid Tor control password', terminal=True) logger.error('Invalid Tor control password', terminal=True)

View File

@ -6,6 +6,7 @@
"disk": 1073741824 "disk": 1073741824
}, },
"general": { "general": {
"allow_public_api_dns_rebinding": false,
"announce_node": true, "announce_node": true,
"dev_mode": false, "dev_mode": false,
"display_header": true, "display_header": true,