khatru: replace useless ApplySaneDefaults() with a set of pluggable "strict" defaults.

This commit is contained in:
fiatjaf
2025-08-28 17:18:22 -03:00
parent 43d6814daf
commit 7ac9e6290b
4 changed files with 44 additions and 23 deletions
+10 -2
View File
@@ -14,7 +14,7 @@ func EventIPRateLimiter(tokensPerInterval int, interval time.Duration, maxTokens
return func(ctx context.Context, _ nostr.Event) (reject bool, msg string) {
ip := khatru.GetIP(ctx)
if ip == "" {
if ip == "127.0.0.1" {
return false, ""
}
return rl(ip), "rate-limited: slow down, please"
@@ -25,6 +25,10 @@ func EventPubKeyRateLimiter(tokensPerInterval int, interval time.Duration, maxTo
rl := startRateLimitSystem[string](tokensPerInterval, interval, maxTokens)
return func(ctx context.Context, evt nostr.Event) (reject bool, msg string) {
ip := khatru.GetIP(ctx)
if ip == "127.0.0.1" {
return false, ""
}
return rl(evt.PubKey.Hex()), "rate-limited: slow down, please"
}
}
@@ -45,6 +49,10 @@ func FilterIPRateLimiter(tokensPerInterval int, interval time.Duration, maxToken
rl := startRateLimitSystem[string](tokensPerInterval, interval, maxTokens)
return func(ctx context.Context, _ nostr.Filter) (reject bool, msg string) {
return rl(khatru.GetIP(ctx)), "rate-limited: there is a bug in the client, no one should be making so many requests"
ip := khatru.GetIP(ctx)
if ip == "127.0.0.1" {
return false, ""
}
return rl(ip), "rate-limited: there is a bug in the client, no one should be making so many requests"
}
}