diff options
author | 2023-08-23 14:32:27 +0200 | |
---|---|---|
committer | 2023-08-23 14:32:27 +0200 | |
commit | 8f38dc2e7f9dc7272c6882fff369be5e43dc711a (patch) | |
tree | 4b414789c96c05573f89ae3f23b4bd1c5870005e /internal/config | |
parent | [performance] Rework home timeline query to use cache more (#2148) (diff) | |
download | gotosocial-8f38dc2e7f9dc7272c6882fff369be5e43dc711a.tar.xz |
[feature] Add rate limit exceptions option, use ISO8601 for rate limit reset (#2151)
* start updating rate limiting, add exceptions
* tests, comments, tidying up
* add rate limiting exceptions to example config
* envparsing
* nolint
* apply kimbediff
* add examples
Diffstat (limited to 'internal/config')
-rw-r--r-- | internal/config/config.go | 1 | ||||
-rw-r--r-- | internal/config/defaults.go | 3 | ||||
-rw-r--r-- | internal/config/flags.go | 1 | ||||
-rw-r--r-- | internal/config/helpers.gen.go | 25 |
4 files changed, 29 insertions, 1 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 86f6b00dd..612947c5e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -148,6 +148,7 @@ type Configuration struct { AdvancedCookiesSamesite string `name:"advanced-cookies-samesite" usage:"'strict' or 'lax', see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite"` AdvancedRateLimitRequests int `name:"advanced-rate-limit-requests" usage:"Amount of HTTP requests to permit within a 5 minute window. 0 or less turns rate limiting off."` + AdvancedRateLimitExceptions []string `name:"advanced-rate-limit-exceptions" usage:"Slice of CIDRs to exclude from rate limit restrictions."` AdvancedThrottlingMultiplier int `name:"advanced-throttling-multiplier" usage:"Multiplier to use per cpu for http request throttling. 0 or less turns throttling off."` AdvancedThrottlingRetryAfter time.Duration `name:"advanced-throttling-retry-after" usage:"Retry-After duration response to send for throttled requests."` AdvancedSenderMultiplier int `name:"advanced-sender-multiplier" usage:"Multiplier to use per cpu for batching outgoing fedi messages. 0 or less turns batching off (not recommended)."` diff --git a/internal/config/defaults.go b/internal/config/defaults.go index 3703d8372..9ad9c125c 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -122,7 +122,8 @@ var Defaults = Configuration{ AdvancedCookiesSamesite: "lax", AdvancedRateLimitRequests: 300, // 1 per second per 5 minutes - AdvancedThrottlingMultiplier: 8, // 8 open requests per CPU + AdvancedRateLimitExceptions: []string{}, + AdvancedThrottlingMultiplier: 8, // 8 open requests per CPU AdvancedThrottlingRetryAfter: time.Second * 30, AdvancedSenderMultiplier: 2, // 2 senders per CPU AdvancedCSPExtraURIs: []string{}, diff --git a/internal/config/flags.go b/internal/config/flags.go index 927f4ddfb..ad07ec2ef 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -149,6 +149,7 @@ func (s *ConfigState) AddServerFlags(cmd *cobra.Command) { // Advanced flags cmd.Flags().String(AdvancedCookiesSamesiteFlag(), cfg.AdvancedCookiesSamesite, fieldtag("AdvancedCookiesSamesite", "usage")) cmd.Flags().Int(AdvancedRateLimitRequestsFlag(), cfg.AdvancedRateLimitRequests, fieldtag("AdvancedRateLimitRequests", "usage")) + cmd.Flags().StringSlice(AdvancedRateLimitExceptionsFlag(), cfg.AdvancedRateLimitExceptions, fieldtag("AdvancedRateLimitExceptions", "usage")) cmd.Flags().Int(AdvancedThrottlingMultiplierFlag(), cfg.AdvancedThrottlingMultiplier, fieldtag("AdvancedThrottlingMultiplier", "usage")) cmd.Flags().Duration(AdvancedThrottlingRetryAfterFlag(), cfg.AdvancedThrottlingRetryAfter, fieldtag("AdvancedThrottlingRetryAfter", "usage")) cmd.Flags().Int(AdvancedSenderMultiplierFlag(), cfg.AdvancedSenderMultiplier, fieldtag("AdvancedSenderMultiplier", "usage")) diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index ab7d38a8a..801d4f667 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -2274,6 +2274,31 @@ func GetAdvancedRateLimitRequests() int { return global.GetAdvancedRateLimitRequ // SetAdvancedRateLimitRequests safely sets the value for global configuration 'AdvancedRateLimitRequests' field func SetAdvancedRateLimitRequests(v int) { global.SetAdvancedRateLimitRequests(v) } +// GetAdvancedRateLimitExceptions safely fetches the Configuration value for state's 'AdvancedRateLimitExceptions' field +func (st *ConfigState) GetAdvancedRateLimitExceptions() (v []string) { + st.mutex.RLock() + v = st.config.AdvancedRateLimitExceptions + st.mutex.RUnlock() + return +} + +// SetAdvancedRateLimitExceptions safely sets the Configuration value for state's 'AdvancedRateLimitExceptions' field +func (st *ConfigState) SetAdvancedRateLimitExceptions(v []string) { + st.mutex.Lock() + defer st.mutex.Unlock() + st.config.AdvancedRateLimitExceptions = v + st.reloadToViper() +} + +// AdvancedRateLimitExceptionsFlag returns the flag name for the 'AdvancedRateLimitExceptions' field +func AdvancedRateLimitExceptionsFlag() string { return "advanced-rate-limit-exceptions" } + +// GetAdvancedRateLimitExceptions safely fetches the value for global configuration 'AdvancedRateLimitExceptions' field +func GetAdvancedRateLimitExceptions() []string { return global.GetAdvancedRateLimitExceptions() } + +// SetAdvancedRateLimitExceptions safely sets the value for global configuration 'AdvancedRateLimitExceptions' field +func SetAdvancedRateLimitExceptions(v []string) { global.SetAdvancedRateLimitExceptions(v) } + // GetAdvancedThrottlingMultiplier safely fetches the Configuration value for state's 'AdvancedThrottlingMultiplier' field func (st *ConfigState) GetAdvancedThrottlingMultiplier() (v int) { st.mutex.RLock() |