Add event stream module

This commit is contained in:
9seconds
2021-03-15 21:34:53 +03:00
parent abff0cf211
commit b08d945d7c
13 changed files with 225 additions and 15 deletions
+1
View File
@@ -5,6 +5,7 @@ import "github.com/9seconds/mtg/v2/mtglib"
type noop struct{}
func (n noop) SeenBefore(_ []byte) bool { return false }
func (n noop) Shutdown() {}
func NewNoop() mtglib.AntiReplayCache {
return noop{}
+2
View File
@@ -18,6 +18,8 @@ func (suite *NoopTestSuite) TestOp() {
suite.False(filter.SeenBefore([]byte{4, 5, 6}))
suite.False(filter.SeenBefore([]byte{1, 2, 3}))
suite.False(filter.SeenBefore([]byte{4, 5, 6}))
filter.Shutdown()
}
func TestNoop(t *testing.T) {
+2
View File
@@ -20,6 +20,8 @@ func (s *stableBloomFilter) SeenBefore(digest []byte) bool {
return s.filter.TestAndAdd(digest)
}
func (s *stableBloomFilter) Shutdown() {}
func NewStableBloomFilter(byteSize uint, errorRate float64) mtglib.AntiReplayCache {
sf := boom.NewDefaultStableBloomFilter(byteSize*8, errorRate) // nolint: gomnd
sf.SetHash(xxhash.New64())
+2
View File
@@ -18,6 +18,8 @@ func (suite *StableBloomFilterTestSuite) TestOp() {
suite.False(filter.SeenBefore([]byte{4, 5, 6}))
suite.True(filter.SeenBefore([]byte{1, 2, 3}))
suite.True(filter.SeenBefore([]byte{4, 5, 6}))
filter.Shutdown()
}
func TestStableBloomFilter(t *testing.T) {