improved documentation + refactored daemonlaunch

master
Kevin 2020-06-14 19:08:17 -05:00
parent 88824b7913
commit a10a32fafb
5 changed files with 104 additions and 70 deletions

View File

@ -26,6 +26,7 @@ from communicatorutils import housekeeping
from communicatorutils import netcheck
from onionrutils import localcommand
from onionrutils import epoch
from onionrcommands.openwebinterface import get_url
from etc import humanreadabletime
import onionrservices
import filepaths
@ -241,6 +242,8 @@ class OnionrCommunicatorDaemon:
logger.info(
'First run detected. Run openhome to get setup.',
terminal=True)
get_url()
while not config.get('onboarding.done', True) and \
not self.shutdown:

View File

@ -42,7 +42,8 @@ def net_check(comm_inst):
if not comm_inst.shutdown:
if not comm_inst.config.get('general.offline_mode', False):
logger.warn('Network check failed, are you connected to ' +
'the Internet, and is Tor working?',
'the Internet, and is Tor working? ' +
'This is usually temporary, but bugs and censorship can cause this to persist, in which case you should report it to beardog [at] mailbox.org',
terminal=True)
restarttor.restart(comm_inst)
comm_inst.offlinePeers = []

View File

@ -25,16 +25,15 @@ from utils import identifyhome
import filepaths
from etc import onionrvalues, cleanup
from onionrcrypto import getourkeypair
from utils import hastor, logoheader
from utils import hastor
import runtests
from httpapi import daemoneventsapi
from .. import version
from .getapihost import get_api_host_until_available
from utils.bettersleep import better_sleep
from netcontroller.torcontrol.onionservicecreator import create_onion_service
from .quotes import QUOTE
from .killdaemon import kill_daemon # noqa
from utils.boxprint import bordered
from .showlogo import show_logo
from lan import LANManager
from lan.server import LANServer
from sneakernet import sneakernet_import_thread
@ -60,8 +59,60 @@ def _proper_shutdown():
sys.exit(1)
def _show_info_messages():
version.version(verbosity=5, function=logger.info)
logger.debug('Python version %s' % platform.python_version())
if onionrvalues.DEVELOPMENT_MODE:
logger.warn('Development mode enabled', timestamp=False, terminal=True)
logger.info('Using public key: %s' %
(logger.colors.underline +
getourkeypair.get_keypair()[0][:52]))
def _setup_online_mode(use_existing_tor: bool,
net: NetController,
security_level: int):
if config.get('transports.tor', True):
# 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 not, we need to tell netcontroller to start one
if use_existing_tor:
try:
os.mkdir(filepaths.tor_hs_loc)
except FileExistsError:
pass
net.socksPort = config.get('tor.existing_socks_port')
try:
net.myID = create_onion_service(
port=net.apiServerIP + ':' + str(net.hsPort))[0]
except IncorrectPassword:
# Exit if we cannot connect to the existing Tor instance
logger.error('Invalid Tor control password', terminal=True)
localcommand.local_command('shutdown')
cleanup.delete_run_files()
sys.exit(1)
if not net.myID.endswith('.onion'):
net.myID += '.onion'
with open(filepaths.tor_hs_address_file, 'w') as tor_file:
tor_file.write(net.myID)
else:
logger.info('Tor is starting...', terminal=True)
if not net.startTor():
# Exit if we cannot start Tor.
localcommand.local_command('shutdown')
cleanup.delete_run_files()
sys.exit(1)
if len(net.myID) > 0 and security_level == 0:
logger.debug('Started .onion service: %s' %
(logger.colors.underline + net.myID))
else:
logger.debug('.onion service disabled')
def daemon():
"""Start the Onionr communication daemon."""
"""Start Onionr's primary threads for communicator, API server, node, and LAN."""
# Determine if Onionr is in offline mode.
# When offline, Onionr can only use LAN and disk transport
offline_mode = config.get('general.offline_mode', False)
@ -90,33 +141,22 @@ def daemon():
# Init run time tester
# (ensures Onionr is running right, for testing purposes)
# Run time tests are not normally run
shared_state.get(runtests.OnionrRunTestManager)
# Create singleton
shared_state.get(serializeddata.SerializedData)
shared_state.share_object() # share the parent object to the threads
show_logo()
# since we randomize loopback API server hostname to protect against attacks,
# we have to wait for it to become set
apiHost = ''
if not offline_mode:
apiHost = get_api_host_until_available()
logger.raw('', terminal=True)
# print nice header thing :)
if config.get('general.display_header', True):
logoheader.header("")
if QUOTE[1]:
logger.info(
"\u001b[33m\033[F" + bordered(QUOTE[0] + '\n -' + QUOTE[1]),
terminal=True)
else:
logger.info("\u001b[33m\033[F" + bordered(QUOTE[0]), terminal=True)
version.version(verbosity=5, function=logger.info)
logger.debug('Python version %s' % platform.python_version())
if onionrvalues.DEVELOPMENT_MODE:
logger.warn('Development mode enabled', timestamp=False, terminal=True)
net = NetController(config.get('client.public.port', 59497),
apiServerIP=apiHost)
shared_state.add(net)
@ -126,44 +166,11 @@ def daemon():
security_level = config.get('general.security_level', 1)
use_existing_tor = config.get('tor.use_existing_tor', False)
if not offline_mode:
if config.get('transports.tor', True):
if use_existing_tor:
try:
os.mkdir(filepaths.tor_hs_loc)
except FileExistsError:
pass
net.socksPort = config.get('tor.existing_socks_port')
try:
net.myID = create_onion_service(
port=net.apiServerIP + ':' + str(net.hsPort))[0]
except IncorrectPassword:
logger.error('Invalid Tor control password', terminal=True)
localcommand.local_command('shutdown')
cleanup.delete_run_files()
sys.exit(1)
if not net.myID.endswith('.onion'):
net.myID += '.onion'
with open(filepaths.tor_hs_address_file, 'w') as tor_file:
tor_file.write(net.myID)
else:
logger.info('Tor is starting...', terminal=True)
if not net.startTor():
localcommand.local_command('shutdown')
cleanup.delete_run_files()
sys.exit(1)
if len(net.myID) > 0 and security_level == 0:
logger.debug('Started .onion service: %s' %
(logger.colors.underline + net.myID))
else:
logger.debug('.onion service disabled')
logger.info('Using public key: %s' %
(logger.colors.underline +
getourkeypair.get_keypair()[0][:52]))
better_sleep(1)
if offline_mode:
_setup_online_mode(offline_mode, use_existing_tor, net, security_level)
_show_info_messages()
events.event('init', threaded=False)
events.event('daemon_start')
@ -175,6 +182,7 @@ def daemon():
Thread(target=sneakernet_import_thread, daemon=True).start()
Thread(target=statistics_reporter, args=[shared_state], daemon=True).start()
communicator.startCommunicator(shared_state)
clean_ephemeral_services()
@ -190,7 +198,7 @@ def daemon():
better_sleep(5)
cleanup.delete_run_files()
if config.get('general.security_level', 1) >= 2:
if security_level >= 2:
filenuke.nuke.clean_tree(identifyhome.identify_home())

View File

@ -0,0 +1,22 @@
"""Onionr - Private P2P Communication.
Show nice logo
"""
import config
import logger
from .quotes import QUOTE
from utils.boxprint import bordered
from utils import logoheader
def show_logo():
logger.raw('', terminal=True)
# print nice header thing :)
if config.get('general.display_header', True):
logoheader.header("")
if QUOTE[1]:
logger.info(
"\u001b[33m\033[F" + bordered(QUOTE[0] + '\n -' + QUOTE[1]),
terminal=True)
else:
logger.info("\u001b[33m\033[F" + bordered(QUOTE[0]), terminal=True)

View File

@ -7,16 +7,16 @@
},
"general": {
"announce_node": true,
"dev_mode": true,
"dev_mode": false,
"display_header": true,
"ephemeral_tunnels": false,
"hide_created_blocks": true,
"insert_deniable_blocks": false,
"insert_deniable_blocks": true,
"max_block_age": 2678400,
"minimum_block_pow": 1,
"minimum_send_pow": 1,
"minimum_block_pow": 5,
"minimum_send_pow": 5,
"public_key": "",
"random_bind_ip": false,
"random_bind_ip": true,
"security_level": 0,
"show_notifications": true,
"store_plaintext_blocks": true,
@ -30,12 +30,12 @@
},
"file": {
"output": true,
"remove_on_exit": false
"remove_on_exit": true
},
"verbosity": "default"
},
"onboarding": {
"done": true
"done": false
},
"peers": {
"max_connect": 1000,
@ -68,7 +68,7 @@
"transports": {
"lan": true,
"sneakernet": true,
"tor": false
"tor": true
},
"ui": {
"theme": "dark"