mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-02 00:11:56 +03:00
Make stable bloom filter threadsafe
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package antireplay
|
package antireplay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/v2/mtglib"
|
"github.com/9seconds/mtg/v2/mtglib"
|
||||||
"github.com/OneOfOne/xxhash"
|
"github.com/OneOfOne/xxhash"
|
||||||
boom "github.com/tylertreat/BoomFilters"
|
boom "github.com/tylertreat/BoomFilters"
|
||||||
@@ -8,9 +10,13 @@ import (
|
|||||||
|
|
||||||
type stableBloomFilter struct {
|
type stableBloomFilter struct {
|
||||||
filter boom.StableBloomFilter
|
filter boom.StableBloomFilter
|
||||||
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stableBloomFilter) SeenBefore(digest []byte) bool {
|
func (s *stableBloomFilter) SeenBefore(digest []byte) bool {
|
||||||
|
s.mutex.Lock()
|
||||||
|
defer s.mutex.Unlock()
|
||||||
|
|
||||||
return s.filter.TestAndAdd(digest)
|
return s.filter.TestAndAdd(digest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user