Try run Tor start async
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -15,6 +15,7 @@ using WalletWasabi.Helpers;
using WalletWasabi.KeyManagement;
using WalletWasabi.Logging;
using WalletWasabi.Services;
+using WalletWasabi.TorSocks5;
namespace WalletWasabi.Gui
{
@@ -34,6 +35,20 @@ namespace WalletWasabi.Gui
}
}
+ private static string _torLogsFile = null;
+
+ public static string TorLogsFile
+ {
+ get
+ {
+ if (!string.IsNullOrWhiteSpace(_torLogsFile)) return _torLogsFile;
+
+ _torLogsFile = Path.Combine(DataDir, "TorLogs.txt");
+
+ return _torLogsFile;
+ }
+ }
+
public static string WalletsDir => Path.Combine(DataDir, "Wallets");
public static string WalletBackupsDir => Path.Combine(DataDir, "WalletBackups");
public static Network Network => Config.Network;
@@ -50,6 +65,7 @@ namespace WalletWasabi.Gui
public static WalletService WalletService { get; private set; }
public static Node RegTestMemPoolServingNode { get; private set; }
public static UpdateChecker UpdateChecker { get; private set; }
+ public static TorProcessManager TorManager { get; private set; }
public static Config Config { get; private set; }
@@ -68,6 +84,12 @@ namespace WalletWasabi.Gui
var blocksFolderPath = Path.Combine(DataDir, $"Blocks{Network}");
var connectionParameters = new NodeConnectionParameters();
AddressManager = null;
+ TorManager = null;
+
+ TorManager = new TorProcessManager(Config.GetTorSocks5EndPoint(), TorLogsFile);
+ TorManager.Start();
+
+ Logger.LogInfo<TorProcessManager>($"Fake {nameof(TorProcessManager)} is initialized.");
if (Network == Network.RegTest)
{

MODIFY
WalletWasabi.Tests/LiveServerTests.cs
WalletWasabi.Tests/LiveServerTests.cs
@@ -29,7 +29,12 @@ namespace WalletWasabi.Tests
LiveServerTestsFixture = liveServerTestsFixture;
var torManager = new TorProcessManager(SharedFixture.TorSocks5Endpoint, SharedFixture.TorLogsFile);
- torManager.StartAsync().GetAwaiter().GetResult();
+ torManager.Start();
+ Task.Delay(3000).GetAwaiter().GetResult();
+ if (!torManager.IsTorRunningAsync().GetAwaiter().GetResult())
+ {
+ throw new Exception("Tor is not running");
+ }
}
#region Blockchain

MODIFY
WalletWasabi.Tests/TorTests.cs
WalletWasabi.Tests/TorTests.cs
@@ -19,7 +19,12 @@ namespace WalletWasabi.Tests
{
SharedFixture = sharedFixture;
var torManager = new TorProcessManager(SharedFixture.TorSocks5Endpoint, SharedFixture.TorLogsFile);
- torManager.StartAsync().GetAwaiter().GetResult();
+ torManager.Start();
+ Task.Delay(3000).GetAwaiter().GetResult();
+ if (!torManager.IsTorRunningAsync().GetAwaiter().GetResult())
+ {
+ throw new Exception("Tor is not running");
+ }
}
[Fact]

MODIFY
WalletWasabi.Tests/XunitConfiguration/SharedFixture.cs
WalletWasabi.Tests/XunitConfiguration/SharedFixture.cs
@@ -8,9 +8,10 @@ namespace WalletWasabi.Tests.XunitConfiguration
{
public class SharedFixture : IDisposable
{
- private static string _dataDir = null;
public static IPEndPoint TorSocks5Endpoint { get; } = new IPEndPoint(IPAddress.Loopback, 9050);
+ private static string _dataDir = null;
+
public static string DataDir
{
get
@@ -23,7 +24,19 @@ namespace WalletWasabi.Tests.XunitConfiguration
}
}
- public static string TorLogsFile => Path.Combine(DataDir, "TorLogs.txt");
+ private static string _torLogsFile = null;
+
+ public static string TorLogsFile
+ {
+ get
+ {
+ if (!string.IsNullOrWhiteSpace(_torLogsFile)) return _torLogsFile;
+
+ _torLogsFile = Path.Combine(DataDir, "TorLogs.txt");
+
+ return _torLogsFile;
+ }
+ }
public SharedFixture()
{

MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -27,7 +27,11 @@ namespace WalletWasabi.TorSocks5
LogFile = logFile;
}
- public async Task StartAsync()
+ public void Start()
+ {
+ Task.Run(async () =>
+ {
+ try
{
// 1. Is it already running?
// 2. Can I simply run it from output directory?
@@ -129,7 +133,7 @@ namespace WalletWasabi.TorSocks5
Logger.LogInfo<TorProcessManager>($"Started Tor process with shell command: {runTorCmd}.");
}
- await Task.Delay(1000).ConfigureAwait(false); // dotnet brainfart, ConfigureAwait(false) IS NEEDED HERE otherwise (only on) Manjuro Linux fails, WTF?!!
+ await Task.Delay(3000).ConfigureAwait(false); // dotnet brainfart, ConfigureAwait(false) IS NEEDED HERE otherwise (only on) Manjuro Linux fails, WTF?!!
if (!await IsTorRunningAsync(TorSocks5EndPoint))
{
throw new TorException("Attempted to start Tor, but it is not running.");
@@ -141,6 +145,12 @@ namespace WalletWasabi.TorSocks5
throw new TorException("Could not automatically start Tor. Try running Tor manually.", ex);
}
}
+ catch (Exception ex)
+ {
+ Logger.LogError<TorProcessManager>(ex);
+ }
+ });
+ }
/// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
public static async Task<bool> IsTorRunningAsync(IPEndPoint torSocks5EndPoint)
@@ -159,5 +169,22 @@ namespace WalletWasabi.TorSocks5
return true;
}
}
+
+ public async Task<bool> IsTorRunningAsync()
+ {
+ using (var client = new TorSocks5Client(TorSocks5EndPoint))
+ {
+ try
+ {
+ await client.ConnectAsync();
+ await client.HandshakeAsync();
+ }
+ catch (ConnectionException)
+ {
+ return false;
+ }
+ return true;
+ }
+ }
}
}

Try run Tor start async