TorSettings: Add "GetTorBinaryFilePath".
MODIFY
WalletWasabi.Tests/UnitTests/Tor/TorBinaryHashesTests.cs
WalletWasabi.Tests/UnitTests/Tor/TorBinaryHashesTests.cs
@@ -4,7 +4,7 @@ using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Threading;
-using WalletWasabi.Microservices;
+using WalletWasabi.Tor;
using Xunit;
namespace WalletWasabi.Tests.UnitTests.Tor
@@ -23,14 +23,13 @@ namespace WalletWasabi.Tests.UnitTests.Tor
{ OSPlatform.OSX, "fe6d719e18bf3a963f0274de259b7e029f40e4fe778f4d170bba343eb491af00" },
};
- foreach (var item in expectedHashes)
+ foreach ((OSPlatform platform, string expectedHash) in expectedHashes)
{
- string binaryFolder = Path.Combine(MicroserviceHelpers.GetBinaryFolder(item.Key), "Tor");
- string filePath = Path.Combine(binaryFolder, item.Key == OSPlatform.Windows ? "tor.exe" : item.Key == OSPlatform.Linux ? "tor" : "tor.real");
+ string filePath = TorSettings.GetTorBinaryFilePath(platform);
using SHA256 sha256 = SHA256.Create();
using FileStream fileStream = File.OpenRead(filePath);
- Assert.Equal(item.Value, ByteHelpers.ToHex(sha256.ComputeHash(fileStream)).ToLowerInvariant());
+ Assert.Equal(expectedHash, ByteHelpers.ToHex(sha256.ComputeHash(fileStream)).ToLowerInvariant());
}
}
}

MODIFY
WalletWasabi/Microservices/MicroserviceHelpers.cs
WalletWasabi/Microservices/MicroserviceHelpers.cs
@@ -7,43 +7,45 @@ namespace WalletWasabi.Microservices
{
public static class MicroserviceHelpers
{
- public static string GetBinaryFolder()
+ public static OSPlatform GetCurrentPlatform()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- return GetBinaryFolder(OSPlatform.Windows);
+ return OSPlatform.Windows;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
- return GetBinaryFolder(OSPlatform.Linux);
+ return OSPlatform.Linux;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
- return GetBinaryFolder(OSPlatform.OSX);
+ return OSPlatform.OSX;
}
else
{
- throw new NotSupportedException("Operating system is not supported.");
+ throw new NotSupportedException("Platform is not supported.");
}
}
- public static string GetBinaryFolder(OSPlatform platform)
+ public static string GetBinaryFolder(OSPlatform? platform = null)
{
- var fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();
+ platform ??= GetCurrentPlatform();
+ string fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();
string commonPartialPath = Path.Combine(fullBaseDirectory, "Microservices", "Binaries");
+
string path;
if (platform == OSPlatform.Windows)
{
- path = Path.Combine(commonPartialPath, $"win64");
+ path = Path.Combine(commonPartialPath, "win64");
}
else if (platform == OSPlatform.Linux)
{
- path = Path.Combine(commonPartialPath, $"lin64");
+ path = Path.Combine(commonPartialPath, "lin64");
}
else if (platform == OSPlatform.OSX)
{
- path = Path.Combine(commonPartialPath, $"osx64");
+ path = Path.Combine(commonPartialPath, "osx64");
}
else
{
@@ -53,9 +55,13 @@ namespace WalletWasabi.Microservices
return path;
}
- public static string GetBinaryPath(string binaryNameWithoutExtension)
+ public static string GetBinaryPath(string binaryNameWithoutExtension, OSPlatform? platform = null)
{
- return Path.Combine(GetBinaryFolder(), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? $"{binaryNameWithoutExtension}.exe" : $"{binaryNameWithoutExtension}");
+ platform ??= GetCurrentPlatform();
+ string binaryFolder = GetBinaryFolder(platform);
+ string fileName = platform.Value == OSPlatform.Windows ? $"{binaryNameWithoutExtension}.exe" : $"{binaryNameWithoutExtension}";
+
+ return Path.Combine(binaryFolder, fileName);
}
}
}

MODIFY
WalletWasabi/Tor/TorSettings.cs
WalletWasabi/Tor/TorSettings.cs
@@ -18,8 +18,7 @@ namespace WalletWasabi.Tor
/// <param name="distributionFolderPath">Full path to folder containing Tor installation files.</param>
public TorSettings(string dataDir, string logFilePath, string distributionFolderPath)
{
- var torBinary = MicroserviceHelpers.GetBinaryPath(Path.Combine("Tor", "tor"));
- TorBinaryFilePath = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? $"{torBinary}.real" : torBinary;
+ TorBinaryFilePath = GetTorBinaryFilePath();
TorBinaryDir = Path.Combine(MicroserviceHelpers.GetBinaryFolder(), "Tor");
TorDataDir = Path.Combine(dataDir, "tordata");
@@ -48,6 +47,15 @@ namespace WalletWasabi.Tor
private string GeoIpPath { get; }
private string GeoIp6Path { get; }
+ /// <returns>Full path to Tor binary for selected <paramref name="platform"/>.</returns>
+ public static string GetTorBinaryFilePath(OSPlatform? platform = null)
+ {
+ platform ??= MicroserviceHelpers.GetCurrentPlatform();
+
+ string binaryPath = MicroserviceHelpers.GetBinaryPath(Path.Combine("Tor", "tor"), platform);
+ return platform == OSPlatform.OSX ? $"{binaryPath}.real" : binaryPath;
+ }
+
public string GetCmdArguments(EndPoint torSocks5EndPoint)
{
return string.Join(

TorSettings: Add "GetTorBinaryFilePath".

Signed-off-by: Kiminuo <kiminuo@protonmail.com>