github.com/imannamdari/v2ray-core/v5@v5.0.5/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 }