diff --git a/src/netcontroller/torcontrol/onionservicecreator.py b/src/netcontroller/torcontrol/onionservicecreator.py new file mode 100644 index 00000000..da1f3785 --- /dev/null +++ b/src/netcontroller/torcontrol/onionservicecreator.py @@ -0,0 +1,4 @@ +"""Onionr - Private P2P Communication. + +Create an ephemeral onion service +""" \ No newline at end of file diff --git a/src/onionrcommands/daemonlaunch.py b/src/onionrcommands/daemonlaunch/__init__.py similarity index 90% rename from src/onionrcommands/daemonlaunch.py rename to src/onionrcommands/daemonlaunch/__init__.py index 27b75eae..315e92c0 100755 --- a/src/onionrcommands/daemonlaunch.py +++ b/src/onionrcommands/daemonlaunch/__init__.py @@ -25,9 +25,11 @@ import filepaths from etc import onionrvalues, cleanup from onionrcrypto import getourkeypair from utils import hastor, logoheader -from . import version import runtests from httpapi import daemoneventsapi +from .. import version +from .getapihost import get_api_host_until_available +from .bettersleep import better_sleep """ 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 @@ -85,13 +87,7 @@ def daemon(): apiHost = '' if not offline_mode: - while apiHost == '': - try: - with open(filepaths.public_API_host_file, 'r') as hostFile: - apiHost = hostFile.read() - except FileNotFoundError: - pass - time.sleep(0.5) + apiHost = get_api_host_until_available() logger.raw('', terminal=True) # print nice header thing :) @@ -110,6 +106,7 @@ def daemon(): shared_state.get(onionrstatistics.tor.TorStats) if not offline_mode: + logger.info('Tor is starting...', terminal=True) if not net.startTor(): localcommand.local_command('shutdown') @@ -125,26 +122,17 @@ def daemon(): (logger.colors.underline + getourkeypair.get_keypair()[0][:52])) - try: - time.sleep(1) - except KeyboardInterrupt: - pass + better_sleep(1) events.event('init', threaded=False) events.event('daemon_start') communicator.startCommunicator(shared_state) - if not offline_mode: net.killTor() - try: - # Time to allow threads to finish, - # if not any "daemon" threads will be slaughtered - # http://docs.python.org/library/threading.html#threading.Thread.daemon - time.sleep(5) - except KeyboardInterrupt: - pass + better_sleep(5) + cleanup.delete_run_files() diff --git a/src/onionrcommands/daemonlaunch/getapihost.py b/src/onionrcommands/daemonlaunch/getapihost.py new file mode 100644 index 00000000..62422085 --- /dev/null +++ b/src/onionrcommands/daemonlaunch/getapihost.py @@ -0,0 +1,38 @@ +"""Onionr - Private P2P Communication. + +Wait for the api host to be available in the public api host file. +returns string of ip for the local public host interface +""" +from time import sleep + +from filepaths import public_API_host_file +""" + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" + + +def get_api_host_until_available() -> str: + """Wait for the api host to be available in the public api host file. + + returns string of ip for the local public host interface + """ + api_host = '' + while api_host == '': + try: + with open(public_API_host_file, 'r') as file: + api_host = file.read() + except FileNotFoundError: + pass + sleep(0.5) + return api_host diff --git a/src/utils/bettersleep.py b/src/utils/bettersleep.py new file mode 100644 index 00000000..03096bc0 --- /dev/null +++ b/src/utils/bettersleep.py @@ -0,0 +1,10 @@ +from time import sleep + + +def better_sleep(wait: int): + """Sleep catching ctrl c for wait seconds.""" + try: + sleep(wait) + except KeyboardInterrupt: + pass + diff --git a/static-data/default_config.json b/static-data/default_config.json index 27e62d47..0c181b72 100755 --- a/static-data/default_config.json +++ b/static-data/default_config.json @@ -54,7 +54,10 @@ "v3onions": true, "use_bridge": false, "bridge_ip": "", - "bridge_fingerprint": "" + "bridge_fingerprint": "", + "existing_control_port": 0, + "existing_control_password": "", + "temp_transport": false }, "allocations": {