Skip to content

Commit 6ef4495

Browse files
authored
p2p/discover: require table nodes to have an IP (#21330)
This fixes a corner case in discv5. The issue cannot happen in discv4 because it performs IP checks on all incoming node information.
1 parent 79addac commit 6ef4495

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

p2p/discover/table.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ func (tab *Table) delete(node *node) {
520520
}
521521

522522
func (tab *Table) addIP(b *bucket, ip net.IP) bool {
523+
if len(ip) == 0 {
524+
return false // Nodes without IP cannot be added.
525+
}
523526
if netutil.IsLAN(ip) {
524527
return true
525528
}

p2p/discover/table_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func testPingReplace(t *testing.T, newNodeIsResponding, lastInBucketIsResponding
5858

5959
// Fill up the sender's bucket.
6060
pingKey, _ := crypto.HexToECDSA("45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8")
61-
pingSender := wrapNode(enode.NewV4(&pingKey.PublicKey, net.IP{}, 99, 99))
61+
pingSender := wrapNode(enode.NewV4(&pingKey.PublicKey, net.IP{127, 0, 0, 1}, 99, 99))
6262
last := fillBucket(tab, pingSender)
6363

6464
// Add the sender as if it just pinged us. Revalidate should replace the last node in

0 commit comments

Comments
 (0)