mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
Rate limit Socket IO communication - WIP (#4036)
Includes settings Includes i18n Includes a nice notification Disconnects on rate limit Includes feeding into metrics/stats Include console warn to server console.
This commit is contained in:
parent
4f5cf2dc63
commit
40014d8230
11 changed files with 75 additions and 8 deletions
|
@ -37,6 +37,12 @@ var channels = require("channels");
|
|||
var stats = require('../stats');
|
||||
var remoteAddress = require("../utils/RemoteAddress").remoteAddress;
|
||||
const nodeify = require("nodeify");
|
||||
const { RateLimiterMemory } = require('rate-limiter-flexible');
|
||||
|
||||
const rateLimiter = new RateLimiterMemory({
|
||||
points: settings.commitRateLimiting.points,
|
||||
duration: settings.commitRateLimiting.duration
|
||||
});
|
||||
|
||||
/**
|
||||
* A associative array that saves informations about a session
|
||||
|
@ -164,6 +170,19 @@ exports.handleDisconnect = async function(client)
|
|||
*/
|
||||
exports.handleMessage = async function(client, message)
|
||||
{
|
||||
var env = process.env.NODE_ENV || 'development';
|
||||
|
||||
if (env === 'production') {
|
||||
try {
|
||||
await rateLimiter.consume(client.handshake.address); // consume 1 point per event from IP
|
||||
}catch(e){
|
||||
console.warn("Rate limited: ", client.handshake.address, " to reduce the amount of rate limiting that happens edit the rateLimit values in settings.json");
|
||||
stats.meter('rateLimited').mark();
|
||||
client.json.send({disconnect:"rateLimited"});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue