work on the ability to attach to existing Tor

This commit is contained in:
Kevin Froman 2020-01-31 18:23:48 -06:00
parent 8bf1389a48
commit ea47ae456b
8 changed files with 68 additions and 18 deletions

View file

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

View file

@ -1,4 +1,30 @@
"""Onionr - Private P2P Communication.
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)

View file

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