mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-11 06:08:39 +00:00
VMess inbound: Optimize replay filter (#5562)
And https://github.com/XTLS/Xray-core/pull/5562#issuecomment-3765387903
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package antireplay
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkMapFilter(b *testing.B) {
|
||||
filter := NewMapFilter[[16]byte](120)
|
||||
var sample [16]byte
|
||||
reader := bufio.NewReader(rand.Reader)
|
||||
reader.Read(sample[:])
|
||||
b.ResetTimer()
|
||||
for range b.N {
|
||||
reader.Read(sample[:])
|
||||
filter.Check(sample)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapFilter(t *testing.T) {
|
||||
filter := NewMapFilter[[16]byte](120)
|
||||
var sample [16]byte
|
||||
rand.Read(sample[:])
|
||||
filter.Check(sample)
|
||||
if filter.Check(sample) {
|
||||
t.Error("Unexpected true negative")
|
||||
}
|
||||
sample[0]++
|
||||
if !filter.Check(sample) {
|
||||
t.Error("Unexpected false positive")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user