StartAsync returns bool now.
MODIFY
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
@@ -28,7 +28,8 @@ namespace WalletWasabi.Tests.IntegrationTests
public async Task InitializeAsync()
{
var torManager = new TorProcessManager(Global.Instance.TorSettings, Global.Instance.TorSocks5Endpoint);
- await torManager.StartAsync(ensureRunning: true);
+ bool started = await torManager.StartAsync(ensureRunning: true);
+ Assert.True(started, "Tor failed to start.");
}
public Task DisposeAsync()

MODIFY
WalletWasabi.Tests/IntegrationTests/TorTests.cs
WalletWasabi.Tests/IntegrationTests/TorTests.cs
@@ -16,7 +16,8 @@ namespace WalletWasabi.Tests.IntegrationTests
public async Task InitializeAsync()
{
var torManager = new TorProcessManager(Global.Instance.TorSettings, Global.Instance.TorSocks5Endpoint);
- await torManager.StartAsync(ensureRunning: true);
+ bool started = await torManager.StartAsync(ensureRunning: true);
+ Assert.True(started, "Tor failed to start.");
}
public Task DisposeAsync()

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -62,9 +62,14 @@ namespace WalletWasabi.Tor
private CancellationTokenSource Stop { get; set; }
- public async Task StartAsync(bool ensureRunning)
- {
- try
+ /// <summary>
+ /// Installs Tor if it is not installed, then it starts Tor.
+ /// </summary>
+ /// <param name="ensureRunning">
+ /// If <c>false</c>, Tor is started but no attempt to verify that it actually runs is made.
+ /// <para>If <c>true</c>, we start Tor and attempt to connect to it to verify it is running (at most 10 attempts).</para>
+ /// </param>
+ public async Task<bool> StartAsync(bool ensureRunning)
{
try
{
@@ -77,7 +82,7 @@ namespace WalletWasabi.Tor
? $"Tor is already running on {endpoint.Address}:{endpoint.Port}."
: "Tor is already running.";
Logger.LogInfo(msg);
- return;
+ return true;
}
// Install Tor if it is not installed and verify Tor is not tampered with (using hash/checksum).
@@ -86,7 +91,7 @@ namespace WalletWasabi.Tor
if (!verified)
{
Logger.LogInfo("Failed to verify Tor installation.");
- return;
+ return false;
}
string torArguments = Settings.GetCmdArguments(TorSocks5EndPoint) + $" --Log \"notice file {Settings.LogFilePath}\"";
@@ -131,28 +136,28 @@ namespace WalletWasabi.Tor
break;
}
- // At most 10 attempts.
- if (i >= 10)
+ const int MaxAttempts = 15;
+
+ if (i >= MaxAttempts)
{
- throw new TorException("Attempted to start Tor, but it is not running.");
+ Logger.LogError($"All {MaxAttempts} attempts to connect to Tor failed.");
+ return false;
}
- // Wait 1500 milliseconds between attempts.
- await Task.Delay(1500).ConfigureAwait(false);
+ // Wait 750 milliseconds between attempts.
+ await Task.Delay(500).ConfigureAwait(false);
}
Logger.LogInfo("Tor is running.");
+ return true;
}
}
catch (Exception ex)
{
- throw new TorException("Could not automatically start Tor. Try running Tor manually.", ex);
- }
- }
- catch (Exception ex)
- {
- Logger.LogError(ex);
+ Logger.LogError("Could not automatically start Tor. Try running Tor manually.", ex);
}
+
+ return false;
}
/// <param name="torSocks5EndPoint">Opt out Tor with null.</param>

StartAsync returns bool now.