30 lines
1.3 KiB
C#
30 lines
1.3 KiB
C#
namespace DataTransfer.Security;
|
|
|
|
public sealed class BotCheckOptions
|
|
{
|
|
public const string SectionName = "BotCheck";
|
|
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Upper bound of the hidden number; a browser tries about half of the numbers on average. A browser computes
|
|
/// roughly 100,000 hashes per second and core, so the default takes a fraction of a second on a desktop and up to
|
|
/// about three seconds on a weak phone.
|
|
/// </summary>
|
|
public int MaxNumber { get; set; } = 200_000;
|
|
|
|
/// <summary>Upper bound used while the server is busy (see <see cref="BusyThreshold" />), to slow down bulk creation.</summary>
|
|
public int BusyMaxNumber { get; set; } = 1_000_000;
|
|
|
|
/// <summary>Share of the connection limit in use from which <see cref="BusyMaxNumber" /> applies; also while clients are queued.</summary>
|
|
public double BusyThreshold { get; set; } = 0.8;
|
|
|
|
/// <summary>A challenge must be solved within this period.</summary>
|
|
public TimeSpan ChallengeLifetime { get; set; } = TimeSpan.FromMinutes(2);
|
|
|
|
public bool IsValid() =>
|
|
MaxNumber > 0
|
|
&& BusyMaxNumber >= MaxNumber
|
|
&& BusyThreshold is > 0 and <= 1
|
|
&& ChallengeLifetime > TimeSpan.Zero;
|
|
}
|