mirror of
https://github.com/Cameri/nostream.git
synced 2025-03-17 21:31:48 +01:00
chore: simplify msg rate limiting
This commit is contained in:
parent
845dedc451
commit
8e5646d272
@ -188,14 +188,19 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
|
||||
{ period: period, rate: rate },
|
||||
)
|
||||
|
||||
const hits = await Promise.all(
|
||||
rateLimits
|
||||
.map(({ period, rate }) => hit(period, rate))
|
||||
)
|
||||
|
||||
debug('rate limit check %s: %o = %o', client, rateLimits.map(({ period }) => period), hits)
|
||||
for (const { rate, period } of rateLimits) {
|
||||
const isRateLimited = await hit(period, rate)
|
||||
|
||||
return hits.some((thresholdCrossed) => thresholdCrossed)
|
||||
|
||||
if (isRateLimited) {
|
||||
debug('rate limited %s: %d messages / %d ms exceeded', client, rate, period)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private onClientPong() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user