client.go | 11 +++++++++-- smartban.go | 3 +-- diff --git a/client.go b/client.go index 62c0d2b4c52c5678990405fa0b779ad84ed041b3..7aab0402a70fc5333e44e759ac96b306ae07c696 100644 --- a/client.go +++ b/client.go @@ -4,12 +4,12 @@ import ( "bufio" "context" "crypto/rand" - "crypto/sha1" "encoding/binary" "encoding/hex" "errors" "expvar" "fmt" + "github.com/cespare/xxhash" "io" "math" "net" @@ -1301,7 +1301,14 @@ }, webSeeds: make(map[string]*Peer), gotMetainfoC: make(chan struct{}), } - t.smartBanCache.Hash = sha1.Sum + var salt [8]byte + rand.Read(salt[:]) + t.smartBanCache.Hash = func(b []byte) uint64 { + h := xxhash.New() + h.Write(salt[:]) + h.Write(b) + return h.Sum64() + } t.smartBanCache.Init() t.networkingEnabled.Set() t.logger = cl.logger.WithDefaultLevel(log.Debug) diff --git a/smartban.go b/smartban.go index 034a702d950372400c8dddb002fa1121304073e5..5515ded51fa3ef94f145a57439ef9e877dee6719 100644 --- a/smartban.go +++ b/smartban.go @@ -2,7 +2,6 @@ package torrent import ( "bytes" - "crypto/sha1" "net/netip" g "github.com/anacrolix/generics" @@ -12,7 +11,7 @@ ) type bannableAddr = netip.Addr -type smartBanCache = smartban.Cache[bannableAddr, RequestIndex, [sha1.Size]byte] +type smartBanCache = smartban.Cache[bannableAddr, RequestIndex, uint64] type blockCheckingWriter struct { cache *smartBanCache