TorSettings: Add OwningProcessId.
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -84,7 +84,7 @@ namespace WalletWasabi.Gui
DataDir = dataDir;
Config = config;
UiConfig = uiConfig;
- TorSettings = new TorSettings(DataDir, torLogsFile, distributionFolderPath: EnvironmentHelpers.GetFullBaseDirectory(), Config.TerminateTorOnExit);
+ TorSettings = new TorSettings(DataDir, torLogsFile, distributionFolderPath: EnvironmentHelpers.GetFullBaseDirectory(), Config.TerminateTorOnExit, Environment.ProcessId);
HostedServices = new HostedServices();
WalletManager = walletManager;

MODIFY
WalletWasabi.Tests/UnitTests/Tor/TorSettingsTests.cs
WalletWasabi.Tests/UnitTests/Tor/TorSettingsTests.cs
@@ -17,7 +17,7 @@ namespace WalletWasabi.Tests.UnitTests.Tor
string logFilePath = Path.Combine("temp", "Tor.log");
string distributionFolder = "tempDistributionDir";
- TorSettings settings = new(dataDir, logFilePath, distributionFolder, terminateOnExit: false);
+ TorSettings settings = new(dataDir, logFilePath, distributionFolder, terminateOnExit: false, owningProcessId: 7);
IPEndPoint endpoint = new(IPAddress.Loopback, WalletWasabi.Helpers.Constants.DefaultTorSocksPort);
string arguments = settings.GetCmdArguments(endpoint);
@@ -31,7 +31,8 @@ namespace WalletWasabi.Tests.UnitTests.Tor
$"--DataDirectory \"{Path.Combine("temp", "tempDataDir", "tordata")}\"",
$"--GeoIPFile \"{Path.Combine("tempDistributionDir", "Tor", "Geoip", "geoip")}\"",
$"--GeoIPv6File \"{Path.Combine("tempDistributionDir", "Tor", "Geoip", "geoip6")}\"",
- $"--Log \"notice file {Path.Combine("temp", "Tor.log")}\"");
+ $"--Log \"notice file {Path.Combine("temp", "Tor.log")}\"",
+ $"__OwningControllerProcess 7");
Assert.Equal(expected, arguments);
}

MODIFY
WalletWasabi/Tor/TorSettings.cs
WalletWasabi/Tor/TorSettings.cs
+using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
@@ -16,7 +17,7 @@ namespace WalletWasabi.Tor
/// <param name="dataDir">Application data directory.</param>
/// <param name="logFilePath">Full Tor log file path.</param>
/// <param name="distributionFolderPath">Full path to folder containing Tor installation files.</param>
- public TorSettings(string dataDir, string logFilePath, string distributionFolderPath, bool terminateOnExit)
+ public TorSettings(string dataDir, string logFilePath, string distributionFolderPath, bool terminateOnExit, int? owningProcessId = null)
{
TorBinaryFilePath = GetTorBinaryFilePath();
TorBinaryDir = Path.Combine(MicroserviceHelpers.GetBinaryFolder(), "Tor");
@@ -27,6 +28,7 @@ namespace WalletWasabi.Tor
IoHelpers.EnsureContainingDirectoryExists(LogFilePath);
DistributionFolder = distributionFolderPath;
TerminateOnExit = terminateOnExit;
+ OwningProcessId = owningProcessId;
GeoIpPath = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip");
GeoIp6Path = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip6");
}
@@ -46,6 +48,9 @@ namespace WalletWasabi.Tor
/// <summary>Whether Tor should be terminated when Wasabi Wallet terminates.</summary>
public bool TerminateOnExit { get; }
+ /// <summary>Owning process ID for Tor program.</summary>
+ public int? OwningProcessId { get; }
+
/// <summary>Full path to executable file that is used to start Tor process.</summary>
public string TorBinaryFilePath { get; }
@@ -69,8 +74,8 @@ namespace WalletWasabi.Tor
public string GetCmdArguments(EndPoint torSocks5EndPoint)
{
- return string.Join(
- " ",
+ List<string> arguments = new()
+ {
$"--SOCKSPort {torSocks5EndPoint}",
$"--CookieAuthentication 1",
$"--ControlPort {ControlEndpoint.Port}",
@@ -78,7 +83,15 @@ namespace WalletWasabi.Tor
$"--DataDirectory \"{TorDataDir}\"",
$"--GeoIPFile \"{GeoIpPath}\"",
$"--GeoIPv6File \"{GeoIp6Path}\"",
- $"--Log \"notice file {LogFilePath}\"");
+ $"--Log \"notice file {LogFilePath}\""
+ };
+
+ if (OwningProcessId is not null)
+ {
+ arguments.Add($"__OwningControllerProcess {OwningProcessId}");
+ }
+
+ return string.Join(" ", arguments);
}
}
}

TorSettings: Add OwningProcessId.