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 {