Wrap TorSocks5Stream.
MODIFY
WalletWasabi/Tor/Http/TorHttpClient.cs
WalletWasabi/Tor/Http/TorHttpClient.cs
using Nito.AsyncEx;
using System;
+using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
@@ -167,9 +168,7 @@ namespace WalletWasabi.Tor.Http
LatestTorException = ex;
}
- /// <remarks>
- /// Throws <see cref="OperationCanceledException"/> if <paramref name="cancel"/> is set.
- /// </remarks>
+ /// <exception cref="OperationCanceledException">If <paramref name="cancel"/> is set.</exception>
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancel = default)
{
Guard.NotNull(nameof(request), request);
@@ -240,10 +239,12 @@ namespace WalletWasabi.Tor.Http
var bytes = Encoding.UTF8.GetBytes(requestString);
- await TorSocks5Client.Stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
- await TorSocks5Client.Stream.FlushAsync().ConfigureAwait(false);
+ Stream transportStream = TorSocks5Client.GetTransportStream();
+
+ await transportStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
+ await transportStream.FlushAsync().ConfigureAwait(false);
- return await HttpResponseMessageExtensions.CreateNewAsync(TorSocks5Client.Stream, request.Method).ConfigureAwait(false);
+ return await HttpResponseMessageExtensions.CreateNewAsync(transportStream, request.Method).ConfigureAwait(false);
}
#region IDisposable Support

MODIFY
WalletWasabi/Tor/Socks5/TorSocks5Client.cs
WalletWasabi/Tor/Socks5/TorSocks5Client.cs
@@ -42,7 +42,7 @@ namespace WalletWasabi.Tor.Socks5
/// <summary>Transport stream for sending HTTP/HTTPS requests through Tor's SOCKS5 server.</summary>
/// <remarks>This stream is not to be used to send commands to Tor's SOCKS5 server.</remarks>
- public Stream Stream { get; internal set; }
+ private Stream Stream { get; set; }
private EndPoint RemoteEndPoint { get; set; }
@@ -187,6 +187,15 @@ namespace WalletWasabi.Tor.Socks5
Stream = sslStream;
}
+ /// <summary>
+ /// Stream to transport HTTP(S) request.
+ /// </summary>
+ /// <remarks>Either <see cref="TcpClient.GetStream"/> or <see cref="SslStream"/> over <see cref="TcpClient.GetStream"/>.</remarks>
+ public Stream GetTransportStream()
+ {
+ return Stream;
+ }
+
private async Task ConnectToDestinationAsync(EndPoint destination, CancellationToken cancellationToken = default)
{
if (!destination.TryGetHostAndPort(out string? host, out int? port))

Wrap TorSocks5Stream.