diff options
Diffstat (limited to 'replay')
-rw-r--r-- | replay/replay.go | 12 | ||||
-rw-r--r-- | replay/replay_test.go | 18 |
2 files changed, 15 insertions, 15 deletions
diff --git a/replay/replay.go b/replay/replay.go index 8685712..5b2de41 100644 --- a/replay/replay.go +++ b/replay/replay.go @@ -17,24 +17,24 @@ const ( bitMask = blockBits - 1 ) -// A ReplayFilter rejects replayed messages by checking if message counter value is +// A Filter rejects replayed messages by checking if message counter value is // within a sliding window of previously received messages. -// The zero value for ReplayFilter is an empty filter ready to use. +// The zero value for Filter is an empty filter ready to use. // Filters are unsafe for concurrent use. -type ReplayFilter struct { +type Filter struct { last uint64 ring [ringBlocks]block } -// Init resets the filter to empty state. -func (f *ReplayFilter) Init() { +// Reset resets the filter to empty state. +func (f *Filter) Reset() { f.last = 0 f.ring[0] = 0 } // ValidateCounter checks if the counter should be accepted. // Overlimit counters (>= limit) are always rejected. -func (f *ReplayFilter) ValidateCounter(counter uint64, limit uint64) bool { +func (f *Filter) ValidateCounter(counter uint64, limit uint64) bool { if counter >= limit { return false } diff --git a/replay/replay_test.go b/replay/replay_test.go index 5af66ff..fcffd20 100644 --- a/replay/replay_test.go +++ b/replay/replay_test.go @@ -14,10 +14,10 @@ import ( * */ -const RejectAfterMessages = (1 << 64) - (1 << 4) - 1 +const RejectAfterMessages = 1<<64 - 1<<13 - 1 func TestReplay(t *testing.T) { - var filter ReplayFilter + var filter Filter const T_LIM = windowSize + 1 @@ -29,7 +29,7 @@ func TestReplay(t *testing.T) { } } - filter.Init() + filter.Reset() T(0, true) /* 1 */ T(1, true) /* 2 */ @@ -67,7 +67,7 @@ func TestReplay(t *testing.T) { T(0, false) /* 34 */ t.Log("Bulk test 1") - filter.Init() + filter.Reset() testNumber = 0 for i := uint64(1); i <= windowSize; i++ { T(i, true) @@ -76,7 +76,7 @@ func TestReplay(t *testing.T) { T(0, false) t.Log("Bulk test 2") - filter.Init() + filter.Reset() testNumber = 0 for i := uint64(2); i <= windowSize+1; i++ { T(i, true) @@ -85,14 +85,14 @@ func TestReplay(t *testing.T) { T(0, false) t.Log("Bulk test 3") - filter.Init() + filter.Reset() testNumber = 0 for i := uint64(windowSize + 1); i > 0; i-- { T(i, true) } t.Log("Bulk test 4") - filter.Init() + filter.Reset() testNumber = 0 for i := uint64(windowSize + 2); i > 1; i-- { T(i, true) @@ -100,7 +100,7 @@ func TestReplay(t *testing.T) { T(0, false) t.Log("Bulk test 5") - filter.Init() + filter.Reset() testNumber = 0 for i := uint64(windowSize); i > 0; i-- { T(i, true) @@ -109,7 +109,7 @@ func TestReplay(t *testing.T) { T(0, false) t.Log("Bulk test 6") - filter.Init() + filter.Reset() testNumber = 0 for i := uint64(windowSize); i > 0; i-- { T(i, true) |