Skip to content

Commit

Permalink
p2p/enode: use unix timestamp as base ENR sequence number
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Jul 31, 2019
1 parent 96ab8e1 commit e1615fb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions p2p/enode/nodedb.go
Expand Up @@ -378,9 +378,14 @@ func (db *DB) UpdateFindFails(id ID, ip net.IP, fails int) error {
return db.storeInt64(nodeItemKey(id, ip, dbNodeFindFails), int64(fails))
}

// LocalSeq retrieves the local record sequence counter.
// LocalSeq retrieves the local record sequence counter, defaulting to the current
// timestamp if no previous exists. This ensures that wiping all data associated
// with a node (apart from its key) will not generate already used sequence nums.
func (db *DB) localSeq(id ID) uint64 {
return db.fetchUint64(localItemKey(id, dbLocalSeq))
if seq := db.fetchUint64(localItemKey(id, dbLocalSeq)); seq > 0 {
return seq
}
return uint64(time.Now().Unix())
}

// storeLocalSeq stores the local record sequence counter.
Expand Down

0 comments on commit e1615fb

Please sign in to comment.