Support trimming
This commit is contained in:
parent
6dbcb38ce2
commit
526beac55e
9 changed files with 89 additions and 18 deletions
|
|
@ -1,10 +1,8 @@
|
|||
using pdns_dhcp.Options;
|
||||
|
||||
using Stl.Interception;
|
||||
|
||||
namespace pdns_dhcp.Kea;
|
||||
|
||||
public interface IKeaFactory : IRequiresFullProxy
|
||||
public interface IKeaFactory
|
||||
{
|
||||
KeaDhcp4LeaseHandler CreateHandler4();
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using System.Globalization;
|
|||
|
||||
using DotNext.Buffers;
|
||||
|
||||
using Microsoft.Toolkit.HighPerformance.Buffers;
|
||||
using CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
namespace pdns_dhcp.Kea;
|
||||
|
||||
|
|
|
|||
39
src/pdns-dhcp/Kea/KeaFactoryServices.cs
Normal file
39
src/pdns-dhcp/Kea/KeaFactoryServices.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using pdns_dhcp.Options;
|
||||
|
||||
namespace pdns_dhcp.Kea;
|
||||
|
||||
public static class KeaFactoryServices
|
||||
{
|
||||
public static IServiceCollection AddKeaFactory(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IKeaFactory, KeaFactory>();
|
||||
return services;
|
||||
}
|
||||
|
||||
private class KeaFactory(IServiceProvider services) : IKeaFactory
|
||||
{
|
||||
private ObjectFactory<KeaDhcp4LeaseHandler>? _cachedCreateHandler4;
|
||||
private ObjectFactory<KeaDhcp6LeaseHandler>? _cachedCreateHandler6;
|
||||
private ObjectFactory<KeaDhcpLeaseWatcher>? _cachedCreateWatcher;
|
||||
|
||||
KeaDhcp4LeaseHandler IKeaFactory.CreateHandler4()
|
||||
{
|
||||
_cachedCreateHandler4 ??= ActivatorUtilities.CreateFactory<KeaDhcp4LeaseHandler>([]);
|
||||
return _cachedCreateHandler4(services, null);
|
||||
}
|
||||
|
||||
KeaDhcp6LeaseHandler IKeaFactory.CreateHandler6()
|
||||
{
|
||||
_cachedCreateHandler6 ??= ActivatorUtilities.CreateFactory<KeaDhcp6LeaseHandler>([]);
|
||||
return _cachedCreateHandler6(services, null);
|
||||
}
|
||||
|
||||
KeaDhcpLeaseWatcher IKeaFactory.CreateWatcher(IKeaDhcpLeaseHandler handler, KeaDhcpServerOptions options)
|
||||
{
|
||||
_cachedCreateWatcher ??= ActivatorUtilities.CreateFactory<KeaDhcpLeaseWatcher>([typeof(IKeaDhcpLeaseHandler), typeof(KeaDhcpServerOptions)]);
|
||||
return _cachedCreateWatcher(services, [handler, options]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
using System.Buffers;
|
||||
using System.IO.Pipelines;
|
||||
using System.Net.Sockets;
|
||||
using System.Text.Json;
|
||||
|
||||
using CommunityToolkit.HighPerformance;
|
||||
using CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Toolkit.HighPerformance;
|
||||
using Microsoft.Toolkit.HighPerformance.Buffers;
|
||||
|
||||
using pdns_dhcp.Dns;
|
||||
|
||||
|
|
@ -31,8 +33,7 @@ public class PowerDnsHandler : ConnectionHandler
|
|||
using var writer = connection.Transport.Output.AsStream();
|
||||
while (!connection.ConnectionClosed.IsCancellationRequested)
|
||||
{
|
||||
var read = await input.ReadAsync(connection.ConnectionClosed).ConfigureAwait(false);
|
||||
if (read.IsCanceled)
|
||||
if (await ReadAsync(input, connection.ConnectionClosed) is not { IsCanceled: false } read)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -61,6 +62,18 @@ public class PowerDnsHandler : ConnectionHandler
|
|||
input.AdvanceTo(read.Buffer.End);
|
||||
}
|
||||
|
||||
static async ValueTask<ReadResult?> ReadAsync(PipeReader reader, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await reader.ReadAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static bool ConsumeJson(ArrayPoolBufferWriter<byte> inflight, ArrayPoolBufferWriter<byte> json, ref JsonReaderState state)
|
||||
{
|
||||
bool final = false;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ using pdns_dhcp.Options;
|
|||
using pdns_dhcp.PowerDns;
|
||||
using pdns_dhcp.Services;
|
||||
|
||||
using Stl.Interception;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddSystemd();
|
||||
|
||||
|
|
@ -31,8 +29,8 @@ builder.Services.AddHostedService<DhcpQueueWorker>();
|
|||
builder.Services.AddSingleton<DhcpLeaseQueue>();
|
||||
builder.Services.AddSingleton<DnsRepository>();
|
||||
|
||||
builder.Services.AddTypedFactory<IDhcpWatcherFactory>();
|
||||
builder.Services.AddTypedFactory<IKeaFactory>();
|
||||
builder.Services.AddDhcpWatcherFactory();
|
||||
builder.Services.AddKeaFactory();
|
||||
|
||||
builder.Services.Configure<SocketTransportOptions>(options =>
|
||||
{
|
||||
|
|
|
|||
26
src/pdns-dhcp/Services/DhcpWatcherFactoryServices.cs
Normal file
26
src/pdns-dhcp/Services/DhcpWatcherFactoryServices.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using pdns_dhcp.Kea;
|
||||
using pdns_dhcp.Options;
|
||||
|
||||
namespace pdns_dhcp.Services;
|
||||
|
||||
public static class DhcpWatcherFactoryServices
|
||||
{
|
||||
public static IServiceCollection AddDhcpWatcherFactory(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IDhcpWatcherFactory, DhcpWatcherFactory>();
|
||||
return services;
|
||||
}
|
||||
|
||||
private class DhcpWatcherFactory(IServiceProvider services) : IDhcpWatcherFactory
|
||||
{
|
||||
private ObjectFactory<KeaService>? _cachedKeaService;
|
||||
|
||||
KeaService IDhcpWatcherFactory.KeaService(KeaDhcpOptions options)
|
||||
{
|
||||
_cachedKeaService ??= ActivatorUtilities.CreateFactory<KeaService>([typeof(KeaDhcpOptions)]);
|
||||
return _cachedKeaService(services, [options]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
using pdns_dhcp.Kea;
|
||||
using pdns_dhcp.Options;
|
||||
|
||||
using Stl.Interception;
|
||||
|
||||
namespace pdns_dhcp.Services;
|
||||
|
||||
public interface IDhcpWatcherFactory : IRequiresFullProxy
|
||||
public interface IDhcpWatcherFactory
|
||||
{
|
||||
KeaService KeaService(KeaDhcpOptions options);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
using System.Buffers;
|
||||
|
||||
using Microsoft.Toolkit.HighPerformance.Buffers;
|
||||
using CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
namespace System.IO;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,13 +14,12 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.2" />
|
||||
<PackageReference Include="DotNext.Threading" Version="4.15.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
|
||||
<PackageReference Include="Sep" Version="0.3.0" />
|
||||
<PackageReference Include="Stl.Generators" Version="6.8.11" PrivateAssets="all" />
|
||||
<PackageReference Include="Stl.Interception" Version="6.8.11" />
|
||||
<PackageReference Include="System.IO.Pipelines" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue