Enable connecting local node to external onion endpoint.
MODIFY
WalletWasabi.Backend/Config.cs
WalletWasabi.Backend/Config.cs
@@ -43,31 +43,42 @@ namespace WalletWasabi.Backend
[JsonProperty(PropertyName = "RegTestBitcoinCorePort")]
public int? RegTestBitcoinCorePort { get; internal set; }
- private IPEndPoint _bitcoinCoreEndPoint;
+ private EndPoint _bitcoinCoreEndPoint;
- public IPEndPoint GetBitcoinCoreEndPoint()
+ public EndPoint GetBitcoinCoreEndPoint()
{
if (_bitcoinCoreEndPoint is null)
{
- IPAddress host;
- int? port;
+ IPAddress ipHost;
+ string dnsHost = null;
+ int? port = null;
+ try
+ {
if (Network == Network.Main)
{
- host = IPAddress.Parse(MainNetBitcoinCoreHost);
port = MainNetBitcoinCorePort;
+ dnsHost = MainNetBitcoinCoreHost;
+ ipHost = IPAddress.Parse(MainNetBitcoinCoreHost);
}
else if (Network == Network.TestNet)
{
- host = IPAddress.Parse(TestNetBitcoinCoreHost);
port = TestNetBitcoinCorePort;
+ dnsHost = TestNetBitcoinCoreHost;
+ ipHost = IPAddress.Parse(TestNetBitcoinCoreHost);
}
else // if (Network == Network.RegTest)
{
- host = IPAddress.Parse(RegTestBitcoinCoreHost);
port = RegTestBitcoinCorePort;
+ dnsHost = RegTestBitcoinCoreHost;
+ ipHost = IPAddress.Parse(RegTestBitcoinCoreHost);
}
- _bitcoinCoreEndPoint = new IPEndPoint(host, port ?? Network.DefaultPort);
+ _bitcoinCoreEndPoint = new IPEndPoint(ipHost, port ?? Network.DefaultPort);
+ }
+ catch
+ {
+ _bitcoinCoreEndPoint = new DnsEndPoint(dnsHost, port ?? Network.DefaultPort);
+ }
}
return _bitcoinCoreEndPoint;
@@ -83,7 +94,7 @@ namespace WalletWasabi.Backend
}
public Config(Network network,
- string BitcoinRpcConnectionString,
+ string bitcoinRpcConnectionString,
string mainNetBitcoinCoreHost,
string testNetBitcoinCoreHost,
string regTestBitcoinCoreHost,
@@ -92,7 +103,7 @@ namespace WalletWasabi.Backend
int? regTestBitcoinCorePort)
{
Network = Guard.NotNull(nameof(network), network);
- BitcoinRpcConnectionString = Guard.NotNullOrEmptyOrWhitespace(nameof(BitcoinRpcConnectionString), BitcoinRpcConnectionString);
+ BitcoinRpcConnectionString = Guard.NotNullOrEmptyOrWhitespace(nameof(bitcoinRpcConnectionString), bitcoinRpcConnectionString);
MainNetBitcoinCoreHost = Guard.NotNullOrEmptyOrWhitespace(nameof(mainNetBitcoinCoreHost), mainNetBitcoinCoreHost);
TestNetBitcoinCoreHost = Guard.NotNullOrEmptyOrWhitespace(nameof(testNetBitcoinCoreHost), testNetBitcoinCoreHost);

MODIFY
WalletWasabi.Backend/Global.cs
WalletWasabi.Backend/Global.cs
@@ -122,10 +122,10 @@ namespace WalletWasabi.Backend
}
}
- private static async Task InitializeP2pAsync(Network network, IPEndPoint iPEndPoint)
+ private static async Task InitializeP2pAsync(Network network, EndPoint endPoint)
{
Guard.NotNull(nameof(network), network);
- Guard.NotNull(nameof(iPEndPoint), iPEndPoint);
+ Guard.NotNull(nameof(endPoint), endPoint);
using (var handshakeTimeout = new CancellationTokenSource())
{
@@ -137,7 +137,7 @@ namespace WalletWasabi.Backend
};
nodeConnectionParameters.TemplateBehaviors.Add(new TrustedNodeNotifyingBehavior());
- var node = await Node.ConnectAsync(network, iPEndPoint, nodeConnectionParameters);
+ var node = await Node.ConnectAsync(network, endPoint, nodeConnectionParameters);
// We have to find it, because it's cloned by the node and not perfectly cloned (event handlers cannot be cloned.)
TrustedNodeNotifyingBehavior = node.Behaviors.Find<TrustedNodeNotifyingBehavior>();
try

MODIFY
WalletWasabi.Gui/Config.cs
WalletWasabi.Gui/Config.cs
@@ -197,7 +197,7 @@ namespace WalletWasabi.Gui
private int? _privacyLevelSome;
private int? _privacyLevelFine;
private int? _privacyLevelStrong;
- private IPEndPoint _bitcoinCoreEndPoint;
+ private EndPoint _bitcoinCoreEndPoint;
public IPEndPoint GetTorSocks5EndPoint()
{
@@ -210,29 +210,40 @@ namespace WalletWasabi.Gui
return _torSocks5EndPoint;
}
- public IPEndPoint GetBitcoinCoreEndPoint()
+ public EndPoint GetBitcoinCoreEndPoint()
{
if (_bitcoinCoreEndPoint is null)
{
- IPAddress host;
- int? port;
+ IPAddress ipHost;
+ string dnsHost = null;
+ int? port = null;
+ try
+ {
if (Network == Network.Main)
{
- host = IPAddress.Parse(MainNetBitcoinCoreHost);
port = MainNetBitcoinCorePort;
+ dnsHost = MainNetBitcoinCoreHost;
+ ipHost = IPAddress.Parse(MainNetBitcoinCoreHost);
}
else if (Network == Network.TestNet)
{
- host = IPAddress.Parse(TestNetBitcoinCoreHost);
port = TestNetBitcoinCorePort;
+ dnsHost = TestNetBitcoinCoreHost;
+ ipHost = IPAddress.Parse(TestNetBitcoinCoreHost);
}
else // if (Network == Network.RegTest)
{
- host = IPAddress.Parse(RegTestBitcoinCoreHost);
port = RegTestBitcoinCorePort;
+ dnsHost = RegTestBitcoinCoreHost;
+ ipHost = IPAddress.Parse(RegTestBitcoinCoreHost);
}
- _bitcoinCoreEndPoint = new IPEndPoint(host, port ?? Network.DefaultPort);
+ _bitcoinCoreEndPoint = new IPEndPoint(ipHost, port ?? Network.DefaultPort);
+ }
+ catch
+ {
+ _bitcoinCoreEndPoint = new DnsEndPoint(dnsHost, port ?? Network.DefaultPort);
+ }
}
return _bitcoinCoreEndPoint;

MODIFY
WalletWasabi/Models/ServiceConfiguration.cs
WalletWasabi/Models/ServiceConfiguration.cs
@@ -12,14 +12,14 @@ namespace WalletWasabi.Models
public int PrivacyLevelSome { get; set; }
public int PrivacyLevelFine { get; set; }
public int PrivacyLevelStrong { get; set; }
- public IPEndPoint BitcoinCoreEndPoint { get; set; }
+ public EndPoint BitcoinCoreEndPoint { get; set; }
public ServiceConfiguration(
int mixUntilAnonymitySet,
int privacyLevelSome,
int privacyLevelFine,
int privacyLevelStrong,
- IPEndPoint bitcoinCoreEndPoint)
+ EndPoint bitcoinCoreEndPoint)
{
MixUntilAnonymitySet = Guard.NotNull(nameof(mixUntilAnonymitySet), mixUntilAnonymitySet);
PrivacyLevelSome = Guard.NotNull(nameof(privacyLevelSome), privacyLevelSome);

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -23,6 +23,7 @@ using System.Net.Http;
using System.Diagnostics;
using NBitcoin.BitcoinCore;
using System.Net.Sockets;
+using NBitcoin.Protocol.Behaviors;
namespace WalletWasabi.Services
{
@@ -733,6 +734,13 @@ namespace WalletWasabi.Services
IsRelay = false
};
+ // If an onion was added must try to use Tor.
+ // onlyForOnionHosts should connect to it if it's an onion endpoint automatically and non-Tor endpoints through clearnet/localhost
+ if (Synchronizer.WasabiClient.TorClient.IsTorUsed)
+ {
+ nodeConnectionParameters.TemplateBehaviors.Add(new SocksSettingsBehavior(Synchronizer.WasabiClient.TorClient.TorSocks5EndPoint, onlyForOnionHosts: true, networkCredential: null, streamIsolation: false));
+ }
+
var localIpEndPoint = ServiceConfiguration.BitcoinCoreEndPoint;
var localNode = await Node.ConnectAsync(Network, localIpEndPoint, nodeConnectionParameters);
try

MODIFY
WalletWasabi/TorSocks5/TorHttpClient.cs
WalletWasabi/TorSocks5/TorHttpClient.cs
@@ -43,6 +43,7 @@ namespace WalletWasabi.TorSocks5
public Uri DestinationUri => DestinationUriAction();
public Func<Uri> DestinationUriAction { get; private set; }
public IPEndPoint TorSocks5EndPoint { get; private set; }
+ public bool IsTorUsed => TorSocks5EndPoint != null;
public bool IsolateStream { get; private set; }

Enable connecting local node to external onion endpoint.