]> Sergey Matveev's repositories - btrtrc.git/blobdiff - smartban_test.go
cmd/btrtrc client
[btrtrc.git] / smartban_test.go
diff --git a/smartban_test.go b/smartban_test.go
deleted file mode 100644 (file)
index 2947f52..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-package torrent
-
-import (
-       "crypto/sha1"
-       "github.com/anacrolix/missinggo/v2/iter"
-       "github.com/anacrolix/torrent/smartban"
-       "github.com/cespare/xxhash"
-       "net/netip"
-       "testing"
-)
-
-func benchmarkSmartBanRecordBlock[Sum comparable](b *testing.B, hash func([]byte) Sum) {
-       var cache smartban.Cache[bannableAddr, RequestIndex, Sum]
-       cache.Hash = hash
-       cache.Init()
-       var data [defaultChunkSize]byte
-       var addr netip.Addr
-       b.SetBytes(int64(len(data)))
-       for i := range iter.N(b.N) {
-               cache.RecordBlock(addr, RequestIndex(i), data[:])
-       }
-}
-
-func BenchmarkSmartBanRecordBlock(b *testing.B) {
-       b.Run("xxHash", func(b *testing.B) {
-               var salt [8]byte
-               benchmarkSmartBanRecordBlock(b, func(block []byte) uint64 {
-                       h := xxhash.New()
-                       // xxHash is not cryptographic, and so we're salting it so attackers can't know a priori
-                       // where block data collisions are.
-                       h.Write(salt[:])
-                       h.Write(block)
-                       return h.Sum64()
-               })
-       })
-       b.Run("Sha1", func(b *testing.B) {
-               benchmarkSmartBanRecordBlock(b, sha1.Sum)
-       })
-}