Move TorLogPath to TorSettings and move TorSettings out of TorProcessManager.
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -51,7 +51,7 @@ namespace WalletWasabi.Gui
public const string ApplicationAccentForegroundBrushResourceKey = "ApplicationAccentForegroundBrush";
public string DataDir { get; }
- public string TorLogsFile { get; }
+ public TorSettings TorSettings { get; }
public BitcoinStore BitcoinStore { get; }
public LegalDocuments LegalDocuments { get; set; }
public Config Config { get; }
@@ -90,7 +90,7 @@ namespace WalletWasabi.Gui
DataDir = dataDir;
Config = config;
UiConfig = uiConfig;
- TorLogsFile = torLogsFile;
+ TorSettings = new TorSettings(DataDir, torLogsFile);
Logger.InitializeDefaults(Path.Combine(DataDir, "Logs.txt"));
@@ -177,7 +177,7 @@ namespace WalletWasabi.Gui
if (Config.UseTor)
{
- TorManager = new TorProcessManager(Config.TorSocks5EndPoint, DataDir, TorLogsFile);
+ TorManager = new TorProcessManager(TorSettings, Config.TorSocks5EndPoint);
TorManager.Start(ensureRunning: false);
}
else

MODIFY
WalletWasabi.Gui/Shell/Commands/DiskCommands.cs
WalletWasabi.Gui/Shell/Commands/DiskCommands.cs
@@ -94,7 +94,7 @@ namespace WalletWasabi.Gui.Shell.Commands
private async Task OnOpenTorLogFileAsync()
{
var global = Locator.Current.GetService<Global>();
- await FileHelpers.OpenFileInTextEditorAsync(global.TorLogsFile);
+ await FileHelpers.OpenFileInTextEditorAsync(global.TorSettings.LogFilePath);
}
private async Task OnOpenConfigFileAsync()

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

MODIFY
WalletWasabi.Tests/IntegrationTests/TorTests.cs
WalletWasabi.Tests/IntegrationTests/TorTests.cs
@@ -17,9 +17,11 @@ namespace WalletWasabi.Tests.IntegrationTests
public TorTests()
{
string dataDir = Path.GetFullPath(AppContext.BaseDirectory);
- string torLogsFile = Global.Instance.TorLogsFile;
+ string logsFilePath = Global.Instance.TorLogsFile;
- var torManager = new TorProcessManager(Global.Instance.TorSocks5Endpoint, dataDir, torLogsFile);
+ var settings = new TorSettings(dataDir: dataDir, logsFilePath);
+
+ var torManager = new TorProcessManager(settings, Global.Instance.TorSocks5Endpoint);
torManager.Start(ensureRunning: true);
Task.Delay(3000).GetAwaiter().GetResult();
}

MODIFY
WalletWasabi.Tests/UnitTests/Tor/TorSettingsTests.cs
WalletWasabi.Tests/UnitTests/Tor/TorSettingsTests.cs
@@ -16,7 +16,7 @@ namespace WalletWasabi.Tests.UnitTests.Tor
[Fact]
public void GetCmdArgumentsTest()
{
- var settings = new TorSettings("temp");
+ var settings = new TorSettings("temp", "temp/Tor.log");
var endpoint = new IPEndPoint(IPAddress.Loopback, WalletWasabi.Helpers.Constants.DefaultTorSocksPort);
string arguments = settings.GetCmdArguments(endpoint);

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -34,16 +34,18 @@ namespace WalletWasabi.Tor
/// </summary>
private long _monitorState;
- /// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
- /// <param name="logFile">Opt out of logging with null.</param>
- public TorProcessManager(EndPoint torSocks5EndPoint, string dataDir, string logFile)
+ /// <summary>
+ /// Creates new instance of the object.
+ /// </summary>
+ /// <param name="settings">Tor settings.</param>
+ /// <param name="torSocks5EndPoint">Valid Tor end point.</param>
+ public TorProcessManager(TorSettings settings, EndPoint torSocks5EndPoint)
{
TorSocks5EndPoint = torSocks5EndPoint;
- LogFile = logFile;
_monitorState = StateNotStarted;
Stop = new CancellationTokenSource();
TorProcess = null;
- Settings = new TorSettings(dataDir);
+ Settings = settings;
}
/// <summary>
@@ -51,11 +53,9 @@ namespace WalletWasabi.Tor
/// </summary>
public EndPoint TorSocks5EndPoint { get; }
- public string LogFile { get; }
-
public static bool RequestFallbackAddressUsage { get; private set; } = false;
- public Process TorProcess { get; private set; }
+ public Process? TorProcess { get; private set; }
private TorSettings Settings { get; }
@@ -65,7 +65,7 @@ namespace WalletWasabi.Tor
public static TorProcessManager Mock() // Mock, do not use Tor at all for debug.
{
- return new TorProcessManager(null, null, null);
+ return new TorProcessManager(null, null);
}
public void Start(bool ensureRunning)
@@ -119,10 +119,10 @@ namespace WalletWasabi.Tor
string torArguments = Settings.GetCmdArguments(TorSocks5EndPoint);
- if (!string.IsNullOrEmpty(LogFile))
+ if (Settings.LogFilePath is { })
{
- IoHelpers.EnsureContainingDirectoryExists(LogFile);
- var logFileFullPath = Path.GetFullPath(LogFile);
+ IoHelpers.EnsureContainingDirectoryExists(Settings.LogFilePath);
+ var logFileFullPath = Path.GetFullPath(Settings.LogFilePath);
torArguments += $" --Log \"notice file {logFileFullPath}\"";
}

MODIFY
WalletWasabi/Tor/TorSettings.cs
WalletWasabi/Tor/TorSettings.cs
-using System;
-using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
-using System.Text;
-using WalletWasabi.Helpers;
namespace WalletWasabi.Tor
{
+ /// <summary>
+ /// All Tor-related settings.
+ /// </summary>
public class TorSettings
{
- public TorSettings(string dataDir)
+ /// <summary>
+ /// Creates new instance.
+ /// </summary>
+ /// <param name="dataDir">Application data directory.</param>
+ /// <param name="logFilePath">Full Tor log file path.</param>
+ public TorSettings(string dataDir, string logFilePath)
{
TorDir = Path.Combine(dataDir, "tor");
TorDataDir = Path.Combine(dataDir, "tordata");
+ LogFilePath = logFilePath;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -33,9 +38,19 @@ namespace WalletWasabi.Tor
}
}
+ /// <summary>Full directory path where Tor is installed (or supposed to be installed).</summary>
public string TorDir { get; }
+
+ /// <summary>Full directory path where Tor stores its data.</summary>
public string TorDataDir { get; }
+
+ /// <summary>Full path. Directory may not necessarily exist.</summary>
+ public string LogFilePath { get; }
+
+ /// <summary>Full path to Tor binary that is checked against a check sum.</summary>
public string HashSourcePath { get; }
+
+ /// <summary>Full path to executable file that is used to start Tor process.</summary>
public string TorPath { get; }
private string GeoIpPath { get; }
private string GeoIp6Path { get; }

Move TorLogPath to TorSettings and move TorSettings out of TorProcessManager.