Add verification to TorInstallator.
MODIFY
WalletWasabi/Tor/TorInstallator.cs
WalletWasabi/Tor/TorInstallator.cs
+using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
@@ -11,30 +12,59 @@ namespace WalletWasabi.Tor
/// </summary>
public class TorInstallator
{
- public static async Task InstallAsync(TorSettings settings)
+ /// <summary>
+ /// Creates new instance.
+ /// </summary>
+ public TorInstallator(TorSettings settings)
+ {
+ Settings = settings;
+ }
+
+ /// <summary>Tor settings containing all necessary settings for Tor installation and running.</summary>
+ public TorSettings Settings { get; }
+
+ /// <summary>
+ /// Installs Tor for Wasabi Wallet use.
+ /// </summary>
+ /// <returns><see cref="Task"/> instance.</returns>
+ public async Task<bool> InstallAsync()
+ {
+ try
{
// Common for all platforms.
- await ExtractZipFileAsync(Path.Combine(settings.DistributionFolder, "data-folder.zip"), settings.TorDir).ConfigureAwait(false);
+ await ExtractZipFileAsync(Path.Combine(Settings.DistributionFolder, "data-folder.zip"), Settings.TorDir).ConfigureAwait(false);
// File differs per platform.
- await ExtractZipFileAsync(Path.Combine(settings.DistributionFolder, $"tor-{GetPlatformIdentifier()}.zip"), settings.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 {settings.TorDir}";
+ string shellCommand = $"chmod -R 750 {Settings.TorDir}";
await EnvironmentHelpers.ShellExecAsync(shellCommand, waitForExit: true).ConfigureAwait(false);
Logger.LogInfo($"Shell command executed: '{shellCommand}'.");
}
+
+ bool verification = File.Exists(Settings.TorBinaryFilePath);
+
+ Logger.LogDebug($"Tor installation finished. Installed correctly? {verification}.");
+ return verification;
+ }
+ catch (Exception e)
+ {
+ Logger.LogError("Tor installation failed.", e);
+ }
+
+ return false;
}
- private static async Task ExtractZipFileAsync(string zipFilePath, string destinationPath)
+ private async Task ExtractZipFileAsync(string zipFilePath, string destinationPath)
{
await IoHelpers.BetterExtractZipToDirectoryAsync(zipFilePath, destinationPath).ConfigureAwait(false);
Logger.LogInfo($"Extracted '{zipFilePath}' to '{destinationPath}'.");
}
- private static string GetPlatformIdentifier()
+ private string GetPlatformIdentifier()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -82,10 +82,10 @@ namespace WalletWasabi.Tor
var fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();
- if (!File.Exists(Settings.TorPath))
+ if (!File.Exists(Settings.TorBinaryFilePath))
{
- Logger.LogInfo($"Tor instance NOT found at '{Settings.TorPath}'. Attempting to acquire it ...");
- TorInstallator.InstallAsync(Settings).GetAwaiter().GetResult();
+ Logger.LogInfo($"Tor instance NOT found at '{Settings.TorBinaryFilePath}'. Attempting to acquire it ...");
+ new TorInstallator(Settings).InstallAsync().GetAwaiter().GetResult();
}
else if (!IoHelpers.CheckExpectedHash(Settings.HashSourcePath, Path.Combine(fullBaseDirectory, "TorDaemons")))
{
@@ -98,11 +98,11 @@ namespace WalletWasabi.Tor
}
Directory.Move(Settings.TorDir, backupTorDir);
- TorInstallator.InstallAsync(Settings).GetAwaiter().GetResult();
+ new TorInstallator(Settings).InstallAsync().GetAwaiter().GetResult();
}
else
{
- Logger.LogInfo($"Tor instance found at '{Settings.TorPath}'.");
+ Logger.LogInfo($"Tor instance found at '{Settings.TorBinaryFilePath}'.");
}
string torArguments = Settings.GetCmdArguments(TorSocks5EndPoint);
@@ -116,7 +116,7 @@ namespace WalletWasabi.Tor
var startInfo = new ProcessStartInfo
{
- FileName = Settings.TorPath,
+ FileName = Settings.TorBinaryFilePath,
Arguments = torArguments,
UseShellExecute = false,
CreateNoWindow = true,

MODIFY
WalletWasabi/Tor/TorSettings.cs
WalletWasabi/Tor/TorSettings.cs
@@ -26,14 +26,14 @@ namespace WalletWasabi.Tor
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- TorPath = $@"{TorBinaryDir}\tor.exe";
+ TorBinaryFilePath = $@"{TorBinaryDir}\tor.exe";
HashSourcePath = $@"{TorBinaryDir}\tor.exe";
GeoIpPath = $@"{TorDir}\Data\Tor\geoip";
GeoIp6Path = $@"{TorDir}\Data\Tor\geoip6";
}
else
{
- TorPath = $@"{TorBinaryDir}/tor";
+ TorBinaryFilePath = $@"{TorBinaryDir}/tor";
HashSourcePath = RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
? $@"{TorBinaryDir}/tor.real"
: $@"{TorBinaryDir}/tor";
@@ -62,7 +62,7 @@ namespace WalletWasabi.Tor
public string HashSourcePath { get; }
/// <summary>Full path to executable file that is used to start Tor process.</summary>
- public string TorPath { get; }
+ public string TorBinaryFilePath { get; }
private string GeoIpPath { get; }
private string GeoIp6Path { get; }

Add verification to TorInstallator.