From 6d827ac89ae68466f88205f347822ff6db8a7edf Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 11 Sep 2024 23:02:01 -0300 Subject: [PATCH] return blank IP and do not rate-limit when calling AddEvent(). --- policies/ratelimits.go | 6 +++++- utils.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/policies/ratelimits.go b/policies/ratelimits.go index 6a78e7c..9f9c497 100644 --- a/policies/ratelimits.go +++ b/policies/ratelimits.go @@ -13,7 +13,11 @@ func EventIPRateLimiter(tokensPerInterval int, interval time.Duration, maxTokens rl := startRateLimitSystem[string](tokensPerInterval, interval, maxTokens) return func(ctx context.Context, _ *nostr.Event) (reject bool, msg string) { - return rl(khatru.GetIP(ctx)), "rate-limited: slow down, please" + ip := khatru.GetIP(ctx) + if ip == "" { + return false, "" + } + return rl(ip), "rate-limited: slow down, please" } } diff --git a/utils.go b/utils.go index 4060764..4745cd1 100644 --- a/utils.go +++ b/utils.go @@ -41,7 +41,12 @@ func GetAuthed(ctx context.Context) string { } func GetIP(ctx context.Context) string { - return GetIPFromRequest(GetConnection(ctx).Request) + conn := GetConnection(ctx) + if conn == nil { + return "" + } + + return GetIPFromRequest(conn.Request) } func GetSubscriptionID(ctx context.Context) string {