fix local coord log issues

This commit is contained in:
Kukks
2024-06-20 11:54:15 +02:00
parent 722d3f7be0
commit 177e34fe3d
3 changed files with 50 additions and 36 deletions

View File

@@ -13,7 +13,7 @@
<PropertyGroup> <PropertyGroup>
<Product>Coinjoin</Product> <Product>Coinjoin</Product>
<Description>Allows you to integrate your btcpayserver store with coinjoins.</Description> <Description>Allows you to integrate your btcpayserver store with coinjoins.</Description>
<Version>1.0.89</Version> <Version>1.0.90</Version>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup> </PropertyGroup>

View File

@@ -133,10 +133,45 @@ public class WabisabiCoordinatorClientInstanceManager:IHostedService
: url + "/"; : url + "/";
} }
var coordinator = url is null ? null : new Uri(url);
IWasabiHttpClientFactory wasabiHttpClientFactory;
if (name == "local" || coordinator is null)
{
var controller = _provider.GetService<WabiSabiController>();
if(controller is null)
return;
wasabiHttpClientFactory = new LocalWabisabiClientFactory( controller);
}
else if (coordinator.Scheme == "nostr" &&
coordinator.AbsolutePath.TrimEnd('/').FromNIP19Note() is NIP19.NosteProfileNote nostrProfileNote)
{
var socks5HttpClientHandler = _provider.GetRequiredService<Socks5HttpClientHandler>();
var factory = new NostrWabisabiClientFactory(socks5HttpClientHandler, nostrProfileNote);
wasabiHttpClientFactory = factory;
}
else
{
var config = _provider.GetService<IConfiguration>();
var socksEndpoint = config.GetValue<string>("socksendpoint");
EndPointParser.TryParse(socksEndpoint, 9050, out var torEndpoint);
if (torEndpoint is not null && torEndpoint is DnsEndPoint dnsEndPoint)
{
torEndpoint = new IPEndPoint(Dns.GetHostAddresses(dnsEndPoint.Host).First(), dnsEndPoint.Port);
}
wasabiHttpClientFactory = new WasabiHttpClientFactory(torEndpoint, () => coordinator);
}
var instance = new WabisabiCoordinatorClientInstance( var instance = new WabisabiCoordinatorClientInstance(
displayName, displayName,
name, url is null? null: new Uri(url), _provider.GetService<ILoggerFactory>(), _provider, UTXOLocker, name, url is null? null: new Uri(url), wasabiHttpClientFactory,_provider.GetService<ILoggerFactory>(), _provider, UTXOLocker,
_provider.GetService<WalletProvider>(), termsConditions, description,_provider.GetRequiredService<Socks5HttpClientHandler>()); _provider.GetService<WalletProvider>(), termsConditions, description);
if (HostedServices.TryAdd(instance.CoordinatorName, instance)) if (HostedServices.TryAdd(instance.CoordinatorName, instance))
{ {
if(started) if(started)
@@ -254,27 +289,21 @@ public class WabisabiCoordinatorClientInstance:IHostedService
public WasabiCoordinatorStatusFetcher WasabiCoordinatorStatusFetcher { get; set; } public WasabiCoordinatorStatusFetcher WasabiCoordinatorStatusFetcher { get; set; }
public CoinJoinManager CoinJoinManager { get; set; } public CoinJoinManager CoinJoinManager { get; set; }
public string Description { get; set; } public string Description { get; set; }
private readonly WalletWasabi.Services.HostedServices _hostedServices = new(); public readonly WalletWasabi.Services.HostedServices _hostedServices = new();
public WabisabiCoordinatorClientInstance(string coordinatorDisplayName, public WabisabiCoordinatorClientInstance(
string coordinatorDisplayName,
string coordinatorName, string coordinatorName,
Uri coordinator, Uri coordinator,
IWasabiHttpClientFactory wasabiHttpClientFactory,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
IUTXOLocker utxoLocker, IUTXOLocker utxoLocker,
WalletProvider walletProvider, string termsConditions, string description, WalletProvider walletProvider, string termsConditions, string description, string coordinatorIdentifier = "CoinJoinCoordinatorIdentifier"
Socks5HttpClientHandler socks5HttpClientHandler, string coordinatorIdentifier = "CoinJoinCoordinatorIdentifier"
) )
{ {
_utxoLocker = utxoLocker; _utxoLocker = utxoLocker;
var config = serviceProvider.GetService<IConfiguration>();
var socksEndpoint = config.GetValue<string>("socksendpoint");
EndPointParser.TryParse(socksEndpoint, 9050, out var torEndpoint);
if (torEndpoint is not null && torEndpoint is DnsEndPoint dnsEndPoint)
{
torEndpoint = new IPEndPoint(Dns.GetHostAddresses(dnsEndPoint.Host).First(), dnsEndPoint.Port);
}
CoordinatorDisplayName = coordinatorDisplayName; CoordinatorDisplayName = coordinatorDisplayName;
CoordinatorName = coordinatorName; CoordinatorName = coordinatorName;
@@ -286,25 +315,10 @@ public class WabisabiCoordinatorClientInstance:IHostedService
IWabiSabiApiRequestHandler sharedWabisabiClient = null; IWabiSabiApiRequestHandler sharedWabisabiClient = null;
var roundStateUpdaterCircuit = new PersonCircuit(); var roundStateUpdaterCircuit = new PersonCircuit();
WasabiHttpClientFactory = wasabiHttpClientFactory;
if(wasabiHttpClientFactory is IHostedService hostedService)
_hostedServices.Register<IHostedService>(() => hostedService, hostedService.GetType().Name);
if (coordinatorName == "local")
{
WasabiHttpClientFactory = new LocalWabisabiClientFactory( serviceProvider.GetRequiredService<WabiSabiController>());
}
else if (coordinator.Scheme == "nostr" &&
coordinator.AbsolutePath.TrimEnd('/').FromNIP19Note() is NIP19.NosteProfileNote nostrProfileNote)
{
var factory = new NostrWabisabiClientFactory(socks5HttpClientHandler, nostrProfileNote);
WasabiHttpClientFactory = factory;
_hostedServices.Register<NostrWabisabiClientFactory>(() => factory, "NostrWabisabiClientFactory");
}
else
{
WasabiHttpClientFactory = new WasabiHttpClientFactory(torEndpoint, () => Coordinator);
}
sharedWabisabiClient = sharedWabisabiClient =
WasabiHttpClientFactory.NewWabiSabiApiRequestHandler(Mode.SingleCircuitPerLifetime, WasabiHttpClientFactory.NewWabiSabiApiRequestHandler(Mode.SingleCircuitPerLifetime,