Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement AtRateLimiter spec changes #1548

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/at_server_spec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
4 changes: 2 additions & 2 deletions packages/at_server_spec/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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