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