Skip to content

Commit 9dfe728

Browse files
authored
p2p/discover: using slices.Contains (#29395)
1 parent 8bd0334 commit 9dfe728

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

p2p/discover/v4_lookup_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (tn *preminedTestnet) neighborsAtDistances(base *enode.Node, distances []ui
285285
for i := range lookupTestnet.dists[d] {
286286
n := lookupTestnet.node(d, i)
287287
d := enode.LogDist(base.ID(), n.ID())
288-
if containsUint(uint(d), distances) {
288+
if slices.Contains(distances, uint(d)) {
289289
result = append(result, n)
290290
if len(result) >= elems {
291291
return result

p2p/discover/v5_udp.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"fmt"
2626
"io"
2727
"net"
28+
"slices"
2829
"sync"
2930
"time"
3031

@@ -437,7 +438,7 @@ func (t *UDPv5) verifyResponseNode(c *callV5, r *enr.Record, distances []uint, s
437438
}
438439
if distances != nil {
439440
nd := enode.LogDist(c.id, node.ID())
440-
if !containsUint(uint(nd), distances) {
441+
if !slices.Contains(distances, uint(nd)) {
441442
return nil, errors.New("does not match any requested distance")
442443
}
443444
}
@@ -448,15 +449,6 @@ func (t *UDPv5) verifyResponseNode(c *callV5, r *enr.Record, distances []uint, s
448449
return node, nil
449450
}
450451

451-
func containsUint(x uint, xs []uint) bool {
452-
for _, v := range xs {
453-
if x == v {
454-
return true
455-
}
456-
}
457-
return false
458-
}
459-
460452
// callToNode sends the given call and sets up a handler for response packets (of message
461453
// type responseType). Responses are dispatched to the call's response channel.
462454
func (t *UDPv5) callToNode(n *enode.Node, responseType byte, req v5wire.Packet) *callV5 {

0 commit comments

Comments
 (0)