SatoshiClient does not inherit TorDisposable.
MODIFY
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
@@ -52,10 +52,10 @@ namespace WalletWasabi.Tests.IntegrationTests
var filterModel = StartingFilters.GetStartingFilter(network);
- FiltersResponse filtersResponse = await client.GetFiltersAsync(filterModel.Header.BlockHash, 2);
+ FiltersResponse? filtersResponse = await client.GetFiltersAsync(filterModel.Header.BlockHash, 2);
Assert.NotNull(filtersResponse);
- Assert.True(filtersResponse.Filters.Count() == 2);
+ Assert.True(filtersResponse!.Filters.Count() == 2);
}
[Theory]
@@ -63,7 +63,8 @@ namespace WalletWasabi.Tests.IntegrationTests
[InlineData(NetworkType.Testnet)]
public async Task GetAllRoundStatesAsync(NetworkType networkType)
{
- using var client = new SatoshiClient(LiveServerTestsFixture.UriMappings[networkType], Common.TorSocks5Endpoint);
+ using var torHttpClient = MakeTorHttpClient(networkType);
+ var client = new SatoshiClient(torHttpClient);
var states = await client.GetAllRoundStatesAsync();
Assert.True(states.NotNullAndNotEmpty());
Assert.True(states.Count() >= 1);

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -107,7 +107,7 @@ namespace WalletWasabi.Tests.RegressionTests
coordinator.AbortAllRoundsInInputRegistration("");
using var torClient = new TorHttpClient(BaseUri, Tests.Common.TorSocks5Endpoint);
- using var satoshiClient = new SatoshiClient(BaseUri, null);
+ var satoshiClient = new SatoshiClient(new ClearnetHttpClient(() => BaseUri));
#region PostInputsGetStates
@@ -708,7 +708,7 @@ namespace WalletWasabi.Tests.RegressionTests
Uri baseUri = new Uri(RegTestFixture.BackendEndPoint);
using var torClient = new TorHttpClient(baseUri, Tests.Common.TorSocks5Endpoint);
- using var satoshiClient = new SatoshiClient(baseUri, null);
+ var satoshiClient = new SatoshiClient(new ClearnetHttpClient(() => BaseUri));
var round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
var roundId = round.RoundId;

MODIFY
WalletWasabi.Tests/RegressionTests/DosTests.cs
WalletWasabi.Tests/RegressionTests/DosTests.cs
@@ -11,6 +11,7 @@ using WalletWasabi.CoinJoin.Common.Models;
using WalletWasabi.CoinJoin.Coordinator;
using WalletWasabi.CoinJoin.Coordinator.Rounds;
using WalletWasabi.Tests.XunitConfiguration;
+using WalletWasabi.Tor.Http;
using Xunit;
using static WalletWasabi.Crypto.SchnorrBlinding;
using UnblindedSignature = WalletWasabi.Crypto.UnblindedSignature;
@@ -23,15 +24,18 @@ namespace WalletWasabi.Tests.RegressionTests
public DosTests(RegTestFixture regTestFixture)
{
RegTestFixture = regTestFixture;
+
+ var httpClient = new ClearnetHttpClient(() => new Uri(RegTestFixture.BackendEndPoint));
+ SatoshiClient = new SatoshiClient(httpClient);
}
private RegTestFixture RegTestFixture { get; }
+ public SatoshiClient SatoshiClient { get; }
- private static async Task WaitForTimeoutAsync(Uri baseUri)
+ private async Task WaitForTimeoutAsync()
{
- using var satoshiClient = new SatoshiClient(baseUri, null);
var times = 0;
- while (!(await satoshiClient.GetAllRoundStatesAsync()).All(x => x.Phase == RoundPhase.InputRegistration))
+ while (!(await SatoshiClient.GetAllRoundStatesAsync()).All(x => x.Phase == RoundPhase.InputRegistration))
{
await Task.Delay(100);
if (times > 50) // 5 sec, 3 should be enough
@@ -98,6 +102,7 @@ namespace WalletWasabi.Tests.RegressionTests
inputProofModels.Add(inputProof);
GetTxOutResponse getTxOutResponse = await rpc.GetTxOutAsync(input.Hash, (int)input.N, includeMempool: true);
+
// Check if inputs are unspent.
Assert.NotNull(getTxOutResponse);
@@ -139,6 +144,7 @@ namespace WalletWasabi.Tests.RegressionTests
{
Assert.Equal(roundId, aliceClient.RoundId);
}
+
// Because it's valuetuple.
users.Add((user.requester, user.blinded, user.activeOutputAddress, user.changeOutputAddress, user.inputProofModels, user.userInputData, aliceClient, null));
}
@@ -170,10 +176,9 @@ namespace WalletWasabi.Tests.RegressionTests
user.unblindedSignature = resp.Item2.First().Signature;
}
- using (var satoshiClient = new SatoshiClient(baseUri, null))
{
var times = 0;
- while (!(await satoshiClient.GetAllRoundStatesAsync()).All(x => x.Phase == RoundPhase.InputRegistration))
+ while (!(await SatoshiClient.GetAllRoundStatesAsync()).All(x => x.Phase == RoundPhase.InputRegistration))
{
await Task.Delay(100);
if (times > 50) // 5 sec, 3 should be enough
@@ -210,6 +215,7 @@ namespace WalletWasabi.Tests.RegressionTests
{
Assert.Equal(roundId, aliceClient.RoundId);
}
+
// Because it's valuetuple.
users.Add((user.requester, user.blinded, user.activeOutputAddress, user.changeOutputAddress, user.inputProofModels, user.userInputData, aliceClient, null));
}
@@ -223,10 +229,9 @@ namespace WalletWasabi.Tests.RegressionTests
confirmationRequests.Add(user.aliceClient.PostConfirmationAsync());
}
- using (var satoshiClient = new SatoshiClient(baseUri, null))
{
var times = 0;
- while (!(await satoshiClient.GetAllRoundStatesAsync()).All(x => x.Phase == RoundPhase.InputRegistration))
+ while (!(await SatoshiClient.GetAllRoundStatesAsync()).All(x => x.Phase == RoundPhase.InputRegistration))
{
await Task.Delay(100);
if (times > 50) // 5 sec, 3 should be enough
@@ -290,7 +295,7 @@ namespace WalletWasabi.Tests.RegressionTests
aliceClientBackup = await AliceClientBase.CreateNewAsync(round.RoundId, new[] { activeOutputAddress }, new[] { round.MixingLevels.GetBaseLevel().SignerKey.PubKey }, new[] { requester }, network, changeOutputAddress, new[] { blinded }, inputsProofs, () => baseUri, null);
}
- await WaitForTimeoutAsync(baseUri);
+ await WaitForTimeoutAsync();
int bannedCount = coordinator.UtxoReferee.CountBanned(false);
Assert.Equal(0, bannedCount);
@@ -304,7 +309,7 @@ namespace WalletWasabi.Tests.RegressionTests
await AliceClientBase.CreateNewAsync(round.RoundId, aliceClientBackup.RegisteredAddresses, round.MixingLevels.GetAllLevels().Select(x => x.SignerKey.PubKey), aliceClientBackup.Requesters, network, registerRequest.changeOutputAddress, new[] { registerRequest.blindedData }, registerRequest.inputsProofs, () => baseUri, null);
}
- await WaitForTimeoutAsync(baseUri);
+ await WaitForTimeoutAsync();
bannedCount = coordinator.UtxoReferee.CountBanned(false);
Assert.Equal(anonymitySet, bannedCount);

MODIFY
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
@@ -23,7 +23,7 @@ using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Models;
using WalletWasabi.Services;
-using WalletWasabi.WebClients.Wasabi;
+using WalletWasabi.Tor.Http;
using static WalletWasabi.Crypto.SchnorrBlinding;
namespace WalletWasabi.CoinJoin.Client.Clients
@@ -1073,10 +1073,10 @@ namespace WalletWasabi.CoinJoin.Client.Clients
private async Task<AliceClientBase> CreateAliceClientAsync(long roundId, List<OutPoint> registrableCoins, (HdPubKey change, IEnumerable<HdPubKey> actives) outputAddresses)
{
RoundStateResponse4 state;
- WasabiClientFactory factory = Synchronizer.WasabiClientFactory;
- using (var satoshiClient = new SatoshiClient(factory.BackendUriGetter, factory.TorEndpoint))
+ using (TorHttpClient torHttpClient = Synchronizer.WasabiClientFactory.NewBackendTorHttpClient(isolateStream: true))
{
+ var satoshiClient = new SatoshiClient(torHttpClient);
state = (RoundStateResponse4)await satoshiClient.GetRoundStateAsync(roundId).ConfigureAwait(false);
}

MODIFY
WalletWasabi/CoinJoin/Client/Clients/SatoshiClient.cs
WalletWasabi/CoinJoin/Client/Clients/SatoshiClient.cs
-using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using WalletWasabi.CoinJoin.Common.Models;
-using WalletWasabi.Tor.Http.Bases;
+using WalletWasabi.Tor.Http;
using WalletWasabi.Tor.Http.Extensions;
using WalletWasabi.WebClients.Wasabi;
namespace WalletWasabi.CoinJoin.Client.Clients
{
- public class SatoshiClient : TorDisposableBase
+ public class SatoshiClient
{
- /// <inheritdoc/>
- public SatoshiClient(Func<Uri> baseUriAction, EndPoint? torSocks5EndPoint) : base(baseUriAction, torSocks5EndPoint)
+ public SatoshiClient(IRelativeHttpClient httpClient)
{
+ HttpClient = httpClient;
}
- /// <inheritdoc/>
- public SatoshiClient(Uri baseUri, EndPoint torSocks5EndPoint) : base(baseUri, torSocks5EndPoint)
- {
- }
+ private IRelativeHttpClient HttpClient { get; }
public async Task<IEnumerable<RoundStateResponseBase>> GetAllRoundStatesAsync()
{
- using var response = await TorClient.SendAsync(HttpMethod.Get, $"/api/v{WasabiClient.ApiVersion}/btc/chaumiancoinjoin/states/").ConfigureAwait(false);
+ using var response = await HttpClient.SendAsync(HttpMethod.Get, $"/api/v{WasabiClient.ApiVersion}/btc/chaumiancoinjoin/states/").ConfigureAwait(false);
if (response.StatusCode != HttpStatusCode.OK)
{
await response.ThrowRequestExceptionFromContentAsync().ConfigureAwait(false);

MODIFY
WalletWasabi/WebClients/Wasabi/WasabiClientFactory.cs
WalletWasabi/WebClients/Wasabi/WasabiClientFactory.cs
@@ -41,5 +41,13 @@ namespace WalletWasabi.WebClients.Wasabi
TorHttpClient torHttpClient = new TorHttpClient(BackendUriGetter.Invoke(), TorEndpoint, isolateStream: isolateStream);
return new WasabiClient(torHttpClient);
}
+
+ /// <summary>
+ /// Creates new <see cref="TorHttpClient"/>.
+ /// </summary>
+ public TorHttpClient NewBackendTorHttpClient(bool isolateStream)
+ {
+ return new TorHttpClient(BackendUriGetter, TorEndpoint, isolateStream);
+ }
}
}

SatoshiClient does not inherit TorDisposable.