return blank IP and do not rate-limit when calling AddEvent().

This commit is contained in:
fiatjaf 2024-09-11 23:02:01 -03:00
parent b8bb58f77c
commit 6d827ac89a
2 changed files with 11 additions and 2 deletions

@ -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"
}
}

@ -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 {