Implement Tor logging
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -197,7 +197,7 @@ namespace WalletWasabi.Gui
IndexDownloader?.Dispose();
Logger.LogInfo($"{nameof(IndexDownloader)} is stopped.", nameof(Global));
- Directory.CreateDirectory(Path.GetDirectoryName(AddressManagerFilePath));
+ IoHelpers.EnsureContainingDirectoryExists(AddressManagerFilePath);
AddressManager?.SavePeerFile(AddressManagerFilePath, Config.Network);
Logger.LogInfo($"{nameof(AddressManager)} is saved to `{AddressManagerFilePath}`.", nameof(Global));

MODIFY
WalletWasabi.Tests/LiveServerTests.cs
WalletWasabi.Tests/LiveServerTests.cs
@@ -28,7 +28,7 @@ namespace WalletWasabi.Tests
SharedFixture = sharedFixture;
LiveServerTestsFixture = liveServerTestsFixture;
- var torManager = new TorProcessManager(SharedFixture.TorSocks5Endpoint);
+ var torManager = new TorProcessManager(SharedFixture.TorSocks5Endpoint, SharedFixture.TorLogsFile);
torManager.StartAsync().GetAwaiter().GetResult();
}

MODIFY
WalletWasabi.Tests/P2pTests.cs
WalletWasabi.Tests/P2pTests.cs
@@ -157,7 +157,7 @@ namespace WalletWasabi.Tests
Directory.Delete(blocksFolderPath, recursive: true);
}
- Directory.CreateDirectory(Path.GetDirectoryName(addressManagerFilePath));
+ IoHelpers.EnsureContainingDirectoryExists(addressManagerFilePath);
addressManager?.SavePeerFile(addressManagerFilePath, network);
Logger.LogInfo<P2pTests>($"Saved {nameof(AddressManager)} to `{addressManagerFilePath}`.");
nodes?.Dispose();

MODIFY
WalletWasabi.Tests/TorTests.cs
WalletWasabi.Tests/TorTests.cs
@@ -18,7 +18,7 @@ namespace WalletWasabi.Tests
public TorTests(SharedFixture sharedFixture)
{
SharedFixture = sharedFixture;
- var torManager = new TorProcessManager(SharedFixture.TorSocks5Endpoint);
+ var torManager = new TorProcessManager(SharedFixture.TorSocks5Endpoint, SharedFixture.TorLogsFile);
torManager.StartAsync().GetAwaiter().GetResult();
}

MODIFY
WalletWasabi.Tests/XunitConfiguration/SharedFixture.cs
WalletWasabi.Tests/XunitConfiguration/SharedFixture.cs
@@ -23,6 +23,8 @@ namespace WalletWasabi.Tests.XunitConfiguration
}
}
+ public static string TorLogsFile => Path.Combine(DataDir, "TorLogs.txt");
+
public SharedFixture()
{
// Initialize tests...

MODIFY
WalletWasabi/Helpers/IoHelpers.cs
WalletWasabi/Helpers/IoHelpers.cs
@@ -169,5 +169,15 @@ namespace System.IO
safestFilePath = null;
return false;
}
+
+ public static void EnsureContainingDirectoryExists(string fileNameOrPath)
+ {
+ string fullPath = Path.GetFullPath(fileNameOrPath); // No matter if relative or absolute path is given to this.
+ string dir = Path.GetDirectoryName(fullPath);
+ if (!string.IsNullOrEmpty(dir)) // root
+ {
+ Directory.CreateDirectory(dir); // It does not fail if it exists.
+ }
+ }
}
}

MODIFY
WalletWasabi/KeyManagement/KeyManager.cs
WalletWasabi/KeyManagement/KeyManager.cs
@@ -105,13 +105,7 @@ namespace WalletWasabi.KeyManagement
{
FilePath = string.IsNullOrWhiteSpace(filePath) ? null : filePath;
if (FilePath == null) return;
- MakeSureContainingDirectoryExists(filePath);
- }
-
- private static void MakeSureContainingDirectoryExists(string filePath)
- {
- var directoryPath = Path.GetDirectoryName(Path.GetFullPath(filePath));
- Directory.CreateDirectory(directoryPath);
+ IoHelpers.EnsureContainingDirectoryExists(FilePath);
}
public void ToFile()
@@ -122,7 +116,7 @@ namespace WalletWasabi.KeyManagement
public void ToFile(string filePath)
{
- MakeSureContainingDirectoryExists(filePath);
+ IoHelpers.EnsureContainingDirectoryExists(filePath);
lock (ToFileLock)
{
string jsonString = JsonConvert.SerializeObject(this, Formatting.Indented);

MODIFY
WalletWasabi/Logging/Logger.cs
WalletWasabi/Logging/Logger.cs
@@ -97,8 +97,7 @@ namespace WalletWasabi.Logging
{
var encrypted = File.ReadAllText(FilePath);
- var dir = Path.GetDirectoryName(destination);
- Directory.CreateDirectory(dir);
+ IoHelpers.EnsureContainingDirectoryExists(destination);
foreach (var entry in encrypted.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
@@ -180,11 +179,7 @@ namespace WalletWasabi.Logging
if (!Modes.Contains(LogMode.File)) return;
- var dir = Path.GetDirectoryName(FilePath);
- if (dir != "")
- {
- Directory.CreateDirectory(dir);
- }
+ IoHelpers.EnsureContainingDirectoryExists(FilePath);
if (File.Exists(FilePath))
{

MODIFY
WalletWasabi/Services/IndexBuilderService.cs
WalletWasabi/Services/IndexBuilderService.cs
@@ -139,8 +139,7 @@ namespace WalletWasabi.Services
_running = 0;
- var indexDir = Path.GetDirectoryName(IndexFilePath);
- Directory.CreateDirectory(indexDir);
+ IoHelpers.EnsureContainingDirectoryExists(IndexFilePath);
if (File.Exists(IndexFilePath))
{
if (RpcClient.Network == Network.RegTest)
@@ -159,8 +158,7 @@ namespace WalletWasabi.Services
}
}
- var utxoSetDir = Path.GetDirectoryName(bech32UtxoSetFilePath);
- Directory.CreateDirectory(utxoSetDir);
+ IoHelpers.EnsureContainingDirectoryExists(bech32UtxoSetFilePath);
if (File.Exists(bech32UtxoSetFilePath))
{
if (RpcClient.Network == Network.RegTest)

MODIFY
WalletWasabi/Services/IndexDownloader.cs
WalletWasabi/Services/IndexDownloader.cs
@@ -143,11 +143,7 @@ namespace WalletWasabi.Services
_running = 0;
Cancel = new CancellationTokenSource();
- var indexDir = Path.GetDirectoryName(IndexFilePath);
- if (!string.IsNullOrEmpty(indexDir))
- {
- Directory.CreateDirectory(indexDir);
- }
+ IoHelpers.EnsureContainingDirectoryExists(indexFilePath);
if (File.Exists(IndexFilePath))
{
if (Network == Network.RegTest)

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -1029,8 +1029,7 @@ namespace WalletWasabi.Services
IndexDownloader.Reorged -= IndexDownloader_ReorgedAsync;
MemPool.TransactionReceived -= MemPool_TransactionReceived;
- var directoryPath = Path.GetDirectoryName(Path.GetFullPath(TransactionsFilePath));
- Directory.CreateDirectory(directoryPath);
+ IoHelpers.EnsureContainingDirectoryExists(TransactionsFilePath);
string jsonString = JsonConvert.SerializeObject(TransactionCache, Formatting.Indented);
File.WriteAllText(TransactionsFilePath,
jsonString,

MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -17,11 +17,14 @@ namespace WalletWasabi.TorSocks5
public class TorProcessManager
{
public IPEndPoint TorSocks5EndPoint { get; }
+ public string LogFile { get; }
/// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
- public TorProcessManager(IPEndPoint torSocks5EndPoint)
+ /// <param name="logFile">Opt out of logging with null.</param>
+ public TorProcessManager(IPEndPoint torSocks5EndPoint, string logFile)
{
TorSocks5EndPoint = torSocks5EndPoint ?? new IPEndPoint(IPAddress.Loopback, 9050);
+ LogFile = logFile;
}
public async Task StartAsync()
@@ -99,11 +102,19 @@ namespace WalletWasabi.TorSocks5
Logger.LogInfo<TorProcessManager>($"Tor instance found at {torPath}.");
}
+ string torArguments = $"--SOCKSPort {TorSocks5EndPoint.Port}";
+ if (!string.IsNullOrEmpty(LogFile))
+ {
+ IoHelpers.EnsureContainingDirectoryExists(LogFile);
+ var logFileFullPath = Path.GetFullPath(LogFile);
+ torArguments += $" --Log \"notice file {logFileFullPath}\"";
+ }
+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var torProcessStartInfo = new ProcessStartInfo(torPath)
{
- Arguments = $"SOCKSPort {TorSocks5EndPoint.Port}",
+ Arguments = torArguments,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
@@ -113,7 +124,7 @@ namespace WalletWasabi.TorSocks5
}
else // Linux and OSX
{
- string runTorCmd = $"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:={torDir}/Tor && export LD_LIBRARY_PATH && cd {torDir}/Tor && ./tor SOCKSPort {TorSocks5EndPoint.Port}";
+ string runTorCmd = $"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:={torDir}/Tor && export LD_LIBRARY_PATH && cd {torDir}/Tor && ./tor {torArguments}";
EnvironmentHelpers.ShellExec(runTorCmd, false);
Logger.LogInfo<TorProcessManager>($"Started Tor process with shell command: {runTorCmd}.");
}

Implement Tor logging