Move the rest of installation stuff from TorProcessManager to TorInstallator.
MODIFY
WalletWasabi/Tor/TorInstallator.cs
WalletWasabi/Tor/TorInstallator.cs
@@ -26,7 +26,7 @@ namespace WalletWasabi.Tor
/// <summary>
/// Installs Tor for Wasabi Wallet use.
/// </summary>
- /// <returns><see cref="Task"/> instance.</returns>
+ /// <returns>Returns <c>true</c> if <see cref="TorSettings.TorBinaryFilePath"/> is present after installation, <c>false</c> otherwise.</returns>
public async Task<bool> InstallAsync()
{
try
@@ -58,6 +58,45 @@ namespace WalletWasabi.Tor
return false;
}
+ /// <summary>
+ /// Verifies that Tor is installed and checksums of installed binaries are correct.
+ /// </summary>
+ /// <returns>Returns <c>true</c> if <see cref="TorSettings.TorBinaryFilePath"/> is present, <c>false</c> otherwise.</returns>
+ public async Task<bool> VerifyInstallationAsync()
+ {
+ try
+ {
+ if (!File.Exists(Settings.TorBinaryFilePath))
+ {
+ Logger.LogInfo($"Tor instance NOT found at '{Settings.TorBinaryFilePath}'. Attempting to acquire it.");
+ return await InstallAsync().ConfigureAwait(false);
+ }
+ else if (!IoHelpers.CheckExpectedHash(Settings.HashSourcePath, Settings.DistributionFolder))
+ {
+ Logger.LogInfo("Install the latest Tor version.");
+ string backupDir = $"{Settings.TorDir}_backup";
+
+ if (Directory.Exists(backupDir))
+ {
+ Directory.Delete(backupDir, recursive: true);
+ }
+
+ Directory.Move(Settings.TorDir, backupDir);
+ return await InstallAsync().ConfigureAwait(false);
+ }
+ else
+ {
+ Logger.LogInfo($"Tor instance found at '{Settings.TorBinaryFilePath}'.");
+ return true;
+ }
+ }
+ catch (Exception e)
+ {
+ Logger.LogError("Verification of Tor installation failed.", e);
+ return false;
+ }
+ }
+
private async Task ExtractZipFileAsync(string zipFilePath, string destinationPath)
{
await IoHelpers.BetterExtractZipToDirectoryAsync(zipFilePath, destinationPath).ConfigureAwait(false);

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -6,7 +6,6 @@ using System.Net.Http;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
-using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Microservices;
using WalletWasabi.Tor.Exceptions;
@@ -80,30 +79,7 @@ namespace WalletWasabi.Tor
return;
}
- var fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();
-
- if (!File.Exists(Settings.TorBinaryFilePath))
- {
- 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")))
- {
- Logger.LogInfo($"Updating Tor...");
-
- string backupTorDir = $"{Settings.TorDir}_backup";
- if (Directory.Exists(backupTorDir))
- {
- Directory.Delete(backupTorDir, true);
- }
- Directory.Move(Settings.TorDir, backupTorDir);
-
- new TorInstallator(Settings).InstallAsync().GetAwaiter().GetResult();
- }
- else
- {
- Logger.LogInfo($"Tor instance found at '{Settings.TorBinaryFilePath}'.");
- }
+ new TorInstallator(Settings).VerifyInstallationAsync().GetAwaiter().GetResult();
string torArguments = Settings.GetCmdArguments(TorSocks5EndPoint);

Move the rest of installation stuff from TorProcessManager to TorInstallator.