good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit dac7cbcf authored by Péter Szilágyi's avatar Péter Szilágyi Committed by GitHub
Browse files

p2p/enode: use localItemKey for local sequence number (#19131)

* p2p/discover: remove unused function

* p2p/enode: use localItemKey for local sequence number

I added localItemKey for this purpose in #18963, but then
forgot to actually use it. This changes the database layout
yet again and requires bumping the version number.
parents dd28ba37 57f959af
No related branches found
No related tags found
No related merge requests found
...@@ -624,6 +624,8 @@ func (tn *preminedTestnet) findnode(toid enode.ID, toaddr *net.UDPAddr, target e ...@@ -624,6 +624,8 @@ func (tn *preminedTestnet) findnode(toid enode.ID, toaddr *net.UDPAddr, target e
func (*preminedTestnet) close() {} func (*preminedTestnet) close() {}
func (*preminedTestnet) ping(toid enode.ID, toaddr *net.UDPAddr) error { return nil } func (*preminedTestnet) ping(toid enode.ID, toaddr *net.UDPAddr) error { return nil }
var _ = (*preminedTestnet).mine // avoid linter warning about mine being dead code.
// mine generates a testnet struct literal with nodes at // mine generates a testnet struct literal with nodes at
// various distances to the given target. // various distances to the given target.
func (tn *preminedTestnet) mine(target encPubkey) { func (tn *preminedTestnet) mine(target encPubkey) {
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package discover package discover
import ( import (
"crypto/ecdsa"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"math/rand" "math/rand"
...@@ -167,11 +166,3 @@ func hexEncPubkey(h string) (ret encPubkey) { ...@@ -167,11 +166,3 @@ func hexEncPubkey(h string) (ret encPubkey) {
copy(ret[:], b) copy(ret[:], b)
return ret return ret
} }
func hexPubkey(h string) *ecdsa.PublicKey {
k, err := decodePubkey(hexEncPubkey(h))
if err != nil {
panic(err)
}
return k
}
...@@ -57,7 +57,7 @@ const ( ...@@ -57,7 +57,7 @@ const (
const ( const (
dbNodeExpiration = 24 * time.Hour // Time after which an unseen node should be dropped. dbNodeExpiration = 24 * time.Hour // Time after which an unseen node should be dropped.
dbCleanupCycle = time.Hour // Time period for running the expiration task. dbCleanupCycle = time.Hour // Time period for running the expiration task.
dbVersion = 8 dbVersion = 9
) )
var zeroIP = make(net.IP, 16) var zeroIP = make(net.IP, 16)
...@@ -380,12 +380,12 @@ func (db *DB) UpdateFindFails(id ID, ip net.IP, fails int) error { ...@@ -380,12 +380,12 @@ func (db *DB) UpdateFindFails(id ID, ip net.IP, fails int) error {
// LocalSeq retrieves the local record sequence counter. // LocalSeq retrieves the local record sequence counter.
func (db *DB) localSeq(id ID) uint64 { func (db *DB) localSeq(id ID) uint64 {
return db.fetchUint64(nodeItemKey(id, zeroIP, dbLocalSeq)) return db.fetchUint64(localItemKey(id, dbLocalSeq))
} }
// storeLocalSeq stores the local record sequence counter. // storeLocalSeq stores the local record sequence counter.
func (db *DB) storeLocalSeq(id ID, n uint64) { func (db *DB) storeLocalSeq(id ID, n uint64) {
db.storeUint64(nodeItemKey(id, zeroIP, dbLocalSeq), n) db.storeUint64(localItemKey(id, dbLocalSeq), n)
} }
// QuerySeeds retrieves random nodes to be used as potential seed nodes // QuerySeeds retrieves random nodes to be used as potential seed nodes
......
...@@ -71,7 +71,7 @@ func TestDBNodeItemKey(t *testing.T) { ...@@ -71,7 +71,7 @@ func TestDBNodeItemKey(t *testing.T) {
if id != keytestID { if id != keytestID {
t.Errorf("splitNodeItemKey returned wrong ID: %v", id) t.Errorf("splitNodeItemKey returned wrong ID: %v", id)
} }
if !bytes.Equal(ip, wantIP) { if !ip.Equal(wantIP) {
t.Errorf("splitNodeItemKey returned wrong IP: %v", ip) t.Errorf("splitNodeItemKey returned wrong IP: %v", ip)
} }
if field != wantField { if field != wantField {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment