Skip to content

Commit ad5a38f

Browse files
fjlgzliudan
authored andcommitted
fix(p2p/discover): require table nodes to have an IP ethereum#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 012b939 commit ad5a38f

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

p2p/discover/table.go

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

524524
func (tab *Table) addIP(b *bucket, ip net.IP) bool {
525+
if len(ip) == 0 {
526+
return false // Nodes without IP cannot be added.
527+
}
525528
if netutil.IsLAN(ip) {
526529
return true
527530
}

p2p/discover/table_test.go

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

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

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

0 commit comments

Comments
 (0)