Files
sing-box/protocol/cloudflare/flow_limiter.go
2026-03-31 15:32:56 +08:00

35 lines
478 B
Go

//go:build with_cloudflared
package cloudflare
import "sync"
type FlowLimiter struct {
access sync.Mutex
active uint64
}
func (l *FlowLimiter) Acquire(limit uint64) bool {
if limit == 0 {
return true
}
l.access.Lock()
defer l.access.Unlock()
if l.active >= limit {
return false
}
l.active++
return true
}
func (l *FlowLimiter) Release(limit uint64) {
if limit == 0 {
return
}
l.access.Lock()
defer l.access.Unlock()
if l.active > 0 {
l.active--
}
}