mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
Remove tor client factory
This commit is contained in:
parent
1a62ee9260
commit
e4cb1a875b
5 changed files with 2 additions and 59 deletions
|
@ -35,7 +35,6 @@
|
|||
<PackageReference Include="BundlerMinifier.Core" Version="3.2.435" />
|
||||
<PackageReference Include="BundlerMinifier.TagHelpers" Version="3.2.435" />
|
||||
<PackageReference Include="HtmlSanitizer" Version="4.0.217" />
|
||||
<PackageReference Include="HttpToSocks5Proxy" Version="1.4.0" />
|
||||
<PackageReference Include="LedgerWallet" Version="2.0.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" />
|
||||
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.9.8">
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
TempData.Remove("bpu");
|
||||
var httpClient = _socks5HttpClientFactory.CreateClient("payjoin");
|
||||
if (endpoint.IsOnion() && httpClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
httpClient = _httpClientFactory.CreateClient("payjoin");
|
||||
}
|
||||
var httpClient = _httpClientFactory.CreateClient("payjoin");
|
||||
|
||||
var cloned = psbt.Clone();
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ namespace BTCPayServer.Controllers
|
|||
private readonly WalletReceiveStateService _WalletReceiveStateService;
|
||||
private readonly EventAggregator _EventAggregator;
|
||||
private readonly SettingsRepository _settingsRepository;
|
||||
private readonly Socks5HttpClientFactory _socks5HttpClientFactory;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
public RateFetcher RateFetcher { get; }
|
||||
|
||||
|
@ -70,7 +69,6 @@ namespace BTCPayServer.Controllers
|
|||
WalletReceiveStateService walletReceiveStateService,
|
||||
EventAggregator eventAggregator,
|
||||
SettingsRepository settingsRepository,
|
||||
Socks5HttpClientFactory socks5HttpClientFactory,
|
||||
IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_currencyTable = currencyTable;
|
||||
|
@ -88,7 +86,6 @@ namespace BTCPayServer.Controllers
|
|||
_WalletReceiveStateService = walletReceiveStateService;
|
||||
_EventAggregator = eventAggregator;
|
||||
_settingsRepository = settingsRepository;
|
||||
_socks5HttpClientFactory = socks5HttpClientFactory;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@ namespace BTCPayServer.Hosting
|
|||
services.TryAddSingleton<SettingsRepository>();
|
||||
services.TryAddSingleton<TorServices>();
|
||||
services.TryAddSingleton<SocketFactory>();
|
||||
services.TryAddSingleton<Socks5HttpClientFactory>();
|
||||
services.TryAddSingleton<LightningClientFactoryService>();
|
||||
services.TryAddSingleton<InvoicePaymentNotification>();
|
||||
services.TryAddSingleton<BTCPayServerOptions>(o =>
|
||||
|
|
|
@ -1,57 +1,13 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Configuration;
|
||||
using MihaZupan;
|
||||
using NBitcoin.Protocol.Connectors;
|
||||
using NBitcoin.Protocol;
|
||||
|
||||
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
|
||||
{
|
||||
private readonly BTCPayServerOptions _options;
|
||||
|
|
Loading…
Add table
Reference in a new issue