mirror of
https://github.com/Cameri/nostream.git
synced 2025-06-21 14:10:48 +02: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 type EventKindsRange = [EventKinds, EventKinds]
|
||||||
|
|
||||||
|
export interface EventRateLimit {
|
||||||
|
kinds?: (EventKinds | [EventKinds, EventKinds])[]
|
||||||
|
rate: number
|
||||||
|
period: number
|
||||||
|
}
|
||||||
|
|
||||||
export interface KindLimits {
|
export interface KindLimits {
|
||||||
whitelist?: (EventKinds | EventKindsRange)[]
|
whitelist?: (EventKinds | EventKindsRange)[]
|
||||||
blacklist?: (EventKinds | EventKindsRange)[]
|
blacklist?: (EventKinds | EventKindsRange)[]
|
||||||
@ -42,6 +48,7 @@ export interface EventLimits {
|
|||||||
pubkey?: PubkeyLimits
|
pubkey?: PubkeyLimits
|
||||||
kind?: KindLimits
|
kind?: KindLimits
|
||||||
createdAt?: CreatedAtLimits
|
createdAt?: CreatedAtLimits
|
||||||
|
rateLimits?: EventRateLimit[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientSubscriptionLimits {
|
export interface ClientSubscriptionLimits {
|
||||||
@ -53,9 +60,20 @@ export interface ClientLimits {
|
|||||||
subscription?: ClientSubscriptionLimits
|
subscription?: ClientSubscriptionLimits
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MessageRateLimit {
|
||||||
|
rate: number
|
||||||
|
period: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MessageLimits {
|
||||||
|
rateLimits?: MessageRateLimit[]
|
||||||
|
ipWhitelist?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface Limits {
|
export interface Limits {
|
||||||
client?: ClientLimits
|
client?: ClientLimits
|
||||||
event?: EventLimits
|
event?: EventLimits
|
||||||
|
message?: MessageLimits
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Worker {
|
export interface Worker {
|
||||||
|
@ -4,10 +4,12 @@ import { join } from 'path'
|
|||||||
import { mergeDeepRight } from 'ramda'
|
import { mergeDeepRight } from 'ramda'
|
||||||
|
|
||||||
import { createLogger } from '../factories/logger-factory'
|
import { createLogger } from '../factories/logger-factory'
|
||||||
|
import { EventKinds } from '../constants/base'
|
||||||
import { ISettings } from '../@types/settings'
|
import { ISettings } from '../@types/settings'
|
||||||
import packageJson from '../../package.json'
|
import packageJson from '../../package.json'
|
||||||
|
|
||||||
const debug = createLogger('settings')
|
const debug = createLogger('settings')
|
||||||
|
|
||||||
export class SettingsStatic {
|
export class SettingsStatic {
|
||||||
static _settings: ISettings
|
static _settings: ISettings
|
||||||
|
|
||||||
@ -48,6 +50,26 @@ export class SettingsStatic {
|
|||||||
maxPositiveDelta: 900,
|
maxPositiveDelta: 900,
|
||||||
maxNegativeDelta: 0, // disabled
|
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: {
|
client: {
|
||||||
subscription: {
|
subscription: {
|
||||||
@ -55,6 +77,26 @@ export class SettingsStatic {
|
|||||||
maxFilters: 10,
|
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,
|
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