Skip to content

Commit 2573094

Browse files
committed
p2p/discover, p2p/discv5: use flexible comparison for IPs
1 parent 745026b commit 2573094

4 files changed

Lines changed: 4 additions & 5 deletions

File tree

‎p2p/discover/udp_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func TestUDP_successfulPing(t *testing.T) {
374374
if n.ID != rid {
375375
t.Errorf("node has wrong ID: got %v, want %v", n.ID, rid)
376376
}
377-
if !bytes.Equal(n.IP, test.remoteaddr.IP) {
377+
if !n.IP.Equal(test.remoteaddr.IP) {
378378
t.Errorf("node has wrong IP: got %v, want: %v", n.IP, test.remoteaddr.IP)
379379
}
380380
if int(n.UDP) != test.remoteaddr.Port {

‎p2p/discv5/net.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ func (net *Network) internNodeFromNeighbours(sender *net.UDPAddr, rn rpcNode) (n
759759
}
760760
return n, err
761761
}
762-
if !bytes.Equal(n.IP, rn.IP) || n.UDP != rn.UDP || n.TCP != rn.TCP {
762+
if !n.IP.Equal(rn.IP) || n.UDP != rn.UDP || n.TCP != rn.TCP {
763763
err = fmt.Errorf("metadata mismatch: got %v, want %v", rn, n)
764764
}
765765
return n, err

‎p2p/discv5/node.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package discv5
1818

1919
import (
20-
"bytes"
2120
"crypto/ecdsa"
2221
"crypto/elliptic"
2322
"encoding/hex"
@@ -81,7 +80,7 @@ func (n *Node) addrEqual(a *net.UDPAddr) bool {
8180
if ipv4 := a.IP.To4(); ipv4 != nil {
8281
ip = ipv4
8382
}
84-
return n.UDP == uint16(a.Port) && bytes.Equal(n.IP, ip)
83+
return n.UDP == uint16(a.Port) && n.IP.Equal(ip)
8584
}
8685

8786
// Incomplete returns true for nodes with no IP address.

‎p2p/discv5/udp.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func makeEndpoint(addr *net.UDPAddr, tcpPort uint16) rpcEndpoint {
196196
}
197197

198198
func (e1 rpcEndpoint) equal(e2 rpcEndpoint) bool {
199-
return e1.UDP == e2.UDP && e1.TCP == e2.TCP && bytes.Equal(e1.IP, e2.IP)
199+
return e1.UDP == e2.UDP && e1.TCP == e2.TCP && e1.IP.Equal(e2.IP)
200200
}
201201

202202
func nodeFromRPC(sender *net.UDPAddr, rn rpcNode) (*Node, error) {

0 commit comments

Comments
 (0)