Remove tor client factory

This commit is contained in:
Kukks
2020-03-17 07:53:20 +01:00
parent 1a62ee9260
commit e4cb1a875b
5 changed files with 2 additions and 59 deletions

View File

@@ -35,7 +35,6 @@
<PackageReference Include="BundlerMinifier.Core" Version="3.2.435" /> <PackageReference Include="BundlerMinifier.Core" Version="3.2.435" />
<PackageReference Include="BundlerMinifier.TagHelpers" Version="3.2.435" /> <PackageReference Include="BundlerMinifier.TagHelpers" Version="3.2.435" />
<PackageReference Include="HtmlSanitizer" Version="4.0.217" /> <PackageReference Include="HtmlSanitizer" Version="4.0.217" />
<PackageReference Include="HttpToSocks5Proxy" Version="1.4.0" />
<PackageReference Include="LedgerWallet" Version="2.0.0.5" /> <PackageReference Include="LedgerWallet" Version="2.0.0.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" />
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.9.8"> <PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.9.8">

View File

@@ -164,15 +164,7 @@ namespace BTCPayServer.Controllers
if (TempData.TryGetValue( "bpu", out var bpu) && !string.IsNullOrEmpty(bpu?.ToString()) && Uri.TryCreate(bpu.ToString(), UriKind.Absolute, out var endpoint)) if (TempData.TryGetValue( "bpu", out var bpu) && !string.IsNullOrEmpty(bpu?.ToString()) && Uri.TryCreate(bpu.ToString(), UriKind.Absolute, out var endpoint))
{ {
TempData.Remove("bpu"); TempData.Remove("bpu");
var httpClient = _socks5HttpClientFactory.CreateClient("payjoin"); var httpClient = _httpClientFactory.CreateClient("payjoin");
if (endpoint.IsOnion() && httpClient == null)
{
return null;
}
else
{
httpClient = _httpClientFactory.CreateClient("payjoin");
}
var cloned = psbt.Clone(); var cloned = psbt.Clone();

View File

@@ -50,7 +50,6 @@ namespace BTCPayServer.Controllers
private readonly WalletReceiveStateService _WalletReceiveStateService; private readonly WalletReceiveStateService _WalletReceiveStateService;
private readonly EventAggregator _EventAggregator; private readonly EventAggregator _EventAggregator;
private readonly SettingsRepository _settingsRepository; private readonly SettingsRepository _settingsRepository;
private readonly Socks5HttpClientFactory _socks5HttpClientFactory;
private readonly IHttpClientFactory _httpClientFactory; private readonly IHttpClientFactory _httpClientFactory;
public RateFetcher RateFetcher { get; } public RateFetcher RateFetcher { get; }
@@ -70,7 +69,6 @@ namespace BTCPayServer.Controllers
WalletReceiveStateService walletReceiveStateService, WalletReceiveStateService walletReceiveStateService,
EventAggregator eventAggregator, EventAggregator eventAggregator,
SettingsRepository settingsRepository, SettingsRepository settingsRepository,
Socks5HttpClientFactory socks5HttpClientFactory,
IHttpClientFactory httpClientFactory) IHttpClientFactory httpClientFactory)
{ {
_currencyTable = currencyTable; _currencyTable = currencyTable;
@@ -88,7 +86,6 @@ namespace BTCPayServer.Controllers
_WalletReceiveStateService = walletReceiveStateService; _WalletReceiveStateService = walletReceiveStateService;
_EventAggregator = eventAggregator; _EventAggregator = eventAggregator;
_settingsRepository = settingsRepository; _settingsRepository = settingsRepository;
_socks5HttpClientFactory = socks5HttpClientFactory;
_httpClientFactory = httpClientFactory; _httpClientFactory = httpClientFactory;
} }

View File

@@ -68,7 +68,6 @@ namespace BTCPayServer.Hosting
services.TryAddSingleton<SettingsRepository>(); services.TryAddSingleton<SettingsRepository>();
services.TryAddSingleton<TorServices>(); services.TryAddSingleton<TorServices>();
services.TryAddSingleton<SocketFactory>(); services.TryAddSingleton<SocketFactory>();
services.TryAddSingleton<Socks5HttpClientFactory>();
services.TryAddSingleton<LightningClientFactoryService>(); services.TryAddSingleton<LightningClientFactoryService>();
services.TryAddSingleton<InvoicePaymentNotification>(); services.TryAddSingleton<InvoicePaymentNotification>();
services.TryAddSingleton<BTCPayServerOptions>(o => services.TryAddSingleton<BTCPayServerOptions>(o =>

View File

@@ -1,57 +1,13 @@
using System.Collections.Concurrent; using System.Net;
using System.Net;
using System.Net.Http;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Configuration; using BTCPayServer.Configuration;
using MihaZupan;
using NBitcoin.Protocol.Connectors; using NBitcoin.Protocol.Connectors;
using NBitcoin.Protocol; using NBitcoin.Protocol;
namespace BTCPayServer.Services namespace BTCPayServer.Services
{ {
public class Socks5HttpClientFactory : IHttpClientFactory
{
private readonly BTCPayServerOptions _options;
public Socks5HttpClientFactory(BTCPayServerOptions options)
{
_options = options;
}
private static (string Host, int Port)? ToParts(EndPoint endpoint)
{
switch (endpoint)
{
case DnsEndPoint dns:
return (dns.Host, dns.Port);
case IPEndPoint ipEndPoint:
return (ipEndPoint.Address.ToString(), ipEndPoint.Port);
}
return null;
}
private ConcurrentDictionary<string, HttpClient> cachedClients = new ConcurrentDictionary<string, HttpClient>();
public HttpClient CreateClient(string name)
{
return cachedClients.GetOrAdd(name, s =>
{
var parts = ToParts(_options.SocksEndpoint);
if (!parts.HasValue)
{
return null;
}
var proxy = new HttpToSocks5Proxy(parts.Value.Host, parts.Value.Port);
return new HttpClient(
new HttpClientHandler {Proxy = proxy, },
true);
});
}
}
public class SocketFactory public class SocketFactory
{ {
private readonly BTCPayServerOptions _options; private readonly BTCPayServerOptions _options;