discover: use hash bits value instead of hardcoded 256

This commit is contained in:
YeahNotSewerSide 2025-12-09 09:09:32 +02:00
parent e58c785424
commit 78a44e006b
No known key found for this signature in database
GPG key ID: 06C0183CB83B9095
2 changed files with 5 additions and 5 deletions

View file

@ -46,9 +46,9 @@ const (
// We keep buckets for the upper 1/15 of distances because // We keep buckets for the upper 1/15 of distances because
// it's very unlikely we'll ever encounter a node that's closer. // it's very unlikely we'll ever encounter a node that's closer.
hashBits = len(common.Hash{}) * 8 hashBits = uint(len(common.Hash{}) * 8)
nBuckets = hashBits / 15 // Number of buckets nBuckets = int(hashBits / 15) // Number of buckets
bucketMinDistance = hashBits - nBuckets // Log distance of closest bucket bucketMinDistance = int(hashBits) - nBuckets // Log distance of closest bucket
// IP address limits. // IP address limits.
bucketIPLimit, bucketSubnet = 2, 24 // at most 2 addresses from the same /24 bucketIPLimit, bucketSubnet = 2, 24 // at most 2 addresses from the same /24
@ -272,7 +272,7 @@ func (tab *Table) findnodeByID(target enode.ID, nresults int, preferLive bool) *
// appendBucketNodes adds nodes at the given distance to the result slice. // appendBucketNodes adds nodes at the given distance to the result slice.
// This is used by the FINDNODE/v5 handler. // This is used by the FINDNODE/v5 handler.
func (tab *Table) appendBucketNodes(dist uint, result []*enode.Node, checkLive bool) []*enode.Node { func (tab *Table) appendBucketNodes(dist uint, result []*enode.Node, checkLive bool) []*enode.Node {
if dist > 256 { if dist > hashBits {
return result return result
} }
if dist == 0 { if dist == 0 {

View file

@ -926,7 +926,7 @@ func (t *UDPv5) collectTableNodes(rip netip.Addr, distances []uint, limit int) [
for _, dist := range distances { for _, dist := range distances {
// Reject duplicate / invalid distances. // Reject duplicate / invalid distances.
_, seen := processed[dist] _, seen := processed[dist]
if seen || dist > 256 { if seen || dist > hashBits {
continue continue
} }
processed[dist] = struct{}{} processed[dist] = struct{}{}