diff options
| author | bndw <ben@bdw.to> | 2026-02-14 08:58:57 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-14 08:58:57 -0800 |
| commit | f0169fa1f9d2e2a5d1c292b9080da10ef0878953 (patch) | |
| tree | c85d31dfbf270fe4ebbe2c53bdbb96c0a0a45ace /internal/nostr/event.go | |
| parent | 44aa0591b0eed7851e961ea17bd1c9601570ac24 (diff) | |
feat: implement per-user rate limiting with token bucket algorithm
Add comprehensive rate limiting package that works seamlessly with
NIP-98 authentication.
Features:
- Token bucket algorithm (allows bursts, smooth average rate)
- Per-pubkey limits for authenticated users
- Per-IP limits for unauthenticated users (fallback)
- Method-specific overrides (e.g., stricter for PublishEvent)
- Per-user custom limits (VIP/admin tiers)
- Standard gRPC interceptors (chain after auth)
- Automatic cleanup of idle limiters
- Statistics tracking (allowed/denied/denial rate)
Configuration options:
- Default rate limits and burst sizes
- Method-specific overrides
- User-specific overrides (with method overrides)
- Skip methods (health checks, public endpoints)
- Skip users (admins, monitoring)
- Configurable cleanup intervals
Performance:
- In-memory (200 bytes per user)
- O(1) lookups with sync.RWMutex
- ~85ns per rate limit check
- Periodic cleanup to free memory
Returns gRPC ResourceExhausted (HTTP 429) when limits exceeded.
Includes comprehensive tests, benchmarks, and detailed README with
usage examples, configuration reference, and security considerations.
Diffstat (limited to 'internal/nostr/event.go')
0 files changed, 0 insertions, 0 deletions
