Moved common tor disposable logic to base class
MODIFY
WalletWasabi/WebClients/ChaumianCoinJoin/AliceClient.cs
WalletWasabi/WebClients/ChaumianCoinJoin/AliceClient.cs
@@ -13,21 +13,19 @@ using WalletWasabi.Backend.Models.Responses;
using WalletWasabi.Logging;
using WalletWasabi.Models.ChaumianCoinJoin;
using WalletWasabi.TorSocks5;
+using WalletWasabi.Bases;
namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
- public class AliceClient : IDisposable
+ public class AliceClient : TorDisposableBase
{
- public TorHttpClient TorClient { get; }
public long RoundId { get; private set; }
public Guid UniqueId { get; private set; }
public byte[] BlindedOutputSignature { get; private set; }
-
- /// <param name="torSocks5EndPoint">if null, then localhost:9050</param>
- private AliceClient(Uri baseUri, IPEndPoint torSocks5EndPoint = null)
+ /// <inheritdoc/>
+ private AliceClient(Uri baseUri, IPEndPoint torSocks5EndPoint = null) : base(baseUri, torSocks5EndPoint)
{
- TorClient = new TorHttpClient(baseUri, torSocks5EndPoint, isolateStream: true);
}
public static async Task<AliceClient> CreateNewAsync(InputsRequest request, Uri baseUri, IPEndPoint torSocks5EndPoint = null)
@@ -147,37 +145,5 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
Logger.LogInfo<AliceClient>($"Round ({RoundId}), Alice ({UniqueId}): Posted {signatures.Count} signatures.");
}
}
-
- #region IDisposable Support
-
- private volatile bool _disposedValue = false; // To detect redundant calls
-
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- if (disposing)
- {
- TorClient?.Dispose();
- }
-
- _disposedValue = true;
- }
- }
-
- // ~AliceClient() {
- // // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- // Dispose(false);
- // }
-
- // This code added to correctly implement the disposable pattern.
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- // GC.SuppressFinalize(this);
- }
-
- #endregion IDisposable Support
}
}

MODIFY
WalletWasabi/WebClients/ChaumianCoinJoin/BobClient.cs
WalletWasabi/WebClients/ChaumianCoinJoin/BobClient.cs
@@ -10,17 +10,15 @@ using WalletWasabi.Backend.Models.Requests;
using WalletWasabi.Backend.Models.Responses;
using WalletWasabi.Models.ChaumianCoinJoin;
using WalletWasabi.TorSocks5;
+using WalletWasabi.Bases;
namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
- public class BobClient : IDisposable
+ public class BobClient : TorDisposableBase
{
- public TorHttpClient TorClient { get; }
-
- /// <param name="torSocks5EndPoint">if null, then localhost:9050</param>
- public BobClient(Uri baseUri, IPEndPoint torSocks5EndPoint = null)
+ /// <inheritdoc/>
+ public BobClient(Uri baseUri, IPEndPoint torSocks5EndPoint = null) : base(baseUri, torSocks5EndPoint)
{
- TorClient = new TorHttpClient(baseUri, torSocks5EndPoint, isolateStream: true);
}
public async Task PostOutputAsync(string roundHash, BitcoinAddress activeOutputAddress, byte[] unblindedSignature)
@@ -36,37 +34,5 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
}
}
}
-
- #region IDisposable Support
-
- private volatile bool _disposedValue = false; // To detect redundant calls
-
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- if (disposing)
- {
- TorClient?.Dispose();
- }
-
- _disposedValue = true;
- }
- }
-
- // ~BobClient() {
- // // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- // Dispose(false);
- // }
-
- // This code added to correctly implement the disposable pattern.
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- // GC.SuppressFinalize(this);
- }
-
- #endregion IDisposable Support
}
}

MODIFY
WalletWasabi/WebClients/ChaumianCoinJoin/SatoshiClient.cs
WalletWasabi/WebClients/ChaumianCoinJoin/SatoshiClient.cs
@@ -6,19 +6,18 @@ using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using WalletWasabi.Backend.Models.Responses;
+using WalletWasabi.Bases;
using WalletWasabi.Models.ChaumianCoinJoin;
using WalletWasabi.TorSocks5;
namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
- public class SatoshiClient : IDisposable
+ public class SatoshiClient : TorDisposableBase
{
- public TorHttpClient TorClient { get; }
-
- /// <param name="torSocks5EndPoint">if null, then localhost:9050</param>
- public SatoshiClient(Uri baseUri, IPEndPoint torSocks5EndPoint = null)
+ /// <inheritdoc/>
+ public SatoshiClient(Uri baseUri, IPEndPoint torSocks5EndPoint = null) : base(baseUri, torSocks5EndPoint)
{
- TorClient = new TorHttpClient(baseUri, torSocks5EndPoint, isolateStream: true);
+
}
public async Task<IEnumerable<CcjRunningRoundState>> GetAllRoundStatesAsync()
@@ -49,37 +48,5 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
IEnumerable<CcjRunningRoundState> states = await GetAllRoundStatesAsync();
return states.First(x => x.Phase == CcjRoundPhase.InputRegistration);
}
-
- #region IDisposable Support
-
- private volatile bool _disposedValue = false; // To detect redundant calls
-
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- if (disposing)
- {
- TorClient?.Dispose();
- }
-
- _disposedValue = true;
- }
- }
-
- // ~SatoshiClient() {
- // // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- // Dispose(false);
- // }
-
- // This code added to correctly implement the disposable pattern.
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- // GC.SuppressFinalize(this);
- }
-
- #endregion IDisposable Support
}
}

Moved common tor disposable logic to base class