Make identity names more descriptive.
MODIFY
WalletWasabi.Tests/UnitTests/Tor/Socks5/TorHttpPoolTests.cs
WalletWasabi.Tests/UnitTests/Tor/Socks5/TorHttpPoolTests.cs
@@ -32,8 +32,8 @@ namespace WalletWasabi.Tests.UnitTests.Tor.Socks5
using CancellationTokenSource timeoutCts = new(TimeSpan.FromMinutes(1));
IIdentity defaultIdentity = DefaultIdentity.Instance;
- IIdentity aliceIdentity = new RandomIdentity(canTorCircuitBeReused: true); // Random but a non-changing identity.
- IIdentity bobIdentity = new RandomIdentity(canTorCircuitBeReused: true); // Random but a non-changing identity.
+ IIdentity aliceIdentity = new PersonIdentity(); // Random but a non-changing identity.
+ IIdentity bobIdentity = new PersonIdentity(); // Random but a non-changing identity.
using TorTcpConnection aliceConnection = new(null!, new MemoryStream(), aliceIdentity, true);
using TorTcpConnection bobConnection = new(null!, new MemoryStream(), bobIdentity, true);

MODIFY
WalletWasabi/Tor/Http/TorHttpClient.cs
WalletWasabi/Tor/Http/TorHttpClient.cs
@@ -26,7 +26,7 @@ namespace WalletWasabi.Tor.Http
PredefinedIdentity = mode switch
{
Mode.DefaultIdentity => DefaultIdentity.Instance,
- Mode.SingleIdentityPerLifetime => new RandomIdentity(canTorCircuitBeReused: true),
+ Mode.SingleIdentityPerLifetime => new PersonIdentity(),
Mode.NewIdentityPerRequest => null,
_ => throw new NotSupportedException(),
};
@@ -69,7 +69,7 @@ namespace WalletWasabi.Tor.Http
{
Mode.DefaultIdentity => PredefinedIdentity!,
Mode.SingleIdentityPerLifetime => PredefinedIdentity!,
- Mode.NewIdentityPerRequest => new RandomIdentity(canTorCircuitBeReused: false),
+ Mode.NewIdentityPerRequest => new OneOffIdentity(),
_ => throw new NotSupportedException()
};

MODIFY
WalletWasabi/Tor/Socks5/Pool/Identities/Identity.cs
WalletWasabi/Tor/Socks5/Pool/Identities/Identity.cs
@@ -3,7 +3,5 @@ namespace WalletWasabi.Tor.Socks5.Pool.Identities
public interface IIdentity
{
string Name { get; }
-
- bool CanTorCircuitBeReused { get; }
}
}

ADD
WalletWasabi/Tor/Socks5/Pool/Identities/OneOffIdentity.cs
+using WalletWasabi.Crypto.Randomness;
+
+namespace WalletWasabi.Tor.Socks5.Pool.Identities
+{
+ /// <summary>Random idendity for an HTTP requests which should not be linked with any other HTTP request.</summary>
+ public class OneOffIdentity : IIdentity
+ {
+ public OneOffIdentity()
+ {
+ Name = RandomString.CapitalAlphaNumeric(21);
+ }
+ public string Name { get; }
+
+ /// <inheritdoc/>
+ public override string ToString()
+ {
+ return $"[{nameof(OneOffIdentity)}: {Name}]";
+ }
+ }
+}

ADD
WalletWasabi/Tor/Socks5/Pool/Identities/PersonIdentity.cs
+using WalletWasabi.Crypto.Randomness;
+
+namespace WalletWasabi.Tor.Socks5.Pool.Identities
+{
+ /// <summary>
+ /// Identity for a set of HTTP requests where we don't mind that
+ /// HTTP requests can be identified as belonging to a single user.
+ /// </summary>
+ /// <remarks>Useful for Alices and Bobs.</remarks>
+ public class PersonIdentity : IIdentity
+ {
+ public PersonIdentity()
+ {
+ Name = RandomString.CapitalAlphaNumeric(21);
+ }
+ public string Name { get; }
+
+ /// <inheritdoc/>
+ public override string ToString()
+ {
+ return $"[{nameof(PersonIdentity)}: {Name}]";
+ }
+ }
+}

MODIFY
WalletWasabi/Tor/Socks5/TorTcpConnectionFactory.cs
WalletWasabi/Tor/Socks5/TorTcpConnectionFactory.cs
@@ -82,7 +82,8 @@ namespace WalletWasabi.Tor.Socks5
transportStream = await UpgradeToSslAsync(tcpClient, host).ConfigureAwait(false);
}
- TorTcpConnection result = new(tcpClient, transportStream, identity, allowRecycling: !useSsl && identity.CanTorCircuitBeReused);
+ bool allowRecycling = !useSsl && (identity is DefaultIdentity or PersonIdentity);
+ TorTcpConnection result = new(tcpClient, transportStream, identity, allowRecycling);
transportStream = null;
tcpClient = null;

Make identity names more descriptive.