瀏覽代碼

Make stable bloom filter threadsafe

tags/v2.0.0-rc1
9seconds 5 年之前
父節點
當前提交
cae33a22e6
共有 1 個檔案被更改,包括 6 行新增 和 0 行删除
  1. 6
    0
      antireplay/stable_bloom_filter.go

+ 6
- 0
antireplay/stable_bloom_filter.go 查看文件

1
 package antireplay
1
 package antireplay
2
 
2
 
3
 import (
3
 import (
4
+	"sync"
5
+
4
 	"github.com/9seconds/mtg/v2/mtglib"
6
 	"github.com/9seconds/mtg/v2/mtglib"
5
 	"github.com/OneOfOne/xxhash"
7
 	"github.com/OneOfOne/xxhash"
6
 	boom "github.com/tylertreat/BoomFilters"
8
 	boom "github.com/tylertreat/BoomFilters"
8
 
10
 
9
 type stableBloomFilter struct {
11
 type stableBloomFilter struct {
10
 	filter boom.StableBloomFilter
12
 	filter boom.StableBloomFilter
13
+	mutex  sync.Mutex
11
 }
14
 }
12
 
15
 
13
 func (s *stableBloomFilter) SeenBefore(digest []byte) bool {
16
 func (s *stableBloomFilter) SeenBefore(digest []byte) bool {
17
+	s.mutex.Lock()
18
+	defer s.mutex.Unlock()
19
+
14
 	return s.filter.TestAndAdd(digest)
20
 	return s.filter.TestAndAdd(digest)
15
 }
21
 }
16
 
22
 

Loading…
取消
儲存