Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use slices.contains #11380

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion p2p/discover/lookup_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"crypto/ecdsa"
"fmt"
"net"
"slices"
"sort"
"testing"

Expand Down Expand Up @@ -149,7 +150,7 @@ func (tn *preminedTestnet) neighborsAtDistances(base *enode.Node, distances []ui
for i := range lookupTestnet.dists[d] {
n := lookupTestnet.node(d, i)
d := enode.LogDist(base.ID(), n.ID())
if containsUint(uint(d), distances) {
if slices.Contains(distances, uint(d)) {
result = append(result, n)
if len(result) >= elems {
return result
Expand Down
12 changes: 2 additions & 10 deletions p2p/discover/v5_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"io"
"math"
"net"
"slices"
"sync"
"time"

Expand Down Expand Up @@ -435,7 +436,7 @@ func (t *UDPv5) verifyResponseNode(c *callV5, r *enr.Record, distances []uint, s
}
if distances != nil {
nd := enode.LogDist(c.node.ID(), node.ID())
if !containsUint(uint(nd), distances) {
if !slices.Contains(distances, uint(nd)) {
return nil, errors.New("does not match any requested distance")
}
}
Expand All @@ -446,15 +447,6 @@ func (t *UDPv5) verifyResponseNode(c *callV5, r *enr.Record, distances []uint, s
return node, nil
}

func containsUint(x uint, xs []uint) bool {
for _, v := range xs {
if x == v {
return true
}
}
return false
}

// call sends the given call and sets up a handler for response packets (of message type
// responseType). Responses are dispatched to the call's response channel.
func (t *UDPv5) call(node *enode.Node, responseType byte, packet v5wire.Packet) *callV5 {
Expand Down
Loading