5#include "CoreMinimal.h"
156 int32 MoveCurrentBucket(
const FDateTime& Now);
static constexpr float AllowXPercentOfTripWireMaxForMovingAverage
Moving-average threshold expressed as a fraction of the tripwire maximum.
Definition LootLockerRateLimiter.h:51
int32 GetSecondsLeftOfRateLimit() const
Returns the approximate number of seconds until the rate limit clears.
bool bEnableRateLimiter
When false, AddRequestAndCheckIfRateLimitHit() always returns false.
Definition LootLockerRateLimiter.h:121
static constexpr int32 TripWireTimeFrameSeconds
Length of the tripwire measurement window in seconds.
Definition LootLockerRateLimiter.h:38
static constexpr int32 CountMovingAverageAcrossNTripWireTimeFrames
Number of tripwire time frames covered by the moving-average window.
Definition LootLockerRateLimiter.h:54
static constexpr int32 BucketsPerTimeFrame
Number of buckets that span one tripwire time frame (= 60 / 5 = 12).
Definition LootLockerRateLimiter.h:61
int32 TotalRequestsInBucketsInTripWireTimeFrame
Running total of requests in the buckets that fall within the current tripwire time frame.
Definition LootLockerRateLimiter.h:142
bool bIsRateLimited
True while requests are being rejected due to an active rate limit.
Definition LootLockerRateLimiter.h:145
bool bFirstRequestSent
Set to true once the first request has been processed.
Definition LootLockerRateLimiter.h:127
static constexpr int32 RateLimitMovingAverageBucketCount
Total number of buckets in the circular array (= 3 * 12 = 36).
Definition LootLockerRateLimiter.h:64
void Reset()
Resets all rate-limiting state to its initial values.
FDateTime RateLimitResolvesAt
Wall-clock time at which the current rate limit is expected to clear.
Definition LootLockerRateLimiter.h:148
static constexpr int32 SecondsPerBucket
Duration of each bucket in seconds.
Definition LootLockerRateLimiter.h:44
FDateTime LastBucketChangeTime
Wall-clock time at which the current bucket became active.
Definition LootLockerRateLimiter.h:136
static constexpr int32 MaxRequestsPerTripWireTimeFrame
Maximum requests allowed within a single TripWireTimeFrameSeconds window.
Definition LootLockerRateLimiter.h:41
virtual ~FLootLockerRateLimiter()=default
static constexpr int32 MaxRequestsPerBucketOnMovingAverage
Per-bucket average that triggers the moving-average rate limit.
Definition LootLockerRateLimiter.h:70
int32 TotalRequestsInBuckets
Running total of all requests across every bucket in the array.
Definition LootLockerRateLimiter.h:139
int32 LastBucket
Index of the most-recently-written bucket (-1 = not yet started).
Definition LootLockerRateLimiter.h:133
virtual bool AddRequestAndCheckIfRateLimitHit()
Records one outgoing request and returns whether the rate limit is currently active.
virtual FDateTime GetTimeNow() const
Returns the current wall-clock time used for bucket advancement.
int32 Buckets[RateLimitMovingAverageBucketCount]
Circular array of per-bucket request counts.
Definition LootLockerRateLimiter.h:130