import (
"bytes"
"crypto/sha1"
+ "net/netip"
+
+ g "github.com/anacrolix/generics"
"github.com/anacrolix/torrent/smartban"
)
-type banPrefix = string
+type bannableAddr = netip.Addr
-type smartBanCache = smartban.Cache[banPrefix, RequestIndex, [sha1.Size]byte]
+type smartBanCache = smartban.Cache[bannableAddr, RequestIndex, [sha1.Size]byte]
type blockCheckingWriter struct {
cache *smartBanCache
requestIndex RequestIndex
// Peers that didn't match blocks written now.
- badPeers map[banPrefix]struct{}
+ badPeers map[bannableAddr]struct{}
blockBuffer bytes.Buffer
chunkSize int
}
func (me *blockCheckingWriter) checkBlock() {
b := me.blockBuffer.Next(me.chunkSize)
for _, peer := range me.cache.CheckBlock(me.requestIndex, b) {
- me.badPeers[peer] = struct{}{}
+ g.MakeMapIfNilAndSet(&me.badPeers, peer, struct{}{})
}
me.requestIndex++
}