Add data management, randomized HTML drip and public README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-14 16:08:45 +01:00
1 parent 3671019e60
commit f5d8ca7484
46 files changed
+1601 -172

No files matched your search

@@ -0,0 +1,10 @@
using Flypaper.Core.Abstractions;
using Flypaper.Core.Models;
namespace Flypaper.Core.Runtime;
public sealed class ProtocolStrategySelector(IEnumerable<ITarpitStrategy> strategies) : ITrapStrategySelector
{
public ITarpitStrategy? Select(TrapContext context) =>
strategies.FirstOrDefault(strategy => strategy.Supports(context.Session.Protocol));
}
@@ -0,0 +1,8 @@
using Flypaper.Core.Abstractions;
namespace Flypaper.Core.Runtime;
internal sealed class SystemRandomSource : IRandomSource
{
public int Next(int minValue, int maxValue) => Random.Shared.Next(minValue, maxValue);
}
+18 -9
View File
@@ -1,6 +1,7 @@
using System.Net;
using Flypaper.Core.Abstractions;
using Flypaper.Core.Models;
using Flypaper.Core.Networking;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -8,7 +9,7 @@ namespace Flypaper.Core.Runtime;
public sealed partial class TrapRunner(
IConnectionGovernor governor,
IEnumerable<ITarpitStrategy> strategies,
ITrapStrategySelector strategies,
ITrapEventSink sink,
IOptionsMonitor<FlypaperOptions> options,
TimeProvider timeProvider,
@@ -20,7 +21,7 @@ public sealed partial class TrapRunner(
CancellationToken ct)
{
var session = context.Session;
var strategy = strategies.FirstOrDefault(s => s.Supports(session.Protocol));
var strategy = strategies.Select(context);
if (strategy is null || !governor.TryAcquire(session, out var lease))
{
@@ -69,9 +70,12 @@ public sealed partial class TrapRunner(
context.Target,
context.ClientInfo);
var store = !(options.CurrentValue.IgnorePrivateNetworks && PrivateNetworks.Contains(trapEvent.RemoteIp));
var storageNote = store ? "" : " (not stored)";
if (outcome == TrapOutcome.Rejected)
{
LogRejected(trapEvent.RemoteIp, trapEvent.Target, trapEvent.ClientInfo);
LogRejected(trapEvent.RemoteIp, trapEvent.Target, trapEvent.ClientInfo, storageNote);
}
else
{
@@ -81,22 +85,27 @@ public sealed partial class TrapRunner(
trapEvent.Duration.TotalSeconds,
trapEvent.BytesSent,
trapEvent.Outcome,
trapEvent.ClientInfo);
trapEvent.ClientInfo,
storageNote);
}
sink.Publish(trapEvent);
if (store)
{
sink.Publish(trapEvent);
}
}
[LoggerMessage(Level = LogLevel.Information,
Message = "Trapped {RemoteIp} {Target} {DurationSeconds:F1}s {BytesSent}B {Outcome} \"{UserAgent}\"")]
Message = "Trapped {RemoteIp} {Target} {DurationSeconds:F1}s {BytesSent}B {Outcome} \"{UserAgent}\"{StorageNote}")]
private partial void LogTrapped(
IPAddress remoteIp,
string? target,
double durationSeconds,
long bytesSent,
TrapOutcome outcome,
string? userAgent);
string? userAgent,
string storageNote);
[LoggerMessage(Level = LogLevel.Information, Message = "Rejected {RemoteIp} {Target} \"{UserAgent}\"")]
private partial void LogRejected(IPAddress remoteIp, string? target, string? userAgent);
[LoggerMessage(Level = LogLevel.Information, Message = "Rejected {RemoteIp} {Target} \"{UserAgent}\"{StorageNote}")]
private partial void LogRejected(IPAddress remoteIp, string? target, string? userAgent, string storageNote);
}