Make the hold method configurable in the dashboard
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9a56fc5b48
commit
6b9bf3cd5f
40 files changed
+815
-134
No files matched your search
@@ -0,0 +1,38 @@
|
||||
using System.Globalization;
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
public abstract class DripStrategy(
|
||||
IOptionsMonitor<DripOptions> options,
|
||||
IRandomSource random,
|
||||
TimeProvider timeProvider) : ITarpitStrategy, IStrategyDetails
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
public abstract string MediaType { get; }
|
||||
|
||||
public bool Supports(TrapProtocol protocol) => protocol == TrapProtocol.Http;
|
||||
|
||||
public string Describe()
|
||||
{
|
||||
var current = options.CurrentValue;
|
||||
return string.Create(
|
||||
CultureInfo.InvariantCulture,
|
||||
$"{Name} {current.MinDelay.TotalMilliseconds:0}-{current.MaxDelay.TotalMilliseconds:0}ms {current.MinChunkSize}-{current.MaxChunkSize}B");
|
||||
}
|
||||
|
||||
public async Task RunAsync(ITrapChannel channel, CancellationToken ct)
|
||||
{
|
||||
foreach (var step in DripSchedule.Create(Content(random), random, options.CurrentValue))
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
await channel.WriteAsync(step.Chunk, ct);
|
||||
await Task.Delay(step.Delay, timeProvider, ct);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract IEnumerable<string> Content(IRandomSource random);
|
||||
}
|
||||
Reference in new issue
Block a user