Tor Bootstrap Uses a new fresh config file.
This commit is contained in:
parent
1b609a9e5e
commit
e981a748e5
1 changed files with 17 additions and 5 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue