ConfigureAwait in Tor library.
MODIFY
WalletWasabi/Http/Models/HeaderField.cs
WalletWasabi/Http/Models/HeaderField.cs
@@ -72,7 +72,7 @@ namespace WalletWasabi.Http.Models
throw new FormatException($"Wrong {nameof(HeaderField)}: {fieldString}.");
}
- var value = await reader.ReadToEndAsync();
+ var value = await reader.ReadToEndAsync().ConfigureAwait(false);
value = Guard.Correct(value);
return new HeaderField(name, value);

MODIFY
WalletWasabi/Http/Models/HeaderSection.cs
WalletWasabi/Http/Models/HeaderSection.cs
@@ -52,7 +52,7 @@ namespace WalletWasabi.Http.Models
{
break;
}
- hs.Fields.Add(await HeaderField.CreateNewAsync(field));
+ hs.Fields.Add(await HeaderField.CreateNewAsync(field).ConfigureAwait(false));
}
ValidateAndCorrectHeaders(hs);

MODIFY
WalletWasabi/Http/Models/RequestLine.cs
WalletWasabi/Http/Models/RequestLine.cs
@@ -33,7 +33,7 @@ namespace WalletWasabi.Http.Models
{
try
{
- var parts = (await GetPartsAsync(requestLineString)).ToArray();
+ var parts = (await GetPartsAsync(requestLineString).ConfigureAwait(false)).ToArray();
var methodString = parts[0];
var uri = new Uri(parts[1]);
var protocolString = parts[2];

MODIFY
WalletWasabi/Http/Models/StartLine.cs
WalletWasabi/Http/Models/StartLine.cs
@@ -45,7 +45,7 @@ namespace WalletWasabi.Http.Models
if (parts.Count == 2)
{
- var rest = await reader.ReadToEndAsync();
+ var rest = await reader.ReadToEndAsync().ConfigureAwait(false);
// startLineString must end here, the ReadToEnd returns "" if nothing to read instead of null
if (rest != "")

MODIFY
WalletWasabi/Http/Models/StatusLine.cs
WalletWasabi/Http/Models/StatusLine.cs
@@ -23,7 +23,7 @@ namespace WalletWasabi.Http.Models
{
try
{
- var parts = (await GetPartsAsync(statusLineString)).ToArray();
+ var parts = (await GetPartsAsync(statusLineString).ConfigureAwait(false)).ToArray();
var protocolString = parts[0];
var codeString = parts[1];
var reason = parts[2];

MODIFY
WalletWasabi/TorSocks5/TorHttpClient.cs
WalletWasabi/TorSocks5/TorHttpClient.cs
@@ -88,11 +88,11 @@ namespace WalletWasabi.TorSocks5
try
{
- using (await AsyncLock.LockAsync(cancel))
+ using (await AsyncLock.LockAsync(cancel).ConfigureAwait(false))
{
try
{
- HttpResponseMessage ret = await SendAsync(request);
+ HttpResponseMessage ret = await SendAsync(request).ConfigureAwait(false);
TorDoesntWorkSince = null;
return ret;
}
@@ -106,7 +106,7 @@ namespace WalletWasabi.TorSocks5
cancel.ThrowIfCancellationRequested();
try
{
- HttpResponseMessage ret2 = await SendAsync(request);
+ HttpResponseMessage ret2 = await SendAsync(request).ConfigureAwait(false);
TorDoesntWorkSince = null;
return ret2;
}
@@ -120,7 +120,7 @@ namespace WalletWasabi.TorSocks5
try
{
- await Task.Delay(1000, cancel);
+ await Task.Delay(1000, cancel).ConfigureAwait(false);
}
catch (TaskCanceledException tce)
{
@@ -134,7 +134,7 @@ namespace WalletWasabi.TorSocks5
cancel.ThrowIfCancellationRequested();
- HttpResponseMessage ret3 = await SendAsync(request);
+ HttpResponseMessage ret3 = await SendAsync(request).ConfigureAwait(false);
TorDoesntWorkSince = null;
return ret3;
}
@@ -187,9 +187,9 @@ namespace WalletWasabi.TorSocks5
if (TorSocks5Client is null || !TorSocks5Client.IsConnected)
{
TorSocks5Client = new TorSocks5Client(TorSocks5EndPoint);
- await TorSocks5Client.ConnectAsync();
- await TorSocks5Client.HandshakeAsync(IsolateStream);
- await TorSocks5Client.ConnectToDestinationAsync(host, request.RequestUri.Port);
+ await TorSocks5Client.ConnectAsync().ConfigureAwait(false);
+ await TorSocks5Client.HandshakeAsync(IsolateStream).ConfigureAwait(false);
+ await TorSocks5Client.ConnectToDestinationAsync(host, request.RequestUri.Port).ConfigureAwait(false);
Stream stream = TorSocks5Client.TcpClient.GetStream();
if (request.RequestUri.Scheme == "https")
@@ -219,7 +219,7 @@ namespace WalletWasabi.TorSocks5
host,
new X509CertificateCollection(),
SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12,
- checkCertificateRevocation: true);
+ checkCertificateRevocation: true).ConfigureAwait(false);
stream = sslStream;
}
@@ -249,21 +249,21 @@ namespace WalletWasabi.TorSocks5
{
if (request.Content.Headers.ContentLength is null)
{
- request.Content.Headers.ContentLength = (await request.Content.ReadAsStringAsync()).Length;
+ request.Content.Headers.ContentLength = (await request.Content.ReadAsStringAsync().ConfigureAwait(false)).Length;
}
}
}
}
- var requestString = await request.ToHttpStringAsync();
+ var requestString = await request.ToHttpStringAsync().ConfigureAwait(false);
var bytes = Encoding.UTF8.GetBytes(requestString);
- await TorSocks5Client.Stream.WriteAsync(bytes, 0, bytes.Length);
- await TorSocks5Client.Stream.FlushAsync();
+ await TorSocks5Client.Stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
+ await TorSocks5Client.Stream.FlushAsync().ConfigureAwait(false);
using (var httpResponseMessage = new HttpResponseMessage())
{
- return await HttpResponseMessageExtensions.CreateNewAsync(TorSocks5Client.Stream, request.Method);
+ return await HttpResponseMessageExtensions.CreateNewAsync(TorSocks5Client.Stream, request.Method).ConfigureAwait(false);
}
}

MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -199,8 +199,8 @@ namespace WalletWasabi.TorSocks5
{
try
{
- await client.ConnectAsync();
- await client.HandshakeAsync();
+ await client.ConnectAsync().ConfigureAwait(false);
+ await client.HandshakeAsync().ConfigureAwait(false);
}
catch (ConnectionException)
{
@@ -221,8 +221,8 @@ namespace WalletWasabi.TorSocks5
{
try
{
- await client.ConnectAsync();
- await client.HandshakeAsync();
+ await client.ConnectAsync().ConfigureAwait(false);
+ await client.HandshakeAsync().ConfigureAwait(false);
}
catch (ConnectionException)
{
@@ -280,7 +280,7 @@ namespace WalletWasabi.TorSocks5
using (var client = new TorHttpClient(baseUri, TorSocks5EndPoint))
{
var message = new HttpRequestMessage(HttpMethod.Get, fallBackTestRequestUri);
- await client.SendAsync(message, Stop.Token);
+ await client.SendAsync(message, Stop.Token).ConfigureAwait(false);
}
// Check if it changed in the meantime...
@@ -331,7 +331,7 @@ namespace WalletWasabi.TorSocks5
Stop?.Cancel();
while (Interlocked.CompareExchange(ref _running, 3, 0) == 2)
{
- await Task.Delay(50);
+ await Task.Delay(50).ConfigureAwait(false);
}
Stop?.Dispose();
Stop = null;

MODIFY
WalletWasabi/TorSocks5/TorSocks5Client.cs
WalletWasabi/TorSocks5/TorSocks5Client.cs
@@ -88,13 +88,13 @@ namespace WalletWasabi.TorSocks5
return;
}
- using (await AsyncLock.LockAsync())
+ using (await AsyncLock.LockAsync().ConfigureAwait(false))
{
string host = TorSocks5EndPoint.GetHostOrDefault();
int? port = TorSocks5EndPoint.GetPortOrDefault();
try
{
- await TcpClient.ConnectAsync(host, port.Value);
+ await TcpClient.ConnectAsync(host, port.Value).ConfigureAwait(false);
}
catch (Exception ex) when (IsConnectionRefused(ex))
{
@@ -114,7 +114,7 @@ namespace WalletWasabi.TorSocks5
/// </summary>
internal async Task HandshakeAsync(bool isolateStream = true)
{
- await HandshakeAsync(isolateStream ? RandomString.Generate(21) : "");
+ await HandshakeAsync(isolateStream ? RandomString.Generate(21) : "").ConfigureAwait(false);
}
/// <summary>
@@ -138,7 +138,7 @@ namespace WalletWasabi.TorSocks5
var sendBuffer = new VersionMethodRequest(methods).ToBytes();
- var receiveBuffer = await SendAsync(sendBuffer, 2);
+ var receiveBuffer = await SendAsync(sendBuffer, 2).ConfigureAwait(false);
var methodSelection = new MethodSelectionResponse();
methodSelection.FromBytes(receiveBuffer);
@@ -169,7 +169,7 @@ namespace WalletWasabi.TorSocks5
sendBuffer = usernamePasswordRequest.ToBytes();
Array.Clear(receiveBuffer, 0, receiveBuffer.Length);
- receiveBuffer = await SendAsync(sendBuffer, 2);
+ receiveBuffer = await SendAsync(sendBuffer, 2).ConfigureAwait(false);
var userNamePasswordResponse = new UsernamePasswordResponse();
userNamePasswordResponse.FromBytes(receiveBuffer);
@@ -193,7 +193,7 @@ namespace WalletWasabi.TorSocks5
internal async Task ConnectToDestinationAsync(EndPoint destination, bool isRecursiveCall = false)
{
Guard.NotNull(nameof(destination), destination);
- await ConnectToDestinationAsync(destination.GetHostOrDefault(), destination.GetPortOrDefault().Value, isRecursiveCall: isRecursiveCall);
+ await ConnectToDestinationAsync(destination.GetHostOrDefault(), destination.GetPortOrDefault().Value, isRecursiveCall: isRecursiveCall).ConfigureAwait(false);
}
/// <param name="host">IPv4 or domain</param>
@@ -204,11 +204,11 @@ namespace WalletWasabi.TorSocks5
if (TorSocks5EndPoint is null)
{
- using (await AsyncLock.LockAsync())
+ using (await AsyncLock.LockAsync().ConfigureAwait(false))
{
TcpClient?.Dispose();
TcpClient = IPAddress.TryParse(host, out IPAddress ip) ? new TcpClient(ip.AddressFamily) : new TcpClient();
- await TcpClient.ConnectAsync(host, port);
+ await TcpClient.ConnectAsync(host, port).ConfigureAwait(false);
Stream = TcpClient.GetStream();
RemoteEndPoint = TcpClient.Client.RemoteEndPoint;
}
@@ -227,7 +227,7 @@ namespace WalletWasabi.TorSocks5
var connectionRequest = new TorSocks5Request(cmd, dstAddr, dstPort);
var sendBuffer = connectionRequest.ToBytes();
- var receiveBuffer = await SendAsync(sendBuffer, isRecursiveCall: isRecursiveCall);
+ var receiveBuffer = await SendAsync(sendBuffer, isRecursiveCall: isRecursiveCall).ConfigureAwait(false);
var connectionResponse = new TorSocks5Response();
connectionResponse.FromBytes(receiveBuffer);
@@ -263,7 +263,7 @@ namespace WalletWasabi.TorSocks5
// try reconnect, maybe the server came online already
try
{
- await ConnectToDestinationAsync(RemoteEndPoint, isRecursiveCall: isRecursiveCall);
+ await ConnectToDestinationAsync(RemoteEndPoint, isRecursiveCall: isRecursiveCall).ConfigureAwait(false);
}
catch (Exception ex) when (IsConnectionRefused(ex))
{
@@ -332,16 +332,16 @@ namespace WalletWasabi.TorSocks5
{
if (!isRecursiveCall) // Because AssertConnectedAsync would be calling it again.
{
- await AssertConnectedAsync(isRecursiveCall: true);
+ await AssertConnectedAsync(isRecursiveCall: true).ConfigureAwait(false);
}
- using (await AsyncLock.LockAsync())
+ using (await AsyncLock.LockAsync().ConfigureAwait(false))
{
var stream = TcpClient.GetStream();
// Write data to the stream
- await stream.WriteAsync(sendBuffer, 0, sendBuffer.Length);
- await stream.FlushAsync();
+ await stream.WriteAsync(sendBuffer, 0, sendBuffer.Length).ConfigureAwait(false);
+ await stream.FlushAsync().ConfigureAwait(false);
// If receiveBufferSize is null, zero or negative or bigger than TcpClient.ReceiveBufferSize
// then work with TcpClient.ReceiveBufferSize
@@ -353,7 +353,7 @@ namespace WalletWasabi.TorSocks5
// Receive the response
var receiveBuffer = new byte[actualReceiveBufferSize];
- int receiveCount = await stream.ReadAsync(receiveBuffer, 0, actualReceiveBufferSize);
+ int receiveCount = await stream.ReadAsync(receiveBuffer, 0, actualReceiveBufferSize).ConfigureAwait(false);
if (receiveCount <= 0)
{
@@ -371,7 +371,7 @@ namespace WalletWasabi.TorSocks5
while (stream.DataAvailable)
{
Array.Clear(receiveBuffer, 0, receiveBuffer.Length);
- receiveCount = await stream.ReadAsync(receiveBuffer, 0, actualReceiveBufferSize);
+ receiveCount = await stream.ReadAsync(receiveBuffer, 0, actualReceiveBufferSize).ConfigureAwait(false);
if (receiveCount <= 0)
{
throw new ConnectionException($"Not connected to Tor SOCKS5 proxy: {TorSocks5EndPoint}.");
@@ -393,13 +393,13 @@ namespace WalletWasabi.TorSocks5
// try reconnect, maybe the server came online already
try
{
- await ConnectToDestinationAsync(RemoteEndPoint, isRecursiveCall: true);
+ await ConnectToDestinationAsync(RemoteEndPoint, isRecursiveCall: true).ConfigureAwait(false);
}
catch (Exception ex2) when (IsConnectionRefused(ex2))
{
throw new ConnectionException($"{nameof(TorSocks5Client)} is not connected to {RemoteEndPoint}.", ex2);
}
- return await SendAsync(sendBuffer, receiveBufferSize, isRecursiveCall: true);
+ return await SendAsync(sendBuffer, receiveBufferSize, isRecursiveCall: true).ConfigureAwait(false);
}
}
}
@@ -417,7 +417,7 @@ namespace WalletWasabi.TorSocks5
if (TorSocks5EndPoint is null)
{
- var hostAddresses = await Dns.GetHostAddressesAsync(host);
+ var hostAddresses = await Dns.GetHostAddressesAsync(host).ConfigureAwait(false);
return hostAddresses.First();
}
@@ -430,7 +430,7 @@ namespace WalletWasabi.TorSocks5
var resolveRequest = new TorSocks5Request(cmd, dstAddr, dstPort);
var sendBuffer = resolveRequest.ToBytes();
- var receiveBuffer = await SendAsync(sendBuffer);
+ var receiveBuffer = await SendAsync(sendBuffer).ConfigureAwait(false);
var resolveResponse = new TorSocks5Response();
resolveResponse.FromBytes(receiveBuffer);
@@ -453,7 +453,7 @@ namespace WalletWasabi.TorSocks5
if (TorSocks5EndPoint is null) // Only Tor is iPv4 dependent
{
- var host = await Dns.GetHostEntryAsync(iPv4);
+ var host = await Dns.GetHostEntryAsync(iPv4).ConfigureAwait(false);
return host.HostName;
}
@@ -468,7 +468,7 @@ namespace WalletWasabi.TorSocks5
var resolveRequest = new TorSocks5Request(cmd, dstAddr, dstPort);
var sendBuffer = resolveRequest.ToBytes();
- var receiveBuffer = await SendAsync(sendBuffer);
+ var receiveBuffer = await SendAsync(sendBuffer).ConfigureAwait(false);
var resolveResponse = new TorSocks5Response();
resolveResponse.FromBytes(receiveBuffer);

ConfigureAwait in Tor library.