2019-08-14 18:52:21 +00:00
|
|
|
/// A representation of the abstract "rate-limiting window" in which
|
|
|
|
/// a [user] is accessing some API or endpoint.
|
|
|
|
class RateLimitingWindow<User> {
|
|
|
|
/// The user who is accessing the endpoint.
|
2019-08-14 19:56:35 +00:00
|
|
|
User user;
|
2019-08-14 18:52:21 +00:00
|
|
|
|
|
|
|
/// The time at which the user's current window began.
|
2019-08-14 19:56:35 +00:00
|
|
|
DateTime startTime;
|
2019-08-14 18:52:21 +00:00
|
|
|
|
2019-08-14 19:17:20 +00:00
|
|
|
/// The number of points the user has already consumed within
|
2019-08-14 18:52:21 +00:00
|
|
|
/// the current window.
|
2019-08-14 19:56:35 +00:00
|
|
|
int pointsConsumed;
|
2019-08-14 18:52:21 +00:00
|
|
|
|
2019-08-14 19:14:47 +00:00
|
|
|
/// The maximum amount of points allowed within a single window.
|
2019-08-14 19:38:09 +00:00
|
|
|
///
|
|
|
|
/// This field is typically only set by the [RateLimiter] middleware,
|
|
|
|
/// and is therefore optional in the constructor.
|
2019-08-14 19:56:35 +00:00
|
|
|
int pointLimit;
|
2019-08-14 19:14:47 +00:00
|
|
|
|
|
|
|
/// The amount of points the user can consume before hitting the
|
|
|
|
/// rate limit for the current window.
|
2019-08-14 19:38:09 +00:00
|
|
|
///
|
|
|
|
/// This field is typically only set by the [RateLimiter] middleware,
|
|
|
|
/// and is therefore optional in the constructor.
|
2019-08-14 19:56:35 +00:00
|
|
|
int remainingPoints;
|
2019-08-14 19:14:47 +00:00
|
|
|
|
|
|
|
/// The time at which the window will reset.
|
2019-08-14 19:38:09 +00:00
|
|
|
///
|
|
|
|
/// This field is typically only set by the [RateLimiter] middleware,
|
|
|
|
/// and is therefore optional in the constructor.
|
2019-08-14 19:56:35 +00:00
|
|
|
DateTime resetTime;
|
2019-08-14 19:14:47 +00:00
|
|
|
|
2019-08-14 19:56:35 +00:00
|
|
|
RateLimitingWindow(this.user, this.startTime, this.pointsConsumed,
|
|
|
|
{this.pointLimit, this.remainingPoints, this.resetTime});
|
2019-08-14 18:52:21 +00:00
|
|
|
}
|