Skip to content

Commit

Permalink
Move tordata dir to tempdir implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Loren Eteval <[email protected]>
  • Loading branch information
LorenEteval committed Sep 6, 2023
1 parent a807d0d commit 06d5bd8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Furious/Core/TorRelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@
from Furious.Utility.Constants import (
APP,
PLATFORM,
DATA_DIR,
APPLICATION_NAME,
DEFAULT_TOR_SOCKS_PORT,
DEFAULT_TOR_HTTPS_PORT,
)
from Furious.Utility.Utility import AsyncSubprocessMessage, runCommand

from PySide6 import QtCore

import os
import re
import signal
import logging
import tempfile
import threading
import functools
import subprocess
Expand All @@ -39,6 +41,7 @@

class TorRelayStarter(AsyncSubprocessMessage):
BOOTSTRAP_STATUS = re.compile(r'Bootstrapped ([0-9]+)%')
TORDATA_TEMP_DIR = QtCore.QTemporaryDir()

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -54,6 +57,14 @@ def torRelayStorageObj(self):
# Handy reference
return APP().torRelaySettingsWidget.StorageObj

@staticmethod
@functools.lru_cache(None)
def getTorDataTempFilepath():
if TorRelayStarter.TORDATA_TEMP_DIR.isValid():
return TorRelayStarter.TORDATA_TEMP_DIR.path()
else:
return os.path.join(tempfile.gettempdir(), APPLICATION_NAME, 'tordata')

def launch(self, proxyServer):
if PLATFORM == 'Windows':
self.torRelay = subprocess.Popen(
Expand All @@ -71,11 +82,15 @@ def launch(self, proxyServer):
stderr=subprocess.PIPE,
)

torDataTempFilepath = TorRelayStarter.getTorDataTempFilepath()

logger.info(f'Tor CLI data directory is {torDataTempFilepath}')

torConfig = (
f'SocksPort {self.torRelayStorageObj.get("socksTunnelPort", DEFAULT_TOR_SOCKS_PORT)}\n'
f'HTTPTunnelPort {self.torRelayStorageObj.get("httpsTunnelPort", DEFAULT_TOR_HTTPS_PORT)}\n'
f'Log {self.torRelayStorageObj.get("logLevel", "notice")} stdout\n'
f'DataDirectory {DATA_DIR / "tordata"}\n'
f'DataDirectory {torDataTempFilepath}\n'
)

if proxyServer:
Expand Down

0 comments on commit 06d5bd8

Please sign in to comment.