mirror of
https://github.com/Cameri/nostream.git
synced 2025-03-18 05:41:49 +01:00
feat: add msg/event rate limit to settings
This commit is contained in:
parent
59c6f806cb
commit
a46fcc64ce
@ -21,6 +21,12 @@ export interface PubkeyLimits {
|
||||
|
||||
export type EventKindsRange = [EventKinds, EventKinds]
|
||||
|
||||
export interface EventRateLimit {
|
||||
kinds?: (EventKinds | [EventKinds, EventKinds])[]
|
||||
rate: number
|
||||
period: number
|
||||
}
|
||||
|
||||
export interface KindLimits {
|
||||
whitelist?: (EventKinds | EventKindsRange)[]
|
||||
blacklist?: (EventKinds | EventKindsRange)[]
|
||||
@ -42,6 +48,7 @@ export interface EventLimits {
|
||||
pubkey?: PubkeyLimits
|
||||
kind?: KindLimits
|
||||
createdAt?: CreatedAtLimits
|
||||
rateLimits?: EventRateLimit[]
|
||||
}
|
||||
|
||||
export interface ClientSubscriptionLimits {
|
||||
@ -53,9 +60,20 @@ export interface ClientLimits {
|
||||
subscription?: ClientSubscriptionLimits
|
||||
}
|
||||
|
||||
export interface MessageRateLimit {
|
||||
rate: number
|
||||
period: number
|
||||
}
|
||||
|
||||
export interface MessageLimits {
|
||||
rateLimits?: MessageRateLimit[]
|
||||
ipWhitelist?: string[]
|
||||
}
|
||||
|
||||
export interface Limits {
|
||||
client?: ClientLimits
|
||||
event?: EventLimits
|
||||
message?: MessageLimits
|
||||
}
|
||||
|
||||
export interface Worker {
|
||||
|
@ -4,10 +4,12 @@ import { join } from 'path'
|
||||
import { mergeDeepRight } from 'ramda'
|
||||
|
||||
import { createLogger } from '../factories/logger-factory'
|
||||
import { EventKinds } from '../constants/base'
|
||||
import { ISettings } from '../@types/settings'
|
||||
import packageJson from '../../package.json'
|
||||
|
||||
const debug = createLogger('settings')
|
||||
|
||||
export class SettingsStatic {
|
||||
static _settings: ISettings
|
||||
|
||||
@ -48,6 +50,26 @@ export class SettingsStatic {
|
||||
maxPositiveDelta: 900,
|
||||
maxNegativeDelta: 0, // disabled
|
||||
},
|
||||
rateLimits: [
|
||||
{
|
||||
kinds: [EventKinds.TEXT_NOTE],
|
||||
period: 60000,
|
||||
rate: 60,
|
||||
},
|
||||
{
|
||||
kinds: [[EventKinds.EPHEMERAL_FIRST, EventKinds.EPHEMERAL_LAST]],
|
||||
period: 60000,
|
||||
rate: 240,
|
||||
},
|
||||
{
|
||||
period: 3600000,
|
||||
rate: 3600,
|
||||
},
|
||||
{
|
||||
period: 86400000,
|
||||
rate: 86400,
|
||||
},
|
||||
],
|
||||
},
|
||||
client: {
|
||||
subscription: {
|
||||
@ -55,6 +77,26 @@ export class SettingsStatic {
|
||||
maxFilters: 10,
|
||||
},
|
||||
},
|
||||
message: {
|
||||
rateLimits: [
|
||||
{
|
||||
period: 60000, // minute
|
||||
rate: 240,
|
||||
},
|
||||
{
|
||||
period: 3600000, // hour
|
||||
rate: 3600,
|
||||
},
|
||||
{
|
||||
period: 86400000, // day
|
||||
rate: 86400,
|
||||
},
|
||||
],
|
||||
ipWhitelist: [
|
||||
'::1', // local host
|
||||
'::ffff:10.10.10.1', // host running docker
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,15 @@ describe('SettingsStatic', () => {
|
||||
maxFilters: 10,
|
||||
},
|
||||
},
|
||||
message: {
|
||||
dailyRate: 86400,
|
||||
hourlyRate: 3600,
|
||||
minutelyRate: 240,
|
||||
ipWhitelist: [
|
||||
'::1',
|
||||
'::ffff:10.10.10.1',
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user