"bufio"
"context"
"crypto/rand"
- "crypto/sha1"
"encoding/binary"
"encoding/hex"
"errors"
"expvar"
"fmt"
+ "github.com/cespare/xxhash"
"io"
"math"
"net"
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)
import (
"bytes"
- "crypto/sha1"
"net/netip"
g "github.com/anacrolix/generics"
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