TorHttpPool: Improve logging.
MODIFY
WalletWasabi/Tor/Socks5/Pool/TorHttpPool.cs
WalletWasabi/Tor/Socks5/Pool/TorHttpPool.cs
@@ -331,6 +331,7 @@ namespace WalletWasabi.Tor.Socks5.Pool
// Find TCP connections to dispose.
foreach (TorTcpConnection tcpConnection in hostConnections.FindAll(c => c.NeedDisposal).ToList())
{
+ Logger.LogDebug($"['{tcpConnection}'] Is to be disposed.");
hostConnections.Remove(tcpConnection);
tcpConnection.Dispose();
}
@@ -340,6 +341,11 @@ namespace WalletWasabi.Tor.Socks5.Pool
bool canBeAdded = hostConnections.Count < MaxConnectionsPerHost;
+ if (!canBeAdded)
+ {
+ Logger.LogTrace($"Beware! Too many active connections: '{string.Join(", ", hostConnections.Select(c => c.ToString()))}'.");
+ }
+
return canBeAdded;
}

MODIFY
WalletWasabi/Tor/Socks5/TorTcpConnection.cs
WalletWasabi/Tor/Socks5/TorTcpConnection.cs
@@ -24,11 +24,13 @@ namespace WalletWasabi.Tor.Socks5
/// <param name="allowRecycling">Whether it is allowed to re-use this Tor TCP connection.</param>
public TorTcpConnection(TcpClient tcpClient, Stream transportStream, ICircuit circuit, bool allowRecycling)
{
+ long id = Interlocked.Increment(ref LastId);
+ Name = $"TC#{id:0000}#{circuit.Name[0..10]}";
+
TcpClient = tcpClient;
TransportStream = transportStream;
Circuit = circuit;
AllowRecycling = allowRecycling;
- Id = Interlocked.Increment(ref LastId);
}
/// <remarks>Lock object to guard <see cref="State"/> property.</remarks>
@@ -53,8 +55,8 @@ namespace WalletWasabi.Tor.Socks5
}
}
- /// <summary>Unique identifier of the pool item for logging purposes.</summary>
- private long Id { get; }
+ /// <summary>Unique identifier of the TCP connection for logging purposes.</summary>
+ private string Name { get; }
/// <summary>TCP connection to Tor's SOCKS5 server.</summary>
private TcpClient TcpClient { get; }
@@ -115,7 +117,7 @@ namespace WalletWasabi.Tor.Socks5
/// <inheritdoc/>
public override string ToString()
{
- return $"PoolConnection#{Id}";
+ return Name;
}
protected virtual void Dispose(bool disposing)

TorHttpPool: Improve logging.