github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/common/antireplay/bloomring.go (about) 1 package antireplay 2 3 import ( 4 "sync" 5 6 ss_bloomring "github.com/v2fly/ss-bloomring" 7 ) 8 9 type BloomRing struct { 10 *ss_bloomring.BloomRing 11 lock *sync.Mutex 12 } 13 14 func (b BloomRing) Interval() int64 { 15 return 9999999 16 } 17 18 func (b BloomRing) Check(sum []byte) bool { 19 b.lock.Lock() 20 defer b.lock.Unlock() 21 if b.Test(sum) { 22 return false 23 } 24 b.Add(sum) 25 return true 26 } 27 28 func NewBloomRing() BloomRing { 29 const ( 30 DefaultSFCapacity = 1e6 31 // FalsePositiveRate 32 DefaultSFFPR = 1e-6 33 DefaultSFSlot = 10 34 ) 35 return BloomRing{ss_bloomring.NewBloomRing(DefaultSFSlot, DefaultSFCapacity, DefaultSFFPR), &sync.Mutex{}} 36 }