work on the ability to attach to existing Tor
parent
8bf1389a48
commit
ea47ae456b
|
@ -22,6 +22,7 @@ lock_file = home + 'onionr.lock'
|
|||
|
||||
site_cache = home + 'onionr-sites.txt'
|
||||
|
||||
tor_hs_loc = home + 'hs/'
|
||||
tor_hs_address_file = home + 'hs/hostname'
|
||||
|
||||
run_check_file = home + '.runcheck'
|
||||
|
|
|
@ -12,7 +12,6 @@ import multiprocessing
|
|||
import platform # For windows sigkill workaround
|
||||
|
||||
from onionrtypes import BooleanSuccessState
|
||||
import config
|
||||
import logger
|
||||
from .. import getopenport
|
||||
from .. import watchdog
|
||||
|
@ -36,7 +35,6 @@ from utils import identifyhome
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
config.reload()
|
||||
TOR_KILL_WAIT = 3
|
||||
addbridges = addbridges.add_bridges
|
||||
|
||||
|
|
|
@ -2,3 +2,29 @@
|
|||
|
||||
Create an ephemeral onion service
|
||||
"""
|
||||
from .torcontroller import get_controller
|
||||
"""
|
||||
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 create_onion_service(port=80):
|
||||
controller = get_controller()
|
||||
hs = controller.create_ephemeral_hidden_service(
|
||||
{80: port},
|
||||
key_type='NEW',
|
||||
key_content='ED25519-V3',
|
||||
await_publication=True,
|
||||
detached=True)
|
||||
return (hs.service_id, hs.private_key)
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
from stem.control import Controller
|
||||
|
||||
import config
|
||||
config.reload()
|
||||
|
||||
|
||||
def get_controller():
|
||||
c = Controller.from_port(port=config.get('tor.controlPort'))
|
||||
c.authenticate(config.get('tor.controlpassword'))
|
||||
def get_controller() -> Controller:
|
||||
"""Create and return a Tor controller connection."""
|
||||
port = config.get('tor.controlPort', 0)
|
||||
password = config.get('tor.controlpassword', '')
|
||||
if config.get('tor.use_existing_tor', False):
|
||||
port = config.get('tor.existing_control_port', 0)
|
||||
password = config.get('tor.existing_control_password', '')
|
||||
c = Controller.from_port(port=port)
|
||||
c.authenticate(password)
|
||||
return c
|
||||
|
|
|
@ -20,6 +20,7 @@ import logger
|
|||
import communicator
|
||||
from onionrplugins import onionrevents as events
|
||||
from netcontroller import NetController
|
||||
from netcontroller import get_open_port
|
||||
from onionrutils import localcommand
|
||||
import filepaths
|
||||
from etc import onionrvalues, cleanup
|
||||
|
@ -29,7 +30,8 @@ import runtests
|
|||
from httpapi import daemoneventsapi
|
||||
from .. import version
|
||||
from .getapihost import get_api_host_until_available
|
||||
from .bettersleep import better_sleep
|
||||
from utils.bettersleep import better_sleep
|
||||
from netcontroller.torcontrol.onionservicecreator import create_onion_service
|
||||
"""
|
||||
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
|
||||
|
@ -105,14 +107,23 @@ def daemon():
|
|||
|
||||
shared_state.get(onionrstatistics.tor.TorStats)
|
||||
|
||||
security_level = config.get('general.security_level', 1)
|
||||
use_existing_tor = config.get('tor.use_existing_tor', False)
|
||||
|
||||
if not offline_mode:
|
||||
|
||||
if use_existing_tor:
|
||||
net.socksPort = config.get('tor.existing_socks_port')
|
||||
net.myID = create_onion_service(port=get_open_port())
|
||||
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 config.get('general.security_level', 1) == 0:
|
||||
if len(net.myID) > 0 and security_level == 0:
|
||||
logger.debug('Started .onion service: %s' %
|
||||
(logger.colors.underline + net.myID))
|
||||
else:
|
||||
|
@ -128,7 +139,7 @@ def daemon():
|
|||
events.event('daemon_start')
|
||||
communicator.startCommunicator(shared_state)
|
||||
|
||||
if not offline_mode:
|
||||
if not offline_mode and not use_existing_tor:
|
||||
net.killTor()
|
||||
|
||||
better_sleep(5)
|
||||
|
|
|
@ -15,3 +15,5 @@ JSONSerializable = NewType('JSONSerializable', str)
|
|||
# Return value of some functions or methods, denoting operation success
|
||||
# Do not use for new code
|
||||
BooleanSuccessState = NewType('BooleanSuccessState', bool)
|
||||
|
||||
OnionAddressString = NewType('OnionAddressString', str)
|
||||
|
|
|
@ -22,10 +22,14 @@ from . import identifyhome
|
|||
import filepaths
|
||||
home = identifyhome.identify_home()
|
||||
|
||||
|
||||
def create_dirs():
|
||||
"""Creates onionr data-related directories in order of the hardcoded list below,
|
||||
"""Create onionr data-related directories in
|
||||
order of the hardcoded list below,
|
||||
then trigger creation of DBs"""
|
||||
gen_dirs = [home, filepaths.block_data_location, filepaths.contacts_location, filepaths.export_location]
|
||||
gen_dirs = [home, filepaths.block_data_location,
|
||||
filepaths.contacts_location, filepaths.export_location,
|
||||
filepaths.tor_hs_loc]
|
||||
for path in gen_dirs:
|
||||
if not os.path.exists(path):
|
||||
os.mkdir(path)
|
||||
|
|
|
@ -55,9 +55,10 @@
|
|||
"use_bridge": false,
|
||||
"bridge_ip": "",
|
||||
"bridge_fingerprint": "",
|
||||
"use_existing_tor": false,
|
||||
"existing_control_port": 0,
|
||||
"existing_control_password": "",
|
||||
"temp_transport": false
|
||||
"existing_socks_port": 0
|
||||
},
|
||||
|
||||
"allocations": {
|
||||
|
|
Loading…
Reference in New Issue