Move settings to constructor.
MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -39,9 +39,9 @@ namespace WalletWasabi.TorSocks5
TorSocks5EndPoint = torSocks5EndPoint;
LogFile = logFile;
_monitorState = StateNotStarted;
- DataDir = dataDir;
Stop = new CancellationTokenSource();
TorProcess = null;
+ Settings = new TorSettings(dataDir);
}
/// <summary>
@@ -51,12 +51,12 @@ namespace WalletWasabi.TorSocks5
public string LogFile { get; }
- private string DataDir { get; }
-
public static bool RequestFallbackAddressUsage { get; private set; } = false;
public Process TorProcess { get; private set; }
+ private TorSettings Settings { get; }
+
public bool IsRunning => Interlocked.Read(ref _monitorState) == StateRunning;
private CancellationTokenSource Stop { get; set; }
@@ -91,32 +91,31 @@ namespace WalletWasabi.TorSocks5
}
var fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();
- var settings = new TorSettings(DataDir);
- if (!File.Exists(settings.TorPath))
+ if (!File.Exists(Settings.TorPath))
{
- Logger.LogInfo($"Tor instance NOT found at '{settings.TorPath}'. Attempting to acquire it ...");
- InstallTor(settings.TorDir);
+ Logger.LogInfo($"Tor instance NOT found at '{Settings.TorPath}'. Attempting to acquire it ...");
+ InstallTor(Settings.TorDir);
}
- else if (!IoHelpers.CheckExpectedHash(settings.HashSourcePath, Path.Combine(fullBaseDirectory, "TorDaemons")))
+ else if (!IoHelpers.CheckExpectedHash(Settings.HashSourcePath, Path.Combine(fullBaseDirectory, "TorDaemons")))
{
Logger.LogInfo($"Updating Tor...");
- string backupTorDir = $"{settings.TorDir}_backup";
+ string backupTorDir = $"{Settings.TorDir}_backup";
if (Directory.Exists(backupTorDir))
{
Directory.Delete(backupTorDir, true);
}
- Directory.Move(settings.TorDir, backupTorDir);
+ Directory.Move(Settings.TorDir, backupTorDir);
- InstallTor(settings.TorDir);
+ InstallTor(Settings.TorDir);
}
else
{
- Logger.LogInfo($"Tor instance found at '{settings.TorPath}'.");
+ Logger.LogInfo($"Tor instance found at '{Settings.TorPath}'.");
}
- string torArguments = settings.GetCmdArguments(TorSocks5EndPoint);
+ string torArguments = Settings.GetCmdArguments(TorSocks5EndPoint);
if (!string.IsNullOrEmpty(LogFile))
{
@@ -129,7 +128,7 @@ namespace WalletWasabi.TorSocks5
{
TorProcess = Process.Start(new ProcessStartInfo
{
- FileName = settings.TorPath,
+ FileName = Settings.TorPath,
Arguments = torArguments,
UseShellExecute = false,
CreateNoWindow = true,
@@ -139,7 +138,7 @@ namespace WalletWasabi.TorSocks5
}
else // Linux and OSX
{
- string runTorCmd = $"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:='{settings.TorDir}/Tor' && export LD_LIBRARY_PATH && cd '{settings.TorDir}/Tor' && ./tor {torArguments}";
+ string runTorCmd = $"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:='{Settings.TorDir}/Tor' && export LD_LIBRARY_PATH && cd '{Settings.TorDir}/Tor' && ./tor {torArguments}";
EnvironmentHelpers.ShellExecAsync(runTorCmd, waitForExit: false).GetAwaiter().GetResult();
Logger.LogInfo($"Started Tor process with shell command: {runTorCmd}.");
}

Move settings to constructor.