work on the ability to attach to existing Tor
This commit is contained in:
parent
bffef46e89
commit
840563f75c
4
src/netcontroller/torcontrol/onionservicecreator.py
Normal file
4
src/netcontroller/torcontrol/onionservicecreator.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
"""Onionr - Private P2P Communication.
|
||||||
|
|
||||||
|
Create an ephemeral onion service
|
||||||
|
"""
|
@ -25,9 +25,11 @@ import filepaths
|
|||||||
from etc import onionrvalues, cleanup
|
from etc import onionrvalues, cleanup
|
||||||
from onionrcrypto import getourkeypair
|
from onionrcrypto import getourkeypair
|
||||||
from utils import hastor, logoheader
|
from utils import hastor, logoheader
|
||||||
from . import version
|
|
||||||
import runtests
|
import runtests
|
||||||
from httpapi import daemoneventsapi
|
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
|
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
|
||||||
@ -85,13 +87,7 @@ def daemon():
|
|||||||
|
|
||||||
apiHost = ''
|
apiHost = ''
|
||||||
if not offline_mode:
|
if not offline_mode:
|
||||||
while apiHost == '':
|
apiHost = get_api_host_until_available()
|
||||||
try:
|
|
||||||
with open(filepaths.public_API_host_file, 'r') as hostFile:
|
|
||||||
apiHost = hostFile.read()
|
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
logger.raw('', terminal=True)
|
logger.raw('', terminal=True)
|
||||||
# print nice header thing :)
|
# print nice header thing :)
|
||||||
@ -110,6 +106,7 @@ def daemon():
|
|||||||
shared_state.get(onionrstatistics.tor.TorStats)
|
shared_state.get(onionrstatistics.tor.TorStats)
|
||||||
|
|
||||||
if not offline_mode:
|
if not offline_mode:
|
||||||
|
|
||||||
logger.info('Tor is starting...', terminal=True)
|
logger.info('Tor is starting...', terminal=True)
|
||||||
if not net.startTor():
|
if not net.startTor():
|
||||||
localcommand.local_command('shutdown')
|
localcommand.local_command('shutdown')
|
||||||
@ -125,26 +122,17 @@ def daemon():
|
|||||||
(logger.colors.underline +
|
(logger.colors.underline +
|
||||||
getourkeypair.get_keypair()[0][:52]))
|
getourkeypair.get_keypair()[0][:52]))
|
||||||
|
|
||||||
try:
|
better_sleep(1)
|
||||||
time.sleep(1)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
events.event('init', threaded=False)
|
events.event('init', threaded=False)
|
||||||
events.event('daemon_start')
|
events.event('daemon_start')
|
||||||
communicator.startCommunicator(shared_state)
|
communicator.startCommunicator(shared_state)
|
||||||
|
|
||||||
|
|
||||||
if not offline_mode:
|
if not offline_mode:
|
||||||
net.killTor()
|
net.killTor()
|
||||||
|
|
||||||
try:
|
better_sleep(5)
|
||||||
# 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
|
|
||||||
cleanup.delete_run_files()
|
cleanup.delete_run_files()
|
||||||
|
|
||||||
|
|
38
src/onionrcommands/daemonlaunch/getapihost.py
Normal file
38
src/onionrcommands/daemonlaunch/getapihost.py
Normal 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
10
src/utils/bettersleep.py
Normal 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
|
||||||
|
|
@ -54,7 +54,10 @@
|
|||||||
"v3onions": true,
|
"v3onions": true,
|
||||||
"use_bridge": false,
|
"use_bridge": false,
|
||||||
"bridge_ip": "",
|
"bridge_ip": "",
|
||||||
"bridge_fingerprint": ""
|
"bridge_fingerprint": "",
|
||||||
|
"existing_control_port": 0,
|
||||||
|
"existing_control_password": "",
|
||||||
|
"temp_transport": false
|
||||||
},
|
},
|
||||||
|
|
||||||
"allocations": {
|
"allocations": {
|
||||||
|
Loading…
Reference in New Issue
Block a user