Use fixed Tor socks to ensure launching our own Tor process
MODIFY
WalletWasabi.Documentation/Ports.md
WalletWasabi.Documentation/Ports.md
@@ -17,6 +17,7 @@ HiddenWallet's ports (3712x) are chosen within a long range of unassigned IANA p
|37129 | Wallet Wasabi Local Client TCPListener on MainNet |
|37130 | Wallet Wasabi Local Client TCPListener on TestNet |
|37131 | Wallet Wasabi Local Client TCPListener on RegTest |
+|37150 | Tor socks port used by Wallet Wasabi |
|37151 | Tor control port used by Wallet Wasabi |
|9050 | Default Tor socks port |
|9051 | Default Tor control port |

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/NetworkSettingsTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/NetworkSettingsTabViewModel.cs
@@ -24,47 +24,23 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
{
[AutoNotify] private bool _useTor;
[AutoNotify] private bool _terminateTorOnExit;
- [AutoNotify] private string _torSocks5EndPoint;
public NetworkSettingsTabViewModel()
{
- this.ValidateProperty(x => x.TorSocks5EndPoint, ValidateTorSocks5EndPoint);
-
_useTor = Services.Config.UseTor;
_terminateTorOnExit = Services.Config.TerminateTorOnExit;
- _torSocks5EndPoint = Services.Config.TorSocks5EndPoint.ToString(-1);
this.WhenAnyValue(
x => x.UseTor,
- x => x.TerminateTorOnExit,
- x => x.TorSocks5EndPoint)
+ x => x.TerminateTorOnExit)
.ObserveOn(RxApp.TaskpoolScheduler)
.Throttle(TimeSpan.FromMilliseconds(ThrottleTime))
.Skip(1)
.Subscribe(_ => Save());
}
- private void ValidateTorSocks5EndPoint(IValidationErrors errors)
- => ValidateEndPoint(errors, TorSocks5EndPoint, Constants.DefaultTorSocksPort, whiteSpaceOk: true);
-
- private static void ValidateEndPoint(IValidationErrors errors, string endPoint, int defaultPort, bool whiteSpaceOk)
- {
- if (!whiteSpaceOk || !string.IsNullOrWhiteSpace(endPoint))
- {
- if (!EndPointParser.TryParse(endPoint, defaultPort, out _))
- {
- errors.Add(ErrorSeverity.Error, "Invalid endpoint.");
- }
- }
- }
-
protected override void EditConfigOnSave(Config config)
{
- if (EndPointParser.TryParse(TorSocks5EndPoint, Constants.DefaultTorSocksPort, out EndPoint? torEp))
- {
- config.TorSocks5EndPoint = torEp;
- }
-
config.UseTor = UseTor;
config.TerminateTorOnExit = TerminateTorOnExit;
}

MODIFY
WalletWasabi.Fluent/Views/Settings/NetworkSettingsTabView.axaml
WalletWasabi.Fluent/Views/Settings/NetworkSettingsTabView.axaml
<TextBlock Text="Terminate Tor when Wasabi is Shutdown" />
<ToggleSwitch IsChecked="{Binding TerminateTorOnExit}" />
</DockPanel>
-
- <StackPanel Spacing="10" IsVisible="{Binding UseTor}">
- <TextBlock Text="Tor SOCKS5 Endpoint" />
- <TextBox Text="{Binding TorSocks5EndPoint}" />
- </StackPanel>
</StackPanel>
</UserControl>

MODIFY
WalletWasabi.Gui/Config.cs
WalletWasabi.Gui/Config.cs
@@ -86,10 +86,6 @@ namespace WalletWasabi.Gui
[JsonProperty(PropertyName = "LocalBitcoinCoreDataDir")]
public string LocalBitcoinCoreDataDir { get; internal set; } = EnvironmentHelpers.GetDefaultBitcoinCoreDataDirOrEmptyString();
- [JsonProperty(PropertyName = "TorSocks5EndPoint")]
- [JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultTorSocksPort)]
- public EndPoint TorSocks5EndPoint { get; internal set; } = new IPEndPoint(IPAddress.Loopback, Constants.DefaultTorSocksPort);
-
[JsonProperty(PropertyName = "MainNetBitcoinP2pEndPoint")]
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultMainNetBitcoinP2pPort)]
public EndPoint MainNetBitcoinP2pEndPoint { get; internal set; } = new IPEndPoint(IPAddress.Loopback, Constants.DefaultMainNetBitcoinP2pPort);
@@ -385,17 +381,6 @@ namespace WalletWasabi.Gui
var regTestBitcoinCoreHost = jsObject.Value<string>("RegTestBitcoinCoreHost");
var regTestBitcoinCorePort = jsObject.Value<int?>("RegTestBitcoinCorePort");
- if (torHost is { })
- {
- int port = torSocks5Port ?? Constants.DefaultTorSocksPort;
-
- if (EndPointParser.TryParse(torHost, port, out EndPoint? ep))
- {
- TorSocks5EndPoint = ep;
- saveIt = true;
- }
- }
-
if (mainNetBitcoinCoreHost is { })
{
int port = mainNetBitcoinCorePort ?? Constants.DefaultMainNetBitcoinP2pPort;

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -102,8 +102,8 @@ namespace WalletWasabi.Gui
if (Config.UseTor)
{
- BackendHttpClientFactory = new HttpClientFactory(Config.TorSocks5EndPoint, backendUriGetter: () => Config.GetCurrentBackendUri());
- ExternalHttpClientFactory = new HttpClientFactory(Config.TorSocks5EndPoint, backendUriGetter: null);
+ BackendHttpClientFactory = new HttpClientFactory(TorSettings.SocksEndpoint, backendUriGetter: () => Config.GetCurrentBackendUri());
+ ExternalHttpClientFactory = new HttpClientFactory(TorSettings.SocksEndpoint, backendUriGetter: null);
}
else
{
@@ -148,7 +148,7 @@ namespace WalletWasabi.Gui
{
using (BenchmarkLogger.Measure(operationName: "TorProcessManager.Start"))
{
- TorManager = new TorProcessManager(TorSettings, Config.TorSocks5EndPoint);
+ TorManager = new TorProcessManager(TorSettings);
await TorManager.StartAsync(cancel).ConfigureAwait(false);
}
@@ -172,7 +172,7 @@ namespace WalletWasabi.Gui
throw;
}
- HostedServices.Register<P2pNetwork>(new P2pNetwork(Network, Config.GetBitcoinP2pEndPoint(), Config.UseTor ? Config.TorSocks5EndPoint : null, Path.Combine(DataDir, "BitcoinP2pNetwork"), BitcoinStore), "Bitcoin P2P Network");
+ HostedServices.Register<P2pNetwork>(new P2pNetwork(Network, Config.GetBitcoinP2pEndPoint(), Config.UseTor ? TorSettings.SocksEndpoint : null, Path.Combine(DataDir, "BitcoinP2pNetwork"), BitcoinStore), "Bitcoin P2P Network");
try
{

MODIFY
WalletWasabi.Gui/Tabs/SettingsView.xaml
WalletWasabi.Gui/Tabs/SettingsView.xaml
<ToggleButton IsChecked="{Binding UseTor}" Content="{Binding UseTor, Converter={StaticResource BooleanStringConverter}, ConverterParameter=On:Off}" Margin="0 0 10 0" />
<TextBlock VerticalAlignment="Center">Tor can be turned off for debugging.</TextBlock>
</StackPanel>
- <StackPanel Margin="0 10" Spacing="5" IsVisible="{Binding UseTor}">
- <TextBlock>Tor SOCKS5 Endpoint</TextBlock>
- <TextBox Text="{Binding TorSocks5EndPoint}">
- <i:Interaction.Behaviors>
- <behaviors:CommandOnLostFocusBehavior Command="{Binding TextBoxLostFocusCommand}" />
- </i:Interaction.Behaviors>
- </TextBox>
- </StackPanel>
<StackPanel Margin="0 10" Orientation="Horizontal" Spacing="5" IsVisible="{Binding UseTor}">
<ToggleButton IsChecked="{Binding TerminateTorOnExit}" Content="{Binding TerminateTorOnExit, Converter={StaticResource BooleanStringConverter}, ConverterParameter=On:Off}" Margin="0 0 10 0" />
<TextBlock VerticalAlignment="Center">Terminate Tor process on exit.</TextBlock>

MODIFY
WalletWasabi.Gui/Tabs/SettingsViewModel.cs
WalletWasabi.Gui/Tabs/SettingsViewModel.cs
@@ -25,7 +25,6 @@ namespace WalletWasabi.Gui.Tabs
internal class SettingsViewModel : WasabiDocumentTabViewModel
{
private Network _network;
- private string _torSocks5EndPoint;
private string _bitcoinP2pEndPoint;
private string _localBitcoinCoreDataDir;
private bool _autocopy;
@@ -52,7 +51,6 @@ namespace WalletWasabi.Gui.Tabs
this.ValidateProperty(x => x.FinePrivacyLevel, ValidateFinePrivacyLevel);
this.ValidateProperty(x => x.StrongPrivacyLevel, ValidateStrongPrivacyLevel);
this.ValidateProperty(x => x.DustThreshold, ValidateDustThreshold);
- this.ValidateProperty(x => x.TorSocks5EndPoint, ValidateTorSocks5EndPoint);
this.ValidateProperty(x => x.BitcoinP2pEndPoint, ValidateBitcoinP2pEndPoint);
Autocopy = Global.UiConfig.Autocopy;
@@ -63,7 +61,6 @@ namespace WalletWasabi.Gui.Tabs
config.LoadOrCreateDefaultFile();
_network = config.Network;
- _torSocks5EndPoint = config.TorSocks5EndPoint.ToString(-1);
UseTor = config.UseTor;
TerminateTorOnExit = config.TerminateTorOnExit;
StartLocalBitcoinCoreOnStartup = config.StartLocalBitcoinCoreOnStartup;
@@ -194,12 +191,6 @@ namespace WalletWasabi.Gui.Tabs
set => this.RaiseAndSetIfChanged(ref _network, value);
}
- public string TorSocks5EndPoint
- {
- get => _torSocks5EndPoint;
- set => this.RaiseAndSetIfChanged(ref _torSocks5EndPoint, value);
- }
-
public string BitcoinP2pEndPoint
{
get => _bitcoinP2pEndPoint;
@@ -357,10 +348,6 @@ namespace WalletWasabi.Gui.Tabs
config.LoadFile();
if (Network == config.Network)
{
- if (EndPointParser.TryParse(TorSocks5EndPoint, Constants.DefaultTorSocksPort, out EndPoint? torEp))
- {
- config.TorSocks5EndPoint = torEp;
- }
if (EndPointParser.TryParse(BitcoinP2pEndPoint, network.DefaultPort, out EndPoint? p2pEp))
{
config.SetBitcoinP2pEndpoint(p2pEp);
@@ -405,9 +392,6 @@ namespace WalletWasabi.Gui.Tabs
private void ValidateDustThreshold(IValidationErrors errors)
=> ValidateDustThreshold(errors, DustThreshold, whiteSpaceOk: true);
- private void ValidateTorSocks5EndPoint(IValidationErrors errors)
- => ValidateEndPoint(errors, TorSocks5EndPoint, Constants.DefaultTorSocksPort, whiteSpaceOk: true);
-
private void ValidateBitcoinP2pEndPoint(IValidationErrors errors)
=> ValidateEndPoint(errors, BitcoinP2pEndPoint, Network.DefaultPort, whiteSpaceOk: true);

MODIFY
WalletWasabi.Tests/IntegrationTests/BlockstreamInfoTests.cs
WalletWasabi.Tests/IntegrationTests/BlockstreamInfoTests.cs
@@ -18,7 +18,7 @@ namespace WalletWasabi.Tests.IntegrationTests
ClearnetHttpClientFactory = new(torEndPoint: null, backendUriGetter: null);
TorHttpClientFactory = new(Common.TorSocks5Endpoint, backendUriGetter: null);
- TorManager = new(Common.TorSettings, Common.TorSocks5Endpoint);
+ TorManager = new(Common.TorSettings);
}
private HttpClientFactory ClearnetHttpClientFactory { get; }

MODIFY
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
@@ -28,7 +28,7 @@ namespace WalletWasabi.Tests.IntegrationTests
LiveServerTestsFixture = liveServerTestsFixture;
TorHttpPool = new(new TorTcpConnectionFactory(Common.TorSocks5Endpoint));
- TorManager = new(Common.TorSettings, Common.TorSocks5Endpoint);
+ TorManager = new(Common.TorSettings);
}
private TorProcessManager TorManager { get; }

MODIFY
WalletWasabi.Tests/IntegrationTests/TorTests.cs
WalletWasabi.Tests/IntegrationTests/TorTests.cs
@@ -18,7 +18,7 @@ namespace WalletWasabi.Tests.IntegrationTests
public TorTests()
{
TorHttpPool = new(new TorTcpConnectionFactory(Common.TorSocks5Endpoint));
- TorManager = new(Common.TorSettings, Common.TorSocks5Endpoint);
+ TorManager = new(Common.TorSettings);
}
private TorHttpPool TorHttpPool { get; }

MODIFY
WalletWasabi.Tests/UnitTests/Tor/TorSettingsTests.cs
WalletWasabi.Tests/UnitTests/Tor/TorSettingsTests.cs
@@ -18,9 +18,8 @@ namespace WalletWasabi.Tests.UnitTests.Tor
string distributionFolder = "tempDistributionDir";
TorSettings settings = new(dataDir, logFilePath, distributionFolder, terminateOnExit: true, owningProcessId: 7);
- IPEndPoint endpoint = new(IPAddress.Loopback, WalletWasabi.Helpers.Constants.DefaultTorSocksPort);
- string arguments = settings.GetCmdArguments(endpoint);
+ string arguments = settings.GetCmdArguments();
string expected = string.Join(
" ",

MODIFY
WalletWasabi/Helpers/Constants.cs
WalletWasabi/Helpers/Constants.cs
@@ -36,8 +36,6 @@ namespace WalletWasabi.Helpers
public const int BigFileReadWriteBufferSize = 1 * 1024 * 1024;
- public const int DefaultTorSocksPort = 9050;
-
public const int DefaultMainNetBitcoinP2pPort = 8333;
public const int DefaultTestNetBitcoinP2pPort = 18333;
public const int DefaultRegTestBitcoinP2pPort = 18444;

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -22,16 +22,14 @@ namespace WalletWasabi.Tor
{
private bool _disposed = false;
- public TorProcessManager(TorSettings settings, EndPoint torSocks5EndPoint)
+ public TorProcessManager(TorSettings settings)
{
- TorSocks5EndPoint = torSocks5EndPoint;
TorProcess = null;
TorControlClient = null;
Settings = settings;
- TcpConnectionFactory = new(torSocks5EndPoint);
+ TcpConnectionFactory = new(settings.SocksEndpoint);
}
- private EndPoint TorSocks5EndPoint { get; }
private ProcessAsync? TorProcess { get; set; }
private TorSettings Settings { get; }
private TorTcpConnectionFactory TcpConnectionFactory { get; }
@@ -53,16 +51,12 @@ namespace WalletWasabi.Tor
if (isAlreadyRunning)
{
- string msg = TorSocks5EndPoint is IPEndPoint endpoint
- ? $"Tor is already running on {endpoint.Address}:{endpoint.Port}."
- : "Tor is already running.";
- Logger.LogInfo(msg);
-
+ Logger.LogInfo($"Tor is already running on {Settings.SocksEndpoint.Address}:{Settings.SocksEndpoint.Port}.");
TorControlClient = await InitTorControlAsync(token).ConfigureAwait(false);
return true;
}
- string torArguments = Settings.GetCmdArguments(TorSocks5EndPoint);
+ string torArguments = Settings.GetCmdArguments();
ProcessStartInfo startInfo = new()
{

MODIFY
WalletWasabi/Tor/TorSettings.cs
WalletWasabi/Tor/TorSettings.cs
@@ -57,6 +57,9 @@ namespace WalletWasabi.Tor
/// <summary>Full path to Tor cookie file.</summary>
public string CookieAuthFilePath { get; }
+ /// <summary>Tor control endpoint.</summary>
+ public IPEndPoint SocksEndpoint { get; } = new(IPAddress.Loopback, 37150);
+
/// <summary>Tor control endpoint.</summary>
public IPEndPoint ControlEndpoint { get; } = new(IPAddress.Loopback, 37151);
@@ -72,11 +75,11 @@ namespace WalletWasabi.Tor
return platform == OSPlatform.OSX ? $"{binaryPath}.real" : binaryPath;
}
- public string GetCmdArguments(EndPoint torSocks5EndPoint)
+ public string GetCmdArguments()
{
List<string> arguments = new()
{
- $"--SOCKSPort {torSocks5EndPoint}",
+ $"--SOCKSPort {SocksEndpoint}",
$"--CookieAuthentication 1",
$"--ControlPort {ControlEndpoint.Port}",
$"--CookieAuthFile \"{CookieAuthFilePath}\"",

Use fixed Tor socks to ensure launching our own Tor process