mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-14 07:53:47 +00:00
Merge branch 'master' into portal1
This commit is contained in:
commit
088af7da90
1 changed files with 18 additions and 15 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
package discover
|
package discover
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -60,8 +61,8 @@ const (
|
||||||
seedMaxAge = 5 * 24 * time.Hour
|
seedMaxAge = 5 * 24 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
// Table is the 'Node table', a Kademlia-like index of neighbor nodes. The table keeps
|
// Table is the 'node table', a Kademlia-like index of neighbor nodes. The table keeps
|
||||||
// itself up-to-date by verifying the liveness of neighbors and requesting their Node
|
// itself up-to-date by verifying the liveness of neighbors and requesting their node
|
||||||
// records when announcements of a new record version are received.
|
// records when announcements of a new record version are received.
|
||||||
type Table struct {
|
type Table struct {
|
||||||
mutex sync.Mutex // protects buckets, bucket content, nursery, rand
|
mutex sync.Mutex // protects buckets, bucket content, nursery, rand
|
||||||
|
|
@ -206,10 +207,10 @@ func (tab *Table) setFallbackNodes(nodes []*enode.Node) error {
|
||||||
nursery := make([]*node, 0, len(nodes))
|
nursery := make([]*node, 0, len(nodes))
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
if err := n.ValidateComplete(); err != nil {
|
if err := n.ValidateComplete(); err != nil {
|
||||||
return fmt.Errorf("bad bootstrap Node %q: %v", n, err)
|
return fmt.Errorf("bad bootstrap node %q: %v", n, err)
|
||||||
}
|
}
|
||||||
if tab.cfg.NetRestrict != nil && !tab.cfg.NetRestrict.Contains(n.IP()) {
|
if tab.cfg.NetRestrict != nil && !tab.cfg.NetRestrict.Contains(n.IP()) {
|
||||||
tab.log.Error("Bootstrap Node filtered by netrestrict", "id", n.ID(), "ip", n.IP())
|
tab.log.Error("Bootstrap node filtered by netrestrict", "id", n.ID(), "ip", n.IP())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
nursery = append(nursery, wrapNode(n))
|
nursery = append(nursery, wrapNode(n))
|
||||||
|
|
@ -330,8 +331,10 @@ func (tab *Table) loadSeedNodes() {
|
||||||
seeds = append(seeds, tab.nursery...)
|
seeds = append(seeds, tab.nursery...)
|
||||||
for i := range seeds {
|
for i := range seeds {
|
||||||
seed := seeds[i]
|
seed := seeds[i]
|
||||||
age := log.Lazy{Fn: func() interface{} { return time.Since(tab.db.LastPongReceived(seed.ID(), seed.IP())) }}
|
if tab.log.Enabled(context.Background(), log.LevelTrace) {
|
||||||
tab.log.Trace("Found seed Node in database", "id", seed.ID(), "addr", seed.addr(), "age", age)
|
age := time.Since(tab.db.LastPongReceived(seed.ID(), seed.IP()))
|
||||||
|
tab.log.Trace("Found seed node in database", "id", seed.ID(), "addr", seed.addr(), "age", age)
|
||||||
|
}
|
||||||
tab.addSeenNode(seed)
|
tab.addSeenNode(seed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -347,10 +350,10 @@ func (tab *Table) doRevalidate(done chan<- struct{}) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ping the selected Node and wait for a pong.
|
// Ping the selected node and wait for a pong.
|
||||||
remoteSeq, err := tab.net.ping(unwrapNode(last))
|
remoteSeq, err := tab.net.ping(unwrapNode(last))
|
||||||
|
|
||||||
// Also fetch record if the Node replied and returned a higher sequence number.
|
// Also fetch record if the node replied and returned a higher sequence number.
|
||||||
if last.Seq() < remoteSeq {
|
if last.Seq() < remoteSeq {
|
||||||
n, err := tab.net.RequestENR(unwrapNode(last))
|
n, err := tab.net.RequestENR(unwrapNode(last))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -364,18 +367,18 @@ func (tab *Table) doRevalidate(done chan<- struct{}) {
|
||||||
defer tab.mutex.Unlock()
|
defer tab.mutex.Unlock()
|
||||||
b := tab.buckets[bi]
|
b := tab.buckets[bi]
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// The Node responded, move it to the front.
|
// The node responded, move it to the front.
|
||||||
last.livenessChecks++
|
last.livenessChecks++
|
||||||
tab.log.Debug("Revalidated Node", "b", bi, "id", last.ID(), "checks", last.livenessChecks)
|
tab.log.Debug("Revalidated node", "b", bi, "id", last.ID(), "checks", last.livenessChecks)
|
||||||
tab.bumpInBucket(b, last)
|
tab.bumpInBucket(b, last)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// No reply received, pick a replacement or delete the Node if there aren't
|
// No reply received, pick a replacement or delete the node if there aren't
|
||||||
// any replacements.
|
// any replacements.
|
||||||
if r := tab.replace(b, last); r != nil {
|
if r := tab.replace(b, last); r != nil {
|
||||||
tab.log.Debug("Replaced dead Node", "b", bi, "id", last.ID(), "ip", last.IP(), "checks", last.livenessChecks, "r", r.ID(), "rip", r.IP())
|
tab.log.Debug("Replaced dead node", "b", bi, "id", last.ID(), "ip", last.IP(), "checks", last.livenessChecks, "r", r.ID(), "rip", r.IP())
|
||||||
} else {
|
} else {
|
||||||
tab.log.Debug("Removed dead Node", "b", bi, "id", last.ID(), "ip", last.IP(), "checks", last.livenessChecks)
|
tab.log.Debug("Removed dead node", "b", bi, "id", last.ID(), "ip", last.IP(), "checks", last.livenessChecks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -664,8 +667,8 @@ func (tab *Table) bumpInBucket(b *bucket, n *node) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tab *Table) deleteInBucket(b *bucket, n *node) {
|
func (tab *Table) deleteInBucket(b *bucket, n *node) {
|
||||||
// Check if the Node is actually in the bucket so the removed hook
|
// Check if the node is actually in the bucket so the removed hook
|
||||||
// isn't called multiple times for the same Node.
|
// isn't called multiple times for the same node.
|
||||||
if !contains(b.entries, n.ID()) {
|
if !contains(b.entries, n.ID()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue