Dashboard table "Gerade in der Falle" and MCP tool list_active, backed by an in-memory registry of running traps. Changelog prepared for 0.8.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System.Collections.Concurrent;
|
|
using Flypaper.Core.Abstractions;
|
|
using Flypaper.Core.Models;
|
|
|
|
namespace Flypaper.Core.Runtime;
|
|
|
|
public sealed class ActiveTrapRegistry(TimeProvider timeProvider) : IActiveTraps
|
|
{
|
|
private readonly ConcurrentDictionary<Guid, Entry> _entries = new();
|
|
|
|
public IActiveTrapHandle Begin(TrapContext context, string strategy)
|
|
{
|
|
var entry = new Entry(this, context, strategy, timeProvider.GetUtcNow());
|
|
_entries[context.Session.Id] = entry;
|
|
return entry;
|
|
}
|
|
|
|
public IReadOnlyList<ActiveTrap> Snapshot() =>
|
|
_entries.Values.Select(entry => entry.ToActiveTrap()).OrderBy(trap => trap.StartedAt).ToList();
|
|
|
|
private sealed class Entry(ActiveTrapRegistry owner, TrapContext context, string strategy, DateTimeOffset startedAt) : IActiveTrapHandle
|
|
{
|
|
private Func<long>? _bytesSent;
|
|
|
|
public void Attach(Func<long> bytesSent) => _bytesSent = bytesSent;
|
|
|
|
public ActiveTrap ToActiveTrap() => new(
|
|
context.Session.Id,
|
|
context.Session.RemoteIp,
|
|
context.Target,
|
|
context.ClientInfo,
|
|
strategy,
|
|
startedAt,
|
|
_bytesSent?.Invoke() ?? 0);
|
|
|
|
public void Dispose() => owner._entries.TryRemove(context.Session.Id, out _);
|
|
}
|
|
}
|