Make Tor lib work with EndPoints instead of IPEndPoints
MODIFY
WalletWasabi.Gui/Config.cs
WalletWasabi.Gui/Config.cs
@@ -188,22 +188,11 @@ namespace WalletWasabi.Gui
return _fallbackBackendUri;
}
- private IPEndPoint _torSocks5EndPoint;
private int? _mixUntilAnonymitySet;
private int? _privacyLevelSome;
private int? _privacyLevelFine;
private int? _privacyLevelStrong;
- public IPEndPoint GetTorSocks5EndPoint()
- {
- if (_torSocks5EndPoint is null)
- {
- _torSocks5EndPoint = TorSocks5EndPoint as IPEndPoint;
- }
-
- return _torSocks5EndPoint;
- }
-
public EndPoint GetBitcoinP2pEndPoint()
{
if (Network == Network.Main)

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -155,7 +155,7 @@ namespace WalletWasabi.Gui
if (Config.UseTor.Value)
{
- Synchronizer = new WasabiSynchronizer(Network, BitcoinStore, () => Config.GetCurrentBackendUri(), Config.GetTorSocks5EndPoint());
+ Synchronizer = new WasabiSynchronizer(Network, BitcoinStore, () => Config.GetCurrentBackendUri(), Config.TorSocks5EndPoint);
}
else
{
@@ -189,7 +189,7 @@ namespace WalletWasabi.Gui
if (Config.UseTor.Value)
{
- TorManager = new TorProcessManager(Config.GetTorSocks5EndPoint(), TorLogsFile);
+ TorManager = new TorProcessManager(Config.TorSocks5EndPoint, TorLogsFile);
}
else
{
@@ -261,7 +261,7 @@ namespace WalletWasabi.Gui
if (Config.UseTor is true)
{
// onlyForOnionHosts: false - Connect to clearnet IPs through Tor, too.
- connectionParameters.TemplateBehaviors.Add(new SocksSettingsBehavior(Config.GetTorSocks5EndPoint(), onlyForOnionHosts: false, networkCredential: null, streamIsolation: true));
+ connectionParameters.TemplateBehaviors.Add(new SocksSettingsBehavior(Config.TorSocks5EndPoint, onlyForOnionHosts: false, networkCredential: null, streamIsolation: true));
// allowOnlyTorEndpoints: true - Connect only to onions and do not connect to clearnet IPs at all.
// This of course makes the first setting unnecessary, but it's better if that's around, in case someone wants to tinker here.
connectionParameters.EndpointConnector = new DefaultEndpointConnector(allowOnlyTorEndpoints: Network == Network.Main);
@@ -410,7 +410,7 @@ namespace WalletWasabi.Gui
if (Config.UseTor.Value)
{
- ChaumianClient = new CcjClient(Synchronizer, Network, keyManager, () => Config.GetCurrentBackendUri(), Config.GetTorSocks5EndPoint());
+ ChaumianClient = new CcjClient(Synchronizer, Network, keyManager, () => Config.GetCurrentBackendUri(), Config.TorSocks5EndPoint);
}
else
{

MODIFY
WalletWasabi.Tests/Global.cs
WalletWasabi.Tests/Global.cs
@@ -12,7 +12,7 @@ namespace WalletWasabi.Tests
{
public static Global Instance { get; } = new Global();
- public IPEndPoint TorSocks5Endpoint { get; }
+ public EndPoint TorSocks5Endpoint { get; }
public string DataDir { get; }

MODIFY
WalletWasabi.Tests/NodeBuilding/CoreNode.cs
WalletWasabi.Tests/NodeBuilding/CoreNode.cs
@@ -19,7 +19,7 @@ namespace WalletWasabi.Tests.NodeBuilding
private NodeBuilder Builder { get; }
public string Folder { get; }
- public IPEndPoint Endpoint => new IPEndPoint(IPAddress.Parse("127.0.0.1"), Ports[0]);
+ public EndPoint Endpoint => new IPEndPoint(IPAddress.Loopback, Ports[0]);
public string Config { get; }

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -34,7 +34,7 @@ namespace WalletWasabi.Services
public Func<Uri> CcjHostUriAction { get; private set; }
public WasabiSynchronizer Synchronizer { get; private set; }
- private IPEndPoint TorSocks5EndPoint { get; set; }
+ private EndPoint TorSocks5EndPoint { get; set; }
private decimal? CoordinatorFeepercentToCheck { get; set; }
@@ -68,7 +68,7 @@ namespace WalletWasabi.Services
Network network,
KeyManager keyManager,
Func<Uri> ccjHostUriAction,
- IPEndPoint torSocks5EndPoint)
+ EndPoint torSocks5EndPoint)
{
Create(synchronizer, network, keyManager, ccjHostUriAction, torSocks5EndPoint);
}
@@ -78,12 +78,12 @@ namespace WalletWasabi.Services
Network network,
KeyManager keyManager,
Uri ccjHostUri,
- IPEndPoint torSocks5EndPoint)
+ EndPoint torSocks5EndPoint)
{
Create(synchronizer, network, keyManager, () => ccjHostUri, torSocks5EndPoint);
}
- private void Create(WasabiSynchronizer synchronizer, Network network, KeyManager keyManager, Func<Uri> ccjHostUriAction, IPEndPoint torSocks5EndPoint)
+ private void Create(WasabiSynchronizer synchronizer, Network network, KeyManager keyManager, Func<Uri> ccjHostUriAction, EndPoint torSocks5EndPoint)
{
Network = Guard.NotNull(nameof(network), network);
KeyManager = Guard.NotNull(nameof(keyManager), keyManager);

MODIFY
WalletWasabi/Services/MempoolService.cs
WalletWasabi/Services/MempoolService.cs
@@ -95,7 +95,7 @@ namespace WalletWasabi.Services
/// <summary>
/// Tries to perform mempool cleanup with the help of the backend.
/// </summary>
- public async Task<bool> TryPerformMempoolCleanupAsync(Func<Uri> destAction, IPEndPoint torSocks)
+ public async Task<bool> TryPerformMempoolCleanupAsync(Func<Uri> destAction, EndPoint torSocks)
{
// If already cleaning, then no need to run it that often.
if (Interlocked.CompareExchange(ref _cleanupInProcess, 1, 0) == 1)

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -801,8 +801,8 @@ namespace WalletWasabi.Services
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);
+ var localEndPoint = ServiceConfiguration.BitcoinCoreEndPoint;
+ var localNode = await Node.ConnectAsync(Network, localEndPoint, nodeConnectionParameters);
try
{
Logger.LogInfo<WalletService>($"TCP Connection succeeded, handshaking...");

MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -134,13 +134,13 @@ namespace WalletWasabi.Services
CreateNew(network, bitcoinStore, client);
}
- public WasabiSynchronizer(Network network, BitcoinStore bitcoinStore, Func<Uri> baseUriAction, IPEndPoint torSocks5EndPoint)
+ public WasabiSynchronizer(Network network, BitcoinStore bitcoinStore, Func<Uri> baseUriAction, EndPoint torSocks5EndPoint)
{
var client = new WasabiClient(baseUriAction, torSocks5EndPoint);
CreateNew(network, bitcoinStore, client);
}
- public WasabiSynchronizer(Network network, BitcoinStore bitcoinStore, Uri baseUri, IPEndPoint torSocks5EndPoint)
+ public WasabiSynchronizer(Network network, BitcoinStore bitcoinStore, Uri baseUri, EndPoint torSocks5EndPoint)
{
var client = new WasabiClient(baseUri, torSocks5EndPoint);
CreateNew(network, bitcoinStore, client);

MODIFY
WalletWasabi/TorSocks5/TorHttpClient.cs
WalletWasabi/TorSocks5/TorHttpClient.cs
@@ -43,7 +43,7 @@ namespace WalletWasabi.TorSocks5
public Uri DestinationUri => DestinationUriAction();
public Func<Uri> DestinationUriAction { get; private set; }
- public IPEndPoint TorSocks5EndPoint { get; private set; }
+ public EndPoint TorSocks5EndPoint { get; private set; }
public bool IsTorUsed => TorSocks5EndPoint != null;
public bool IsolateStream { get; private set; }
@@ -52,18 +52,18 @@ namespace WalletWasabi.TorSocks5
private static AsyncLock AsyncLock { get; } = new AsyncLock(); // We make everything synchronous, so slow, but at least stable.
- public TorHttpClient(Uri baseUri, IPEndPoint torSocks5EndPoint, bool isolateStream = false)
+ public TorHttpClient(Uri baseUri, EndPoint torSocks5EndPoint, bool isolateStream = false)
{
baseUri = Guard.NotNull(nameof(baseUri), baseUri);
Create(torSocks5EndPoint, isolateStream, () => baseUri);
}
- public TorHttpClient(Func<Uri> baseUriAction, IPEndPoint torSocks5EndPoint, bool isolateStream = false)
+ public TorHttpClient(Func<Uri> baseUriAction, EndPoint torSocks5EndPoint, bool isolateStream = false)
{
Create(torSocks5EndPoint, isolateStream, baseUriAction);
}
- private void Create(IPEndPoint torSocks5EndPoint, bool isolateStream, Func<Uri> baseUriAction)
+ private void Create(EndPoint torSocks5EndPoint, bool isolateStream, Func<Uri> baseUriAction)
{
DestinationUriAction = Guard.NotNull(nameof(baseUriAction), baseUriAction);
if (DestinationUri.IsLoopback)

MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -19,7 +19,7 @@ namespace WalletWasabi.TorSocks5
/// <summary>
/// If null then it's just a mock, clearnet is used.
/// </summary>
- public IPEndPoint TorSocks5EndPoint { get; }
+ public EndPoint TorSocks5EndPoint { get; }
public string LogFile { get; }
@@ -29,7 +29,7 @@ namespace WalletWasabi.TorSocks5
/// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
/// <param name="logFile">Opt out of logging with null.</param>
- public TorProcessManager(IPEndPoint torSocks5EndPoint, string logFile)
+ public TorProcessManager(EndPoint torSocks5EndPoint, string logFile)
{
TorSocks5EndPoint = torSocks5EndPoint;
LogFile = logFile;
@@ -193,7 +193,7 @@ namespace WalletWasabi.TorSocks5
}
/// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
- public static async Task<bool> IsTorRunningAsync(IPEndPoint torSocks5EndPoint)
+ public static async Task<bool> IsTorRunningAsync(EndPoint torSocks5EndPoint)
{
using (var client = new TorSocks5Client(torSocks5EndPoint))
{

MODIFY
WalletWasabi/TorSocks5/TorSocks5Client.cs
WalletWasabi/TorSocks5/TorSocks5Client.cs
@@ -24,7 +24,7 @@ namespace WalletWasabi.TorSocks5
public TcpClient TcpClient { get; private set; }
- public IPEndPoint TorSocks5EndPoint { get; private set; }
+ public EndPoint TorSocks5EndPoint { get; private set; }
public Stream Stream { get; internal set; }
@@ -32,7 +32,7 @@ namespace WalletWasabi.TorSocks5
public int DestinationPort { get; private set; }
- private IPEndPoint RemoteEndPoint { get; set; }
+ private EndPoint RemoteEndPoint { get; set; }
public bool IsConnected
{
@@ -56,11 +56,11 @@ namespace WalletWasabi.TorSocks5
#region ConstructorsAndInitializers
- /// <param name="ipEndPoint">Opt out Tor with null.</param>
- internal TorSocks5Client(IPEndPoint ipEndPoint)
+ /// <param name="endPoint">Opt out Tor with null.</param>
+ internal TorSocks5Client(EndPoint endPoint)
{
- TorSocks5EndPoint = ipEndPoint;
- TcpClient = ipEndPoint is null ? new TcpClient() : new TcpClient(ipEndPoint.AddressFamily);
+ TorSocks5EndPoint = endPoint;
+ TcpClient = endPoint is null ? new TcpClient() : new TcpClient(endPoint.AddressFamily);
AsyncLock = new AsyncLock();
}
@@ -72,10 +72,9 @@ namespace WalletWasabi.TorSocks5
AsyncLock = new AsyncLock();
Stream = tcpClient.GetStream();
TorSocks5EndPoint = null;
- var remoteEndPoint = tcpClient.Client.RemoteEndPoint as IPEndPoint;
- DestinationHost = remoteEndPoint.Address.ToString();
- DestinationPort = remoteEndPoint.Port;
- RemoteEndPoint = remoteEndPoint;
+ DestinationHost = tcpClient.Client.RemoteEndPoint.GetHostOrDefault();
+ DestinationPort = tcpClient.Client.RemoteEndPoint.GetPortOrDefault().Value;
+ RemoteEndPoint = tcpClient.Client.RemoteEndPoint;
if (!IsConnected)
{
throw new ConnectionException($"{nameof(TorSocks5Client)} is not connected to {RemoteEndPoint}.");
@@ -91,18 +90,20 @@ namespace WalletWasabi.TorSocks5
using (await AsyncLock.LockAsync())
{
+ string host = TorSocks5EndPoint.GetHostOrDefault();
+ int? port = TorSocks5EndPoint.GetPortOrDefault();
try
{
- await TcpClient.ConnectAsync(TorSocks5EndPoint.Address, TorSocks5EndPoint.Port);
+ await TcpClient.ConnectAsync(host, port.Value);
}
catch (Exception ex) when (IsConnectionRefused(ex))
{
throw new ConnectionException(
- $"Could not connect to Tor SOCKSPort at {TorSocks5EndPoint.Address}:{TorSocks5EndPoint.Port}. Is Tor running?", ex);
+ $"Could not connect to Tor SOCKSPort at {host}:{port}. Is Tor running?", ex);
}
Stream = TcpClient.GetStream();
- RemoteEndPoint = TcpClient.Client.RemoteEndPoint as IPEndPoint;
+ RemoteEndPoint = TcpClient.Client.RemoteEndPoint;
}
}
@@ -195,10 +196,10 @@ namespace WalletWasabi.TorSocks5
}
}
- internal async Task ConnectToDestinationAsync(IPEndPoint destination, bool isRecursiveCall = false)
+ internal async Task ConnectToDestinationAsync(EndPoint destination, bool isRecursiveCall = false)
{
Guard.NotNull(nameof(destination), destination);
- await ConnectToDestinationAsync(destination.Address.ToString(), destination.Port, isRecursiveCall: isRecursiveCall);
+ await ConnectToDestinationAsync(destination.GetHostOrDefault(), destination.GetPortOrDefault().Value, isRecursiveCall: isRecursiveCall);
}
/// <param name="host">IPv4 or domain</param>
@@ -222,7 +223,7 @@ namespace WalletWasabi.TorSocks5
}
await TcpClient.ConnectAsync(host, port);
Stream = TcpClient.GetStream();
- RemoteEndPoint = TcpClient.Client.RemoteEndPoint as IPEndPoint;
+ RemoteEndPoint = TcpClient.Client.RemoteEndPoint;
}
return;

MODIFY
WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/AliceClient.cs
WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/AliceClient.cs
@@ -40,7 +40,7 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
IEnumerable<Requester> requesters,
Network network,
Func<Uri> baseUriAction,
- IPEndPoint torSocks5EndPoint) : base(baseUriAction, torSocks5EndPoint)
+ EndPoint torSocks5EndPoint) : base(baseUriAction, torSocks5EndPoint)
{
RoundId = roundId;
RegisteredAddresses = registeredAddresses.ToArray();
@@ -57,7 +57,7 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
Network network,
InputsRequest request,
Uri baseUri,
- IPEndPoint torSocks5EndPoint)
+ EndPoint torSocks5EndPoint)
{
return await CreateNewAsync(roundId, registeredAddresses, schnorrPubKeys, requesters, network, request, () => baseUri, torSocks5EndPoint);
}
@@ -69,7 +69,7 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
Network network,
InputsRequest request,
Func<Uri> baseUriAction,
- IPEndPoint torSocks5EndPoint)
+ EndPoint torSocks5EndPoint)
{
AliceClient client = new AliceClient(roundId, registeredAddresses, schnorrPubKeys, requesters, network, baseUriAction, torSocks5EndPoint);
try
@@ -123,7 +123,7 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
IEnumerable<uint256> blindedOutputScriptHashes,
IEnumerable<InputProofModel> inputs,
Uri baseUri,
- IPEndPoint torSocks5EndPoint)
+ EndPoint torSocks5EndPoint)
{
return await CreateNewAsync(roundId, registeredAddresses, schnorrPubKeys, requesters, network, changeOutput, blindedOutputScriptHashes, inputs, () => baseUri, torSocks5EndPoint);
}
@@ -137,7 +137,7 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
IEnumerable<uint256> blindedOutputScriptHashes,
IEnumerable<InputProofModel> inputs,
Func<Uri> baseUriAction,
- IPEndPoint torSocks5EndPoint)
+ EndPoint torSocks5EndPoint)
{
var request = new InputsRequest
{

MODIFY
WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/BobClient.cs
WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/BobClient.cs
@@ -14,12 +14,12 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
public class BobClient : TorDisposableBase
{
/// <inheritdoc/>
- public BobClient(Func<Uri> baseUriAction, IPEndPoint torSocks5EndPoint) : base(baseUriAction, torSocks5EndPoint)
+ public BobClient(Func<Uri> baseUriAction, EndPoint torSocks5EndPoint) : base(baseUriAction, torSocks5EndPoint)
{
}
/// <inheritdoc/>
- public BobClient(Uri baseUri, IPEndPoint torSocks5EndPoint) : base(baseUri, torSocks5EndPoint)
+ public BobClient(Uri baseUri, EndPoint torSocks5EndPoint) : base(baseUri, torSocks5EndPoint)
{
}

MODIFY
WalletWasabi/WebClients/Wasabi/WasabiClient.cs
WalletWasabi/WebClients/Wasabi/WasabiClient.cs
@@ -18,12 +18,12 @@ namespace WalletWasabi.WebClients.Wasabi
public class WasabiClient : TorDisposableBase
{
/// <inheritdoc/>
- public WasabiClient(Func<Uri> baseUriAction, IPEndPoint torSocks5EndPoint) : base(baseUriAction, torSocks5EndPoint)
+ public WasabiClient(Func<Uri> baseUriAction, EndPoint torSocks5EndPoint) : base(baseUriAction, torSocks5EndPoint)
{
}
/// <inheritdoc/>
- public WasabiClient(Uri baseUri, IPEndPoint torSocks5EndPoint) : base(baseUri, torSocks5EndPoint)
+ public WasabiClient(Uri baseUri, EndPoint torSocks5EndPoint) : base(baseUri, torSocks5EndPoint)
{
}

Make Tor lib work with EndPoints instead of IPEndPoints