Make `dataDir` to be TorProcessManager argument.
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -177,16 +177,16 @@ namespace WalletWasabi.Gui
if (Config.UseTor)
{
- TorManager = new TorProcessManager(Config.TorSocks5EndPoint, TorLogsFile);
+ TorManager = new TorProcessManager(Config.TorSocks5EndPoint, DataDir, TorLogsFile);
+ TorManager.Start(ensureRunning: false);
}
else
{
TorManager = TorProcessManager.Mock();
}
- TorManager.Start(false, DataDir);
var fallbackRequestTestUri = new Uri(Config.GetFallbackBackendUri(), "/api/software/versions");
- TorManager.StartMonitor(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(7), DataDir, fallbackRequestTestUri);
+ TorManager.StartMonitor(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(7), fallbackRequestTestUri);
Logger.LogInfo($"{nameof(TorProcessManager)} is initialized.");

MODIFY
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
@@ -25,8 +25,11 @@ namespace WalletWasabi.Tests.IntegrationTests
{
LiveServerTestsFixture = liveServerTestsFixture;
- var torManager = new TorProcessManager(Global.Instance.TorSocks5Endpoint, Global.Instance.TorLogsFile);
- torManager.Start(ensureRunning: true, dataDir: Path.GetFullPath(AppContext.BaseDirectory));
+ string dataDir = Path.GetFullPath(AppContext.BaseDirectory);
+ string torLogsFile = Global.Instance.TorLogsFile;
+
+ var torManager = new TorProcessManager(Global.Instance.TorSocks5Endpoint, dataDir, torLogsFile);
+ torManager.Start(ensureRunning: true);
Task.Delay(3000).GetAwaiter().GetResult();
}

MODIFY
WalletWasabi.Tests/IntegrationTests/TorTests.cs
WalletWasabi.Tests/IntegrationTests/TorTests.cs
@@ -4,8 +4,8 @@ using System.IO;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
+using System.Threading;
using System.Threading.Tasks;
-using WalletWasabi.Tests.XunitConfiguration;
using WalletWasabi.TorSocks5;
using Xunit;
@@ -16,8 +16,11 @@ namespace WalletWasabi.Tests.IntegrationTests
{
public TorTests()
{
- var torManager = new TorProcessManager(Global.Instance.TorSocks5Endpoint, Global.Instance.TorLogsFile);
- torManager.Start(ensureRunning: true, dataDir: Path.GetFullPath(AppContext.BaseDirectory));
+ string dataDir = Path.GetFullPath(AppContext.BaseDirectory);
+ string torLogsFile = Global.Instance.TorLogsFile;
+
+ var torManager = new TorProcessManager(Global.Instance.TorSocks5Endpoint, dataDir, torLogsFile);
+ torManager.Start(ensureRunning: true);
Task.Delay(3000).GetAwaiter().GetResult();
}

MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -26,10 +26,11 @@ namespace WalletWasabi.TorSocks5
/// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
/// <param name="logFile">Opt out of logging with null.</param>
- public TorProcessManager(EndPoint torSocks5EndPoint, string logFile)
+ public TorProcessManager(EndPoint torSocks5EndPoint, string dataDir, string logFile)
{
TorSocks5EndPoint = torSocks5EndPoint;
LogFile = logFile;
+ DataDir = dataDir;
_running = 0;
Stop = new CancellationTokenSource();
TorProcess = null;
@@ -42,6 +43,8 @@ namespace WalletWasabi.TorSocks5
public string LogFile { get; }
+ private string DataDir { get; }
+
public static bool RequestFallbackAddressUsage { get; private set; } = false;
public Process TorProcess { get; private set; }
@@ -52,10 +55,10 @@ namespace WalletWasabi.TorSocks5
public static TorProcessManager Mock() // Mock, do not use Tor at all for debug.
{
- return new TorProcessManager(null, null);
+ return new TorProcessManager(null, null, null);
}
- public void Start(bool ensureRunning, string dataDir)
+ public void Start(bool ensureRunning)
{
if (TorSocks5EndPoint is null)
{
@@ -80,7 +83,7 @@ namespace WalletWasabi.TorSocks5
}
var fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();
- var settings = new TorSettings(dataDir);
+ var settings = new TorSettings(DataDir);
if (!File.Exists(settings.TorPath))
{
@@ -209,7 +212,7 @@ namespace WalletWasabi.TorSocks5
#region Monitor
- public void StartMonitor(TimeSpan torMisbehaviorCheckPeriod, TimeSpan checkIfRunningAfterTorMisbehavedFor, string dataDirToStartWith, Uri fallBackTestRequestUri)
+ public void StartMonitor(TimeSpan torMisbehaviorCheckPeriod, TimeSpan checkIfRunningAfterTorMisbehavedFor, Uri fallBackTestRequestUri)
{
if (TorSocks5EndPoint is null)
{
@@ -260,7 +263,7 @@ namespace WalletWasabi.TorSocks5
else
{
Logger.LogInfo($"Tor did not work properly for {(int)torMisbehavedFor.TotalSeconds} seconds. Maybe it crashed. Attempting to start it...");
- Start(true, dataDirToStartWith); // Try starting Tor, if it does not work it'll be another issue.
+ Start(ensureRunning: true); // Try starting Tor, if it does not work it'll be another issue.
await Task.Delay(14000, Stop.Token).ConfigureAwait(false);
}
}

Make `dataDir` to be TorProcessManager argument.