work on the ability to attach to existing Tor

This commit is contained in:
Kevin Froman 2020-01-30 23:47:48 -06:00
parent bffef46e89
commit 840563f75c
5 changed files with 64 additions and 21 deletions

View File

@ -0,0 +1,4 @@
"""Onionr - Private P2P Communication.
Create an ephemeral onion service
"""

View File

@ -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()

View File

@ -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 <https://www.gnu.org/licenses/>.
"""
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

10
src/utils/bettersleep.py Normal file
View File

@ -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

View File

@ -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": {