carlos / platform Public

edge: in-memory probe-burst limiter

60 not-founds on one app inside 60 s start a 10-minute box-wide cool-down
for that client. Counters are fixed rings of the last 60 timestamps, a
cooling client is not counted, and counters (100,000) and cool-downs
(50,000) are capped with oldest-first, counted eviction.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev e0b13a3ebb8342f62db6606ca9d7c2930eda1f47 parent 2c058d8
2 files changed, +651 −0
  • internal/edge/burst.go +262 −0
  • internal/edge/burst_test.go +389 −0
diff --git a/internal/edge/burst.go b/internal/edge/burst.go
new file mode 100644
index 000000000..644ce12f1
--- /dev/null
+++ b/internal/edge/burst.go
@@ -0,0 +1,262 @@
+package edge
+
+import (
+ "container/list"
+ "net/netip"
+ "sync"
+ "time"
+)
+
+// The probe-burst limiter. A client that collects burstThreshold not-found
+// answers on one app inside burstWindow is put in a cool-down that covers
+// every app on the box. This file is only the bookkeeping: serving decides
+// what counts and what a cool-down refuses.
+//
+// Memory does not depend on request volume. A counter is the last 60
+// timestamps for one (app, client) and never grows past that. A client that
+// is already cooling is not counted at all. The number of counters and of
+// cool-downs is capped, and at a cap the entry that was touched longest ago
+// goes first, so a scan of many addresses costs a fixed amount of memory
+// and shows up in stats instead of in the heap.
+const (
+ burstThreshold = 60
+ burstWindow = 60 * time.Second
+ burstCooldown = 10 * time.Minute
+)
+
+// These are vars only so a test can lower them.
+var (
+ burstMaxCounters = 100_000
+ burstMaxCooldowns = 50_000
+)
+
+// burstStats counts the entries the caps pushed out while still live.
+// Expired entries dropped on the way do not count.
+type burstStats struct {
+ CountersEvicted int64
+ CooldownsEvicted int64
+}
+
+// burstCounter holds the last burstThreshold not-found times (unix nanos) for
+// one app and client. It grows by append until it is full, then becomes a
+// ring: head is the oldest entry and the next one to be overwritten. Most
+// clients never see more than a few not-founds, so most counters stay small.
+type burstCounter struct {
+ app string
+ client netip.Prefix
+ ts []int64
+ head int
+ elem *list.Element
+}
+
+func (c *burstCounter) newest() int64 {
+ return c.ts[(c.head+len(c.ts)-1)%len(c.ts)]
+}
+
+// burstCool is one client's cool-down. from is the app that tripped it on
+// this box, or "" when a notice from another edge started it.
+type burstCool struct {
+ client netip.Prefix
+ until time.Time
+ from string
+ elem *list.Element
+}
+
+type burstLimiter struct {
+ now func() time.Time
+
+ mu sync.Mutex
+ // counters is nested by client so a trip can drop all of one client's
+ // counters without scanning. counterLRU holds the same counters, most
+ // recently noted at the front.
+ counters map[netip.Prefix]map[string]*list.Element
+ counterLRU *list.List
+ // cooldowns is ordered oldest-first; extending one moves it to the back.
+ cooldowns map[netip.Prefix]*list.Element
+ cooldownList *list.List
+ st burstStats
+}
+
+func newBurstLimiter(now func() time.Time) *burstLimiter {
+ if now == nil {
+ now = time.Now
+ }
+ return &burstLimiter{
+ now: now,
+ counters: make(map[netip.Prefix]map[string]*list.Element),
+ counterLRU: list.New(),
+ cooldowns: make(map[netip.Prefix]*list.Element),
+ cooldownList: list.New(),
+ }
+}
+
+// note records one not-found for app and client and reports whether it was
+// the one that tripped a cool-down. A client already cooling is not counted.
+func (b *burstLimiter) note(app string, client netip.Prefix) (tripped bool, until time.Time) {
+ now := b.now()
+ n := now.UnixNano()
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ if _, ok := b.liveCooldown(client, now); ok {
+ return false, time.Time{}
+ }
+ c := b.counter(app, client, n)
+ if len(c.ts) < burstThreshold {
+ c.ts = append(c.ts, n)
+ } else {
+ c.ts[c.head] = n
+ c.head = (c.head + 1) % burstThreshold
+ }
+ // A full ring whose oldest entry is still inside the window holds
+ // burstThreshold not-founds within burstWindow.
+ if len(c.ts) < burstThreshold || n-c.ts[c.head] >= int64(burstWindow) {
+ return false, time.Time{}
+ }
+ b.dropClient(client)
+ until = now.Add(burstCooldown)
+ b.setCooldown(client, until, app, now)
+ return true, until
+}
+
+// cooling reports the client's live cool-down. from names the app that
+// tripped it on this box, or is empty for one a notice started.
+func (b *burstLimiter) cooling(client netip.Prefix) (until time.Time, from string, ok bool) {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ cd, ok := b.liveCooldown(client, b.now())
+ if !ok {
+ return time.Time{}, "", false
+ }
+ return cd.until, cd.from, true
+}
+
+// apply starts or extends a cool-down from a notice another edge sent. It
+// refuses an until that is not in the future or is more than burstCooldown
+// ahead, so a notice cannot park a client for longer than a local trip would.
+// An accepted until never shortens a cool-down already running. It reports
+// whether until was within bounds, and never reports a trip: the edge that
+// tripped has already told the others, and they must not tell it back.
+func (b *burstLimiter) apply(client netip.Prefix, until time.Time) bool {
+ now := b.now()
+ if !until.After(now) || until.After(now.Add(burstCooldown)) {
+ return false
+ }
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ b.dropClient(client)
+ if cd, ok := b.liveCooldown(client, now); ok {
+ if until.After(cd.until) {
+ cd.until = until
+ b.cooldownList.MoveToBack(cd.elem)
+ }
+ return true
+ }
+ b.setCooldown(client, until, "", now)
+ return true
+}
+
+func (b *burstLimiter) stats() burstStats {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ return b.st
+}
+
+// liveCooldown returns the client's cool-down if it has not ended, removing
+// it if it has. Caller holds b.mu.
+func (b *burstLimiter) liveCooldown(client netip.Prefix, now time.Time) (*burstCool, bool) {
+ el, ok := b.cooldowns[client]
+ if !ok {
+ return nil, false
+ }
+ cd := el.Value.(*burstCool)
+ if !cd.until.After(now) {
+ b.cooldownList.Remove(el)
+ delete(b.cooldowns, client)
+ return nil, false
+ }
+ return cd, true
+}
+
+// setCooldown adds a cool-down for a client that has none live, making room
+// first: ended cool-downs come off the front for free, and if the cap is
+// still reached the oldest live one is evicted and counted. Caller holds b.mu.
+func (b *burstLimiter) setCooldown(client netip.Prefix, until time.Time, from string, now time.Time) {
+ for el := b.cooldownList.Front(); el != nil; el = b.cooldownList.Front() {
+ cd := el.Value.(*burstCool)
+ if cd.until.After(now) {
+ break
+ }
+ b.cooldownList.Remove(el)
+ delete(b.cooldowns, cd.client)
+ }
+ if old, ok := b.cooldowns[client]; ok {
+ // An ended entry for this client that the front sweep stopped short of.
+ b.cooldownList.Remove(old)
+ delete(b.cooldowns, client)
+ }
+ for b.cooldownList.Len() >= burstMaxCooldowns {
+ el := b.cooldownList.Front()
+ if el == nil {
+ break
+ }
+ b.cooldownList.Remove(el)
+ delete(b.cooldowns, el.Value.(*burstCool).client)
+ b.st.CooldownsEvicted++
+ }
+ cd := &burstCool{client: client, until: until, from: from}
+ cd.elem = b.cooldownList.PushBack(cd)
+ b.cooldowns[client] = cd.elem
+}
+
+// counter finds or makes the counter for app and client and marks it most
+// recently used. Caller holds b.mu.
+func (b *burstLimiter) counter(app string, client netip.Prefix, n int64) *burstCounter {
+ if el, ok := b.counters[client][app]; ok {
+ b.counterLRU.MoveToFront(el)
+ return el.Value.(*burstCounter)
+ }
+ // Counters whose newest entry has left the window can never contribute
+ // to a trip, so they come off the back for free; only past that does the
+ // cap evict a live one.
+ for el := b.counterLRU.Back(); el != nil; el = b.counterLRU.Back() {
+ old := el.Value.(*burstCounter)
+ if n-old.newest() < int64(burstWindow) {
+ break
+ }
+ b.removeCounter(old)
+ }
+ for b.counterLRU.Len() >= burstMaxCounters {
+ el := b.counterLRU.Back()
+ if el == nil {
+ break
+ }
+ b.removeCounter(el.Value.(*burstCounter))
+ b.st.CountersEvicted++
+ }
+ c := &burstCounter{app: app, client: client}
+ c.elem = b.counterLRU.PushFront(c)
+ apps := b.counters[client]
+ if apps == nil {
+ apps = make(map[string]*list.Element, 1)
+ b.counters[client] = apps
+ }
+ apps[app] = c.elem
+ return c
+}
+
+func (b *burstLimiter) removeCounter(c *burstCounter) {
+ b.counterLRU.Remove(c.elem)
+ apps := b.counters[c.client]
+ delete(apps, c.app)
+ if len(apps) == 0 {
+ delete(b.counters, c.client)
+ }
+}
+
+// dropClient forgets every counter a client holds. Caller holds b.mu.
+func (b *burstLimiter) dropClient(client netip.Prefix) {
+ for _, el := range b.counters[client] {
+ b.counterLRU.Remove(el)
+ }
+ delete(b.counters, client)
+}
diff --git a/internal/edge/burst_test.go b/internal/edge/burst_test.go
new file mode 100644
index 000000000..a710f1717
--- /dev/null
+++ b/internal/edge/burst_test.go
@@ -0,0 +1,389 @@
+package edge
+
+import (
+ "net/netip"
+ "sync"
+ "testing"
+ "time"
+)
+
+// burstClock is a hand-driven clock so the window and cool-down are exact.
+type burstClock struct {
+ mu sync.Mutex
+ t time.Time
+}
+
+func newBurstClock() *burstClock {
+ return &burstClock{t: time.Date(2026, 10, 31, 12, 0, 0, 0, time.UTC)}
+}
+
+func (c *burstClock) now() time.Time {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ return c.t
+}
+
+func (c *burstClock) advance(d time.Duration) {
+ c.mu.Lock()
+ c.t = c.t.Add(d)
+ c.mu.Unlock()
+}
+
+func burstTestLimiter() (*burstLimiter, *burstClock) {
+ c := newBurstClock()
+ return newBurstLimiter(c.now), c
+}
+
+var (
+ burstClientA = netip.MustParsePrefix("203.0.113.7/32")
+ burstClientB = netip.MustParsePrefix("2001:db8:1:2::/64")
+)
+
+// lowerBurstCaps shrinks the bounds for one test and restores them after.
+func lowerBurstCaps(t *testing.T, counters, cooldowns int) {
+ t.Helper()
+ oc, od := burstMaxCounters, burstMaxCooldowns
+ burstMaxCounters, burstMaxCooldowns = counters, cooldowns
+ t.Cleanup(func() { burstMaxCounters, burstMaxCooldowns = oc, od })
+}
+
+func TestBurstTripsAt60InAWindow(t *testing.T) {
+ b, c := burstTestLimiter()
+ for i := 1; i <= 59; i++ {
+ if tripped, _ := b.note("bab/shop", burstClientA); tripped {
+ t.Fatalf("note %d tripped; want the 60th", i)
+ }
+ c.advance(500 * time.Millisecond)
+ }
+ tripped, until := b.note("bab/shop", burstClientA)
+ if !tripped {
+ t.Fatal("60th note did not trip")
+ }
+ if want := c.now().Add(burstCooldown); !until.Equal(want) {
+ t.Fatalf("until = %v, want %v", until, want)
+ }
+ if tripped, _ := b.note("bab/shop", burstClientA); tripped {
+ t.Fatal("61st note tripped a second time")
+ }
+}
+
+func TestBurstWindowSlides(t *testing.T) {
+ b, c := burstTestLimiter()
+ // 60 notes whose first and last are 61 s apart: never 60 inside 60 s.
+ step := 61 * time.Second / 59
+ for i := 0; i < 60; i++ {
+ if tripped, _ := b.note("bab/shop", burstClientA); tripped {
+ t.Fatalf("note %d tripped", i+1)
+ }
+ c.advance(step)
+ }
+ // And a steady pace slower than 60 per 60 s never trips, however long it
+ // lasts: 60 notes at this spacing span 59 x 1.02 s, more than the window.
+ b, c = burstTestLimiter()
+ for i := 0; i < 600; i++ {
+ if tripped, _ := b.note("bab/shop", burstClientA); tripped {
+ t.Fatalf("note %d tripped at a sustained slow pace", i+1)
+ }
+ c.advance(1020 * time.Millisecond)
+ }
+}
+
+func TestBurstCountsPerApp(t *testing.T) {
+ b, _ := burstTestLimiter()
+ for i := 0; i < 30; i++ {
+ if tripped, _ := b.note("bab/one", burstClientA); tripped {
+ t.Fatal("app one tripped")
+ }
+ if tripped, _ := b.note("bdk/two", burstClientA); tripped {
+ t.Fatal("app two tripped")
+ }
+ }
+ if _, _, ok := b.cooling(burstClientA); ok {
+ t.Fatal("30 + 30 across two apps put the client in a cool-down")
+ }
+}
+
+func TestBurstCountsPerClient(t *testing.T) {
+ b, _ := burstTestLimiter()
+ for i := 0; i < 59; i++ {
+ b.note("bab/shop", burstClientA)
+ b.note("bab/shop", burstClientB)
+ }
+ if _, _, ok := b.cooling(burstClientA); ok {
+ t.Fatal("client A cooling after 59")
+ }
+ if tripped, _ := b.note("bab/shop", burstClientA); !tripped {
+ t.Fatal("client A did not trip on its 60th")
+ }
+ if _, _, ok := b.cooling(burstClientB); ok {
+ t.Fatal("client B cooling because client A tripped")
+ }
+}
+
+func TestBurstCooldownIsBoxWide(t *testing.T) {
+ b, _ := burstTestLimiter()
+ for i := 0; i < 60; i++ {
+ b.note("bab/shop", burstClientA)
+ }
+ until, from, ok := b.cooling(burstClientA)
+ if !ok || from != "bab/shop" || until.IsZero() {
+ t.Fatalf("cooling = (%v, %q, %v), want a cool-down from bab/shop", until, from, ok)
+ }
+ // The cool-down belongs to the client, not the app it tripped on.
+ // Notes on another app during the cool-down are no-ops and leave it be.
+ if tripped, _ := b.note("bdk/other", burstClientA); tripped {
+ t.Fatal("a note on another app tripped again")
+ }
+ if _, f, ok := b.cooling(burstClientA); !ok || f != "bab/shop" {
+ t.Fatalf("cooling after another app's note: from %q ok %v", f, ok)
+ }
+ if _, _, ok := b.cooling(burstClientB); ok {
+ t.Fatal("another client is cooling")
+ }
+}
+
+func TestBurstTripClearsTheClientsCounters(t *testing.T) {
+ b, c := burstTestLimiter()
+ for i := 0; i < 20; i++ {
+ b.note("bdk/other", burstClientA)
+ }
+ for i := 0; i < 60; i++ {
+ b.note("bab/shop", burstClientA)
+ }
+ if n := b.counterCount(); n != 0 {
+ t.Fatalf("counters after a trip = %d, want 0", n)
+ }
+ // After the cool-down the client starts from nothing.
+ c.advance(burstCooldown + time.Second)
+ for i := 0; i < 59; i++ {
+ if tripped, _ := b.note("bab/shop", burstClientA); tripped {
+ t.Fatalf("note %d tripped after the cool-down", i+1)
+ }
+ }
+}
+
+func TestBurstCooldownExpires(t *testing.T) {
+ b, c := burstTestLimiter()
+ for i := 0; i < 60; i++ {
+ b.note("bab/shop", burstClientA)
+ }
+ c.advance(burstCooldown - time.Second)
+ if _, _, ok := b.cooling(burstClientA); !ok {
+ t.Fatal("cool-down ended early")
+ }
+ c.advance(time.Second)
+ if _, _, ok := b.cooling(burstClientA); ok {
+ t.Fatal("cool-down did not end at 10 minutes")
+ }
+ if n := b.cooldownCount(); n != 0 {
+ t.Fatalf("expired cool-down still held: %d", n)
+ }
+}
+
+func TestBurstApplyBounds(t *testing.T) {
+ b, c := burstTestLimiter()
+ now := c.now()
+ if b.apply(burstClientA, now) {
+ t.Fatal("until == now accepted")
+ }
+ if b.apply(burstClientA, now.Add(-time.Second)) {
+ t.Fatal("until in the past accepted")
+ }
+ if b.apply(burstClientA, now.Add(burstCooldown+time.Second)) {
+ t.Fatal("until 10 min + 1 s ahead accepted")
+ }
+ if _, _, ok := b.cooling(burstClientA); ok {
+ t.Fatal("a refused notice started a cool-down")
+ }
+ if !b.apply(burstClientA, now.Add(burstCooldown)) {
+ t.Fatal("until exactly 10 min ahead refused")
+ }
+ until, from, ok := b.cooling(burstClientA)
+ if !ok || from != "" || !until.Equal(now.Add(burstCooldown)) {
+ t.Fatalf("cooling = (%v, %q, %v)", until, from, ok)
+ }
+
+ // A shorter until never shortens; a longer one extends.
+ b.apply(burstClientA, now.Add(time.Minute))
+ if u, _, _ := b.cooling(burstClientA); !u.Equal(now.Add(burstCooldown)) {
+ t.Fatalf("a shorter notice moved until to %v", u)
+ }
+ c.advance(5 * time.Minute)
+ b.apply(burstClientA, c.now().Add(burstCooldown))
+ if u, _, _ := b.cooling(burstClientA); !u.Equal(c.now().Add(burstCooldown)) {
+ t.Fatalf("a later notice did not extend: %v", u)
+ }
+}
+
+func TestBurstApplyNeverReportsATripAndNoteIsNoOpWhileCooling(t *testing.T) {
+ b, _ := burstTestLimiter()
+ b.apply(burstClientA, b.now().Add(time.Minute))
+ for i := 0; i < 200; i++ {
+ if tripped, _ := b.note("bab/shop", burstClientA); tripped {
+ t.Fatal("note tripped for a client already cooling from a notice")
+ }
+ }
+ if n := b.counterCount(); n != 0 {
+ t.Fatalf("notes during a cool-down left %d counters", n)
+ }
+ if _, from, _ := b.cooling(burstClientA); from != "" {
+ t.Fatalf("from = %q, want the notice's empty source", from)
+ }
+}
+
+func TestBurstBoundsEvictOldest(t *testing.T) {
+ lowerBurstCaps(t, 3, 2)
+ b, _ := burstTestLimiter()
+ clients := []netip.Prefix{
+ netip.MustParsePrefix("198.51.100.1/32"),
+ netip.MustParsePrefix("198.51.100.2/32"),
+ netip.MustParsePrefix("198.51.100.3/32"),
+ netip.MustParsePrefix("198.51.100.4/32"),
+ }
+ for _, cl := range clients {
+ b.note("bab/shop", cl)
+ }
+ if n := b.counterCount(); n != 3 {
+ t.Fatalf("counters = %d, want the cap of 3", n)
+ }
+ if got := b.stats().CountersEvicted; got != 1 {
+ t.Fatalf("CountersEvicted = %d, want 1", got)
+ }
+ // The oldest (client 1) went: 59 more notes from it do not trip,
+ // because its first note is gone and it starts again from one.
+ for i := 0; i < 59; i++ {
+ if tripped, _ := b.note("bab/shop", clients[0]); tripped {
+ t.Fatalf("evicted client tripped at %d", i)
+ }
+ }
+
+ // Cool-downs: the third evicts the first.
+ b, c := burstTestLimiter()
+ until := c.now().Add(time.Minute)
+ for _, cl := range clients[:3] {
+ if !b.apply(cl, until) {
+ t.Fatal("apply refused")
+ }
+ }
+ if n := b.cooldownCount(); n != 2 {
+ t.Fatalf("cool-downs = %d, want the cap of 2", n)
+ }
+ if got := b.stats().CooldownsEvicted; got != 1 {
+ t.Fatalf("CooldownsEvicted = %d, want 1", got)
+ }
+ if _, _, ok := b.cooling(clients[0]); ok {
+ t.Fatal("the oldest cool-down survived")
+ }
+ for _, cl := range clients[1:3] {
+ if _, _, ok := b.cooling(cl); !ok {
+ t.Fatalf("%v lost its cool-down", cl)
+ }
+ }
+}
+
+func TestBurstExpiredEntriesAreDroppedBeforeEvicting(t *testing.T) {
+ lowerBurstCaps(t, 2, 2)
+ b, c := burstTestLimiter()
+ b.note("bab/shop", burstClientA)
+ b.apply(burstClientA, c.now().Add(time.Minute))
+ c.advance(burstCooldown)
+ // Both held entries are long expired: a new one needs no eviction.
+ other := netip.MustParsePrefix("198.51.100.9/32")
+ b.note("bab/shop", other)
+ b.note("bab/shop", burstClientB)
+ b.apply(other, c.now().Add(time.Minute))
+ b.apply(burstClientB, c.now().Add(time.Minute))
+ if s := b.stats(); s.CountersEvicted != 0 || s.CooldownsEvicted != 0 {
+ t.Fatalf("expired entries were counted as evictions: %+v", s)
+ }
+}
+
+func TestBurstSingleKeyFloodBounded(t *testing.T) {
+ b, c := burstTestLimiter()
+ // A flood that never lets 60 land inside a window: one note per 2 s.
+ allocs := testing.AllocsPerRun(1, func() {
+ for i := 0; i < 1_000_000; i++ {
+ b.note("bab/shop", burstClientB)
+ c.advance(2 * time.Second)
+ }
+ })
+ if n := b.counterCount(); n != 1 {
+ t.Fatalf("counters = %d, want 1", n)
+ }
+ // AllocsPerRun runs the function once to warm up and once measured; the
+ // ring is made in the first, so the measured pass allocates nothing per
+ // note. Allow a handful for the runtime.
+ if allocs > 10 {
+ t.Fatalf("1,000,000 notes allocated %v times", allocs)
+ }
+ if s := b.stats(); s.CountersEvicted != 0 {
+ t.Fatalf("evictions = %d", s.CountersEvicted)
+ }
+
+ // A flood inside a cool-down is a no-op: no counters, no allocation.
+ b2, _ := burstTestLimiter()
+ b2.apply(burstClientA, b2.now().Add(time.Minute))
+ allocs = testing.AllocsPerRun(1, func() {
+ for i := 0; i < 1_000_000; i++ {
+ b2.note("bab/shop", burstClientA)
+ }
+ })
+ if allocs > 10 || b2.counterCount() != 0 {
+ t.Fatalf("notes during a cool-down: %v allocations, %d counters", allocs, b2.counterCount())
+ }
+}
+
+func TestBurstRingHoldsAtMost60Timestamps(t *testing.T) {
+ b, c := burstTestLimiter()
+ for i := 0; i < 5000; i++ {
+ b.note("bab/shop", burstClientA)
+ c.advance(2 * time.Second)
+ }
+ if got := b.ringLen("bab/shop", burstClientA); got != burstThreshold {
+ t.Fatalf("ring holds %d timestamps, want %d", got, burstThreshold)
+ }
+}
+
+func TestBurstConcurrent(t *testing.T) {
+ b := newBurstLimiter(time.Now)
+ var wg sync.WaitGroup
+ for g := 0; g < 8; g++ {
+ wg.Add(1)
+ go func(g int) {
+ defer wg.Done()
+ cl := netip.PrefixFrom(netip.AddrFrom4([4]byte{10, 0, 0, byte(g)}), 32)
+ for i := 0; i < 2000; i++ {
+ b.note("bab/shop", cl)
+ b.cooling(cl)
+ if i%500 == 0 {
+ b.apply(cl, time.Now().Add(time.Minute))
+ b.stats()
+ }
+ }
+ }(g)
+ }
+ wg.Wait()
+}
+
+// The tests look inside under the lock; the serving path never needs these.
+
+func (b *burstLimiter) counterCount() int {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ return b.counterLRU.Len()
+}
+
+func (b *burstLimiter) cooldownCount() int {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ return b.cooldownList.Len()
+}
+
+func (b *burstLimiter) ringLen(app string, client netip.Prefix) int {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ if el, ok := b.counters[client][app]; ok {
+ return len(el.Value.(*burstCounter).ts)
+ }
+ return 0
+}