Make stable bloom filter threadsafe

This commit is contained in:
9seconds
2021-03-15 10:53:29 +03:00
parent 3dc263d6d7
commit cae33a22e6
+6
View File
@@ -1,6 +1,8 @@
package antireplay
import (
"sync"
"github.com/9seconds/mtg/v2/mtglib"
"github.com/OneOfOne/xxhash"
boom "github.com/tylertreat/BoomFilters"
@@ -8,9 +10,13 @@ import (
type stableBloomFilter struct {
filter boom.StableBloomFilter
mutex sync.Mutex
}
func (s *stableBloomFilter) SeenBefore(digest []byte) bool {
s.mutex.Lock()
defer s.mutex.Unlock()
return s.filter.TestAndAdd(digest)
}