Add link labyrinth, static robots.txt and robots bait paths
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b7027e2a72
commit
a25072e6fb
29 files changed
+774
-34
No files matched your search
@@ -13,22 +13,42 @@ public sealed class ConfiguredStrategySelector(
|
||||
public ITarpitStrategy? Select(TrapContext context)
|
||||
{
|
||||
var candidates = strategies.Where(strategy => strategy.Supports(context.Session.Protocol)).ToList();
|
||||
if (string.Equals(context.Path, RobotsStaticStrategy.Path, StringComparison.OrdinalIgnoreCase)
|
||||
&& candidates.FirstOrDefault(strategy => strategy.Name == RobotsStaticStrategy.StrategyName) is { } robots)
|
||||
{
|
||||
return robots;
|
||||
}
|
||||
|
||||
if (BaitPaths.Matches(BaitPaths.Parse(options.CurrentValue.BaitPaths), context.Path)
|
||||
&& candidates.FirstOrDefault(strategy => strategy.Name == MazeDripStrategy.BaitName) is { } bait)
|
||||
{
|
||||
return bait;
|
||||
}
|
||||
|
||||
if (options.CurrentValue.MatchPath && FileContent.Match(context.Path) is { } profile
|
||||
&& candidates.FirstOrDefault(strategy => strategy.Name == profile.Name) is { } fileStrategy)
|
||||
{
|
||||
return fileStrategy;
|
||||
}
|
||||
|
||||
var maze = options.CurrentValue.LinkSpacing > 0
|
||||
&& candidates.Any(strategy => strategy.Name == MazeDripStrategy.PageName);
|
||||
var page = maze ? MazeDripStrategy.PageName : HtmlDripStrategy.StrategyName;
|
||||
string[] wanted = options.CurrentValue.Content switch
|
||||
{
|
||||
DripContent.Text => [TextDripStrategy.StrategyName],
|
||||
DripContent.Alternating => [HtmlDripStrategy.StrategyName, TextDripStrategy.StrategyName],
|
||||
_ => [HtmlDripStrategy.StrategyName]
|
||||
DripContent.Alternating => [page, TextDripStrategy.StrategyName],
|
||||
_ => [page]
|
||||
};
|
||||
|
||||
var matching = candidates.Where(strategy => wanted.Contains(strategy.Name)).ToList();
|
||||
return matching.Count == 0
|
||||
var chosen = matching.Count == 0
|
||||
? candidates.FirstOrDefault()
|
||||
: matching[random.Next(0, matching.Count)];
|
||||
|
||||
return chosen?.Name == MazeDripStrategy.PageName && MazeContent.IsDirectory(context.Path)
|
||||
&& candidates.FirstOrDefault(strategy => strategy.Name == MazeDripStrategy.ListingName) is { } listing
|
||||
? listing
|
||||
: chosen;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,10 @@ internal sealed class CountingTrapChannel(ITrapChannel inner) : ITrapChannel
|
||||
|
||||
public TrapSession Session => inner.Session;
|
||||
|
||||
public string? Path => inner.Path;
|
||||
|
||||
public string? Host => inner.Host;
|
||||
|
||||
public long BytesSent => Interlocked.Read(ref _bytesSent);
|
||||
|
||||
public async ValueTask WriteAsync(ReadOnlyMemory<byte> data, CancellationToken ct)
|
||||
|
||||
@@ -31,7 +31,13 @@ public sealed partial class TrapRunner(
|
||||
|
||||
using var _ = lease;
|
||||
var description = strategy is IStrategyDetails details ? details.Describe() : strategy.Name;
|
||||
using var hold = new CancellationTokenSource(options.CurrentValue.MaxHoldDuration, timeProvider);
|
||||
var holdDuration = options.CurrentValue.MaxHoldDuration;
|
||||
if (strategy is IHoldExtension extension && extension.MinimumHold > holdDuration)
|
||||
{
|
||||
holdDuration = extension.MinimumHold;
|
||||
}
|
||||
|
||||
using var hold = new CancellationTokenSource(holdDuration, timeProvider);
|
||||
using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct, hold.Token);
|
||||
|
||||
CountingTrapChannel? channel = null;
|
||||
|
||||
Reference in new issue
Block a user