mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 11:04:02 +03:00
Make stable bloom filter threadsafe
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user