Add DistributionFolderPath to TorSettings. Add TorSettings to tests/Global.
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -92,7 +92,7 @@ namespace WalletWasabi.Gui
DataDir = dataDir;
Config = config;
UiConfig = uiConfig;
- TorSettings = new TorSettings(DataDir, torLogsFile);
+ TorSettings = new TorSettings(DataDir, torLogsFile, distributionFolderPath: Path.Combine(EnvironmentHelpers.GetFullBaseDirectory(), "TorDaemons"));
Logger.InitializeDefaults(Path.Combine(DataDir, "Logs.txt"));

MODIFY
WalletWasabi.Tests/Global.cs
WalletWasabi.Tests/Global.cs
@@ -9,6 +9,7 @@ using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Models;
using WalletWasabi.Services;
+using WalletWasabi.Tor;
namespace WalletWasabi.Tests
{
@@ -19,7 +20,11 @@ namespace WalletWasabi.Tests
TorSocks5Endpoint = new IPEndPoint(IPAddress.Loopback, 9050);
DataDir = EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Tests"));
- TorLogsFile = Path.Combine(DataDir, "TorLogs.txt");
+
+ string torLogsFile = Path.Combine(DataDir, "TorLogs.txt");
+ string torDistributionFolder = Path.Combine(EnvironmentHelpers.GetFullBaseDirectory(), "TorDaemons");
+
+ TorSettings = new TorSettings(DataDir, torLogsFile, torDistributionFolder);
Logger.SetFilePath(Path.Combine(DataDir, "Logs.txt"));
Logger.SetMinimumLevel(LogLevel.Info);
@@ -30,9 +35,9 @@ namespace WalletWasabi.Tests
public EndPoint TorSocks5Endpoint { get; }
- public string DataDir { get; }
+ public TorSettings TorSettings { get; }
- public string TorLogsFile { get; }
+ public string DataDir { get; }
public static SmartTransaction GenerateRandomSmartTransaction()
{

MODIFY
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
@@ -27,13 +27,7 @@ namespace WalletWasabi.Tests.IntegrationTests
public async Task InitializeAsync()
{
- EndPoint endpoint = Global.Instance.TorSocks5Endpoint;
- string dataDir = Path.GetFullPath(AppContext.BaseDirectory);
- string logFilePath = Global.Instance.TorLogsFile;
-
- var settings = new TorSettings(dataDir: dataDir, logFilePath);
-
- var torManager = new TorProcessManager(settings, endpoint);
+ var torManager = new TorProcessManager(Global.Instance.TorSettings, Global.Instance.TorSocks5Endpoint);
torManager.Start(ensureRunning: true);
await Task.Delay(3000);
}

MODIFY
WalletWasabi.Tests/IntegrationTests/TorTests.cs
WalletWasabi.Tests/IntegrationTests/TorTests.cs
@@ -16,13 +16,7 @@ namespace WalletWasabi.Tests.IntegrationTests
{
public async Task InitializeAsync()
{
- EndPoint endpoint = Global.Instance.TorSocks5Endpoint;
- string dataDir = Path.GetFullPath(AppContext.BaseDirectory);
- string logFilePath = Global.Instance.TorLogsFile;
-
- var settings = new TorSettings(dataDir: dataDir, logFilePath);
-
- var torManager = new TorProcessManager(settings, endpoint);
+ var torManager = new TorProcessManager(Global.Instance.TorSettings, Global.Instance.TorSocks5Endpoint);
torManager.Start(ensureRunning: true);
await Task.Delay(3000);
}

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

MODIFY
WalletWasabi/Tor/TorInstallator.cs
WalletWasabi/Tor/TorInstallator.cs
@@ -11,21 +11,18 @@ namespace WalletWasabi.Tor
/// </summary>
public class TorInstallator
{
- public static async Task InstallAsync(string torDir)
+ public static async Task InstallAsync(TorSettings settings)
{
- // Folder containing installation files.
- string distributionFolder = Path.Combine(EnvironmentHelpers.GetFullBaseDirectory(), "TorDaemons");
-
// Common for all platforms.
- await ExtractZipFileAsync(Path.Combine(distributionFolder, "data-folder.zip"), torDir).ConfigureAwait(false);
+ await ExtractZipFileAsync(Path.Combine(settings.DistributionFolder, "data-folder.zip"), settings.TorDir).ConfigureAwait(false);
// File differs per platform.
- await ExtractZipFileAsync(Path.Combine(distributionFolder, $"tor-{GetPlatformIdentifier()}.zip"), torDir).ConfigureAwait(false);
+ await ExtractZipFileAsync(Path.Combine(settings.DistributionFolder, $"tor-{GetPlatformIdentifier()}.zip"), settings.TorDir).ConfigureAwait(false);
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Set sufficient file permission.
- string shellCommand = $"chmod -R 750 {torDir}";
+ string shellCommand = $"chmod -R 750 {settings.TorDir}";
await EnvironmentHelpers.ShellExecAsync(shellCommand, waitForExit: true).ConfigureAwait(false);
Logger.LogInfo($"Shell command executed: '{shellCommand}'.");
}

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -84,7 +84,7 @@ namespace WalletWasabi.Tor
if (!File.Exists(Settings.TorPath))
{
Logger.LogInfo($"Tor instance NOT found at '{Settings.TorPath}'. Attempting to acquire it ...");
- TorInstallator.InstallAsync(Settings.TorDir).GetAwaiter().GetResult();
+ TorInstallator.InstallAsync(Settings).GetAwaiter().GetResult();
}
else if (!IoHelpers.CheckExpectedHash(Settings.HashSourcePath, Path.Combine(fullBaseDirectory, "TorDaemons")))
{
@@ -97,7 +97,7 @@ namespace WalletWasabi.Tor
}
Directory.Move(Settings.TorDir, backupTorDir);
- TorInstallator.InstallAsync(Settings.TorDir).GetAwaiter().GetResult();
+ TorInstallator.InstallAsync(Settings).GetAwaiter().GetResult();
}
else
{

MODIFY
WalletWasabi/Tor/TorSettings.cs
WalletWasabi/Tor/TorSettings.cs
+using System;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
@@ -14,11 +15,13 @@ namespace WalletWasabi.Tor
/// </summary>
/// <param name="dataDir">Application data directory.</param>
/// <param name="logFilePath">Full Tor log file path.</param>
- public TorSettings(string dataDir, string logFilePath)
+ /// <param name="distributionFolderPath">Full path to folder containing Tor installation files.</param>
+ public TorSettings(string dataDir, string logFilePath, string distributionFolderPath)
{
TorDir = Path.Combine(dataDir, "tor");
TorDataDir = Path.Combine(dataDir, "tordata");
LogFilePath = logFilePath;
+ DistributionFolder = distributionFolderPath;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -47,6 +50,9 @@ namespace WalletWasabi.Tor
/// <summary>Full path. Directory may not necessarily exist.</summary>
public string LogFilePath { get; }
+ /// <summary>Full Tor distribution folder where Tor installation files are located.</summary>
+ public string DistributionFolder { get; }
+
/// <summary>Full path to Tor binary that is checked against a check sum.</summary>
public string HashSourcePath { get; }

Add DistributionFolderPath to TorSettings. Add TorSettings to tests/Global.