p2p/discover: update comment

This commit is contained in:
Felix Lange 2024-05-28 19:02:23 +02:00
parent 3148497f2b
commit 6cab7ddfe0

View file

@ -612,18 +612,19 @@ func (tab *Table) bumpInBucket(b *bucket, newRecord *enode.Node, isInbound bool)
return elem.ID() == newRecord.ID() return elem.ID() == newRecord.ID()
}) })
if i == -1 { if i == -1 {
return nil, false // node not in bucket return nil, false // not in bucket
} }
// Disallow updates unless the sequence number is increased.
// Note there is a special case for discv4: if the node contacts us (isInbound),
// it is allowed to update its own entry.
n = b.entries[i] n = b.entries[i]
// For inbound updates (from the node itself) we accept any change, even if it sets
// back the sequence number. For found nodes (!isInbound), seq has to advance. Note
// this check also ensures found discv4 nodes (which always have seq=0) can't be
// updated.
if newRecord.Seq() <= n.Seq() && !isInbound { if newRecord.Seq() <= n.Seq() && !isInbound {
return n, false return n, false
} }
// Check if there is an endpoint update and validate against IP limits. // Check endpoint update against IP limits.
ipchanged := newRecord.IPAddr() != n.IPAddr() ipchanged := newRecord.IPAddr() != n.IPAddr()
portchanged := newRecord.UDP() != n.UDP() portchanged := newRecord.UDP() != n.UDP()
if ipchanged { if ipchanged {
@ -637,9 +638,8 @@ func (tab *Table) bumpInBucket(b *bucket, newRecord *enode.Node, isInbound bool)
// Apply update. // Apply update.
n.Node = newRecord n.Node = newRecord
// Endpoint changes cause the node to be considered unverified.
if ipchanged || portchanged { if ipchanged || portchanged {
// Ensure node is revalidated quickly for endpoint changes.
tab.revalidation.nodeEndpointChanged(tab, n) tab.revalidation.nodeEndpointChanged(tab, n)
return n, true return n, true
} }