Use points instead of request count

This commit is contained in:
Tobe O 2019-08-14 15:17:02 -04:00
parent 71f2c748f1
commit a202b189be

View file

@ -10,14 +10,15 @@ import 'rate_limiting_window.dart';
/// can be computed from each request, as well as information about /// can be computed from each request, as well as information about
/// the current rate-limiting window. /// the current rate-limiting window.
abstract class RateLimiter<User> { abstract class RateLimiter<User> {
/// The maximum number of requests allowed within the given [window]. /// The maximum number of points that may be consumed
final int maxRequestsPerWindow; /// within the given [windowDuration].
final int maxPointsPerWindow;
/// The amount of time, during which, a user is not allowed to send /// The amount of time, during which, a user is not allowed to consume
/// more than [maxRequestsPerWindow]. /// more than [maxPointsPerWindow].
final Duration window; final Duration windowDuration;
RateLimiter(this.maxRequestsPerWindow, this.window); RateLimiter(this.maxPointsPerWindow, this.windowDuration);
/// Computes the current window in which the user is acting. /// Computes the current window in which the user is acting.
/// ///
@ -27,12 +28,11 @@ abstract class RateLimiter<User> {
FutureOr<RateLimitingWindow<User>> getCurrentWindow( FutureOr<RateLimitingWindow<User>> getCurrentWindow(
RequestContext req, ResponseContext res); RequestContext req, ResponseContext res);
/// Updates the underlying store with information about the /// Updates the underlying store with information about the new
/// [newWindow] that the user is operating in. /// [window] that the user is operating in.
FutureOr<void> updateCurrentWindow(RequestContext req, ResponseContext res, FutureOr<void> updateCurrentWindow(RequestContext req, ResponseContext res,
RateLimitingWindow<User> newWindow); RateLimitingWindow<User> window);
FutureOr<Object> denyRequest(RequestContext req, ResponseContext res) { FutureOr<Object> denyRequest(RequestContext req, ResponseContext res,
RateLimitingWindow<User> window) {}
}
} }