2019-12-26 13:41:38 +00:00
|
|
|
# Basic request ratelimit system
|
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
2020-09-14 21:13:15 +00:00
|
|
|
This core extension is intended to limit the number of requests from clients per unit of time.
|
2019-12-26 13:41:38 +00:00
|
|
|
|
|
|
|
## Message type identifiers
|
|
|
|
|
|
|
|
None.
|
|
|
|
|
|
|
|
## Use cases
|
|
|
|
|
|
|
|
- Client:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"id": "abcd",
|
|
|
|
"type": "profile:register",
|
|
|
|
"to": "cadmium.org",
|
|
|
|
"payload": {
|
|
|
|
"username": "spam_spam_spam",
|
|
|
|
"thirdPIDs": [],
|
|
|
|
"password": "spam"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- Server:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"id": "abcd",
|
|
|
|
"type": "profile:register",
|
|
|
|
"from": "cadmium.org",
|
|
|
|
"ok": false,
|
|
|
|
"payload": {
|
2020-07-16 08:04:56 +00:00
|
|
|
"errID": "ratelimit_exceed",
|
2019-12-26 13:41:38 +00:00
|
|
|
"errText": "Request ratelimit exceed! Please, try again later!",
|
|
|
|
"errPayload": {
|
2020-07-16 08:04:56 +00:00
|
|
|
"retryAfter": 1000
|
2019-12-26 13:41:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-12-26 14:39:19 +00:00
|
|
|
## Errors
|
2019-12-26 13:41:38 +00:00
|
|
|
|
2019-12-26 14:39:19 +00:00
|
|
|
### Global errors
|
2019-12-26 13:41:38 +00:00
|
|
|
|
|
|
|
- `ratelimit_exceed`
|
|
|
|
|
|
|
|
## Business Rules
|
|
|
|
|
|
|
|
- Server MUST count number of requests per unit of time and drop new requests after specified number of made requests with Protocol Error message.
|
|
|
|
- Number of requests and used unit of time SHOULD be configurable on server
|
|
|
|
|
|
|
|
## JSON Schema
|
|
|
|
|
|
|
|
### Error payload
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
interface RatelimitExceedErrorPayload {
|
|
|
|
/**
|
2020-07-16 08:04:56 +00:00
|
|
|
* How long after the client can retry the request (in millis)
|
2019-12-26 13:41:38 +00:00
|
|
|
*/
|
|
|
|
retryAfter: number
|
|
|
|
}
|
|
|
|
```
|