Restructure solution into folders and fix persistence issues
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
37987a394a
commit
7c39cb5562
62 files changed
+219
-151
No files matched your search
+4
-1
@@ -1,8 +1,11 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Flypaper.Core.Models;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Abstractions;
|
||||
|
||||
public interface IConnectionGovernor
|
||||
{
|
||||
int ActiveConnections { get; }
|
||||
|
||||
bool TryAcquire(TrapSession session, [NotNullWhen(true)] out IDisposable? lease);
|
||||
}
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
namespace Flypaper.Core;
|
||||
using Flypaper.Core.Models;
|
||||
|
||||
namespace Flypaper.Core.Abstractions;
|
||||
|
||||
public interface ITarpitStrategy
|
||||
{
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Flypaper.Core;
|
||||
using Flypaper.Core.Models;
|
||||
|
||||
namespace Flypaper.Core.Abstractions;
|
||||
|
||||
public interface ITrapChannel
|
||||
{
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
namespace Flypaper.Core;
|
||||
using Flypaper.Core.Models;
|
||||
|
||||
namespace Flypaper.Core.Abstractions;
|
||||
|
||||
public interface ITrapEventSink
|
||||
{
|
||||
+4
-3
@@ -1,3 +1,5 @@
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Runtime;
|
||||
using Flypaper.Core.Strategies;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -5,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
public static class FlypaperCoreExtensions
|
||||
{
|
||||
public static IServiceCollection AddFlypaperCore(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
@@ -13,8 +15,7 @@ public static class ServiceCollectionExtensions
|
||||
services.Configure<DripOptions>(configuration.GetSection(DripOptions.SectionName));
|
||||
|
||||
services.TryAddSingleton(TimeProvider.System);
|
||||
services.TryAddSingleton<ConnectionGovernor>();
|
||||
services.TryAddSingleton<IConnectionGovernor>(sp => sp.GetRequiredService<ConnectionGovernor>());
|
||||
services.TryAddSingleton<IConnectionGovernor, ConnectionGovernor>();
|
||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, DripStrategy>());
|
||||
services.TryAddSingleton<TrapRunner>();
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Models;
|
||||
|
||||
public sealed record TrapContext(TrapSession Session, string? Target = null, string? ClientInfo = null);
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Net;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Models;
|
||||
|
||||
public sealed record TrapEvent(
|
||||
Guid SessionId,
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Models;
|
||||
|
||||
public enum TrapOutcome
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Models;
|
||||
|
||||
public enum TrapProtocol
|
||||
{
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Net;
|
||||
|
||||
namespace Flypaper.Core.Models;
|
||||
|
||||
public sealed record TrapSession(Guid Id, TrapProtocol Protocol, IPAddress RemoteIp, DateTimeOffset StartedAt)
|
||||
{
|
||||
public IPAddress RemoteIp { get; init; } = RemoteIp.IsIPv4MappedToIPv6 ? RemoteIp.MapToIPv4() : RemoteIp;
|
||||
}
|
||||
+4
-4
@@ -1,8 +1,10 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Runtime;
|
||||
|
||||
public sealed class ConnectionGovernor(IOptionsMonitor<FlypaperOptions> options) : IConnectionGovernor
|
||||
{
|
||||
@@ -23,7 +25,7 @@ public sealed class ConnectionGovernor(IOptionsMonitor<FlypaperOptions> options)
|
||||
|
||||
public bool TryAcquire(TrapSession session, [NotNullWhen(true)] out IDisposable? lease)
|
||||
{
|
||||
var ip = Normalize(session.RemoteIp);
|
||||
var ip = session.RemoteIp;
|
||||
var limits = options.CurrentValue;
|
||||
|
||||
lock (_gate)
|
||||
@@ -55,8 +57,6 @@ public sealed class ConnectionGovernor(IOptionsMonitor<FlypaperOptions> options)
|
||||
}
|
||||
}
|
||||
|
||||
private static IPAddress Normalize(IPAddress ip) => ip.IsIPv4MappedToIPv6 ? ip.MapToIPv4() : ip;
|
||||
|
||||
private sealed class Lease(ConnectionGovernor owner, IPAddress ip) : IDisposable
|
||||
{
|
||||
private int _disposed;
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
namespace Flypaper.Core;
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Models;
|
||||
|
||||
namespace Flypaper.Core.Runtime;
|
||||
|
||||
internal sealed class CountingTrapChannel(ITrapChannel inner) : ITrapChannel
|
||||
{
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Net;
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Runtime;
|
||||
|
||||
public sealed partial class TrapRunner(
|
||||
IConnectionGovernor governor,
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public sealed record RuntimeSettings(
|
||||
IReadOnlyList<string> TrapPaths,
|
||||
+1
-3
@@ -1,4 +1,4 @@
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public sealed record RuntimeSettingsInput(
|
||||
string? TrapPaths,
|
||||
@@ -7,5 +7,3 @@ public sealed record RuntimeSettingsInput(
|
||||
string? MaxConnectionsPerIp,
|
||||
string? MaxHoldDuration,
|
||||
string? ExtraKnownHosts);
|
||||
|
||||
public sealed record RuntimeSettingsParseResult(RuntimeSettings? Settings, IReadOnlyDictionary<string, string> Errors);
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public sealed record RuntimeSettingsParseResult(RuntimeSettings? Settings, IReadOnlyDictionary<string, string> Errors);
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public static partial class RuntimeSettingsParser
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public static class SettingKeys
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Flypaper.Core;
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public static class SettingsList
|
||||
{
|
||||
@@ -1,3 +1,5 @@
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
using System.Net;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
|
||||
public sealed record TrapSession(Guid Id, TrapProtocol Protocol, IPAddress RemoteIp, DateTimeOffset StartedAt);
|
||||
Reference in new issue
Block a user