Add data management, randomized HTML drip and public README
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3671019e60
commit
f5d8ca7484
46 files changed
+1601
-172
No files matched your search
@@ -0,0 +1,52 @@
|
||||
using System.Text;
|
||||
using Flypaper.Core.Abstractions;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
public static class DripSchedule
|
||||
{
|
||||
public static IEnumerable<DripStep> Create(IEnumerable<string> content, IRandomSource random, DripOptions options)
|
||||
{
|
||||
var minChunk = Math.Max(1, options.MinChunkSize);
|
||||
var maxChunk = Math.Max(minChunk, options.MaxChunkSize);
|
||||
var minDelay = (int)Math.Max(0, options.MinDelay.TotalMilliseconds);
|
||||
var maxDelay = Math.Max(minDelay, (int)options.MaxDelay.TotalMilliseconds);
|
||||
|
||||
using var fragments = content.GetEnumerator();
|
||||
var pending = Array.Empty<byte>();
|
||||
var offset = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var chunk = new byte[random.Next(minChunk, maxChunk + 1)];
|
||||
var filled = 0;
|
||||
|
||||
while (filled < chunk.Length)
|
||||
{
|
||||
if (offset == pending.Length)
|
||||
{
|
||||
if (!fragments.MoveNext())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pending = Encoding.UTF8.GetBytes(fragments.Current);
|
||||
offset = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
var count = Math.Min(chunk.Length - filled, pending.Length - offset);
|
||||
pending.AsSpan(offset, count).CopyTo(chunk.AsSpan(filled));
|
||||
offset += count;
|
||||
filled += count;
|
||||
}
|
||||
|
||||
if (filled == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return new DripStep(chunk.AsMemory(0, filled), TimeSpan.FromMilliseconds(random.Next(minDelay, maxDelay + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user