diff --git a/packages/at_server_spec/CHANGELOG.md b/packages/at_server_spec/CHANGELOG.md index d6a3f02ae..cd7e06452 100644 --- a/packages/at_server_spec/CHANGELOG.md +++ b/packages/at_server_spec/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.0.15 +- feat: Introduce AtRateLimiter to limit the requests based on the criteria defined +- fix: Modify InboundConnection to implement AtRateLimiter to limit requests ## 3.0.14 - fix: Rename TOTP to OTP ## 3.0.13 diff --git a/packages/at_server_spec/lib/src/at_rate_limiter/at_rate_limiter.dart b/packages/at_server_spec/lib/src/at_rate_limiter/at_rate_limiter.dart new file mode 100644 index 000000000..bd2a3d4f3 --- /dev/null +++ b/packages/at_server_spec/lib/src/at_rate_limiter/at_rate_limiter.dart @@ -0,0 +1,18 @@ +/// A rate limiter class that allows controlling the rate of requests within a specified time frame. +/// +/// This class provides a way to limit the number of requests that can be made +/// within a specified time frame. It keeps track of the timestamps of previous +/// requests and allows requests to be made only if they do not exceed the +/// maximum allowed requests per time frame. +abstract class AtRateLimiter { + /// The maximum number of requests allowed within the specified time frame. + late int maxRequestsPerTimeFrame; + + /// The duration of the time frame within which requests are limited. + late int timeFrameInMillis; + + /// Checks whether a new request is allowed based on the rate limiting rules. + /// + /// Returns `true` if the request is allowed, or `false` if it exceeds the rate limit. + bool isRequestAllowed(); +} diff --git a/packages/at_server_spec/lib/src/connection/inbound_connection.dart b/packages/at_server_spec/lib/src/connection/inbound_connection.dart index c4851ab47..bab07d14b 100644 --- a/packages/at_server_spec/lib/src/connection/inbound_connection.dart +++ b/packages/at_server_spec/lib/src/connection/inbound_connection.dart @@ -1,7 +1,8 @@ import 'dart:io'; +import 'package:at_server_spec/src/at_rate_limiter/at_rate_limiter.dart'; import 'package:at_server_spec/src/connection/at_connection.dart'; -abstract class InboundConnection extends AtConnection { +abstract class InboundConnection extends AtConnection implements AtRateLimiter { ///Returns true if remote socket and remote port of this and connection matches bool equals(InboundConnection connection); diff --git a/packages/at_server_spec/pubspec.yaml b/packages/at_server_spec/pubspec.yaml index 9a327f72d..0812c17ab 100644 --- a/packages/at_server_spec/pubspec.yaml +++ b/packages/at_server_spec/pubspec.yaml @@ -1,6 +1,6 @@ name: at_server_spec description: A Dart library containing abstract classes that defines what implementations of the root and secondary servers are responsible for. -version: 3.0.14 +version: 3.0.15 repository: https://github.com/atsign-foundation/at_server homepage: https://docs.atsign.com documentation: https://docs.atsign.com/atplatform/secondaryserver @@ -10,7 +10,7 @@ environment: dependencies: meta: ^1.8.0 - at_commons: ^3.0.54 + at_commons: ^3.0.55 dev_dependencies: lints: ^1.0.1