From e981a748e5f6a3c72ab46597720d754861c0bb97 Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Thu, 6 Aug 2026 11:27:50 -0400 Subject: [PATCH] Tor Bootstrap Uses a new fresh config file. --- .../networking/tor_tools/bootstrap.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/core/services/networking/tor_tools/bootstrap.py b/core/services/networking/tor_tools/bootstrap.py index ad953f4..5c91c4c 100644 --- a/core/services/networking/tor_tools/bootstrap.py +++ b/core/services/networking/tor_tools/bootstrap.py @@ -15,6 +15,7 @@ from typing import Optional from enum import Enum import atexit import threading +from pathlib import Path _tor_process: Optional[subprocess.Popen] = None @@ -148,7 +149,7 @@ def _attempt_single_bootstrap( if port is None: return ApiResponse(valid=False, error_type=ErrorType.INVALID_INPUT) - command = _build_tor_command(port, use_new_folder) + command = prep_config_and_command(port, use_new_folder) try: _tor_process = subprocess.Popen( @@ -203,13 +204,24 @@ def _cleanup_on_exit(): _tor_process.kill() -def _build_tor_command(port: int, use_new_folder: bool) -> list[str]: - """Extract command building to reduce clutter.""" - command = ["tor", "--SocksPort", str(port)] +def prep_config_and_command(port: int, use_new_folder: bool) -> list[str]: + """ + Purpose: + We're making a new blank config, and then preparing the command + + Why: + The Tor config and the data directory are different. + We make a new config to avoid permissions, + But the same data directory can be reused for speed. + """ + + Path("/tmp/torrc.empty").touch() + + command = ["tor", "-f", "/tmp/torrc.empty", "--SocksPort", str(port)] + # Only making a new data folder if we need to: if use_new_folder: command.extend(["--DataDirectory", f"/tmp/tor-{port}"]) return command -