mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-03 13:38:39 +00:00
Merge 9762b927dd into 12eabbd76d
This commit is contained in:
commit
eed0d844b4
1 changed files with 16 additions and 11 deletions
|
|
@ -290,28 +290,33 @@ func (tab *Table) refresh() <-chan struct{} {
|
||||||
// preferLive is true and the table contains any verified nodes, the result will not
|
// preferLive is true and the table contains any verified nodes, the result will not
|
||||||
// contain unverified nodes. However, if there are no verified nodes at all, the result
|
// contain unverified nodes. However, if there are no verified nodes at all, the result
|
||||||
// will contain unverified nodes.
|
// will contain unverified nodes.
|
||||||
func (tab *Table) findnodeByID(target enode.ID, nresults int, preferLive bool) *nodesByDistance {
|
func (tab *Table) findnodeByID(target enode.ID, nresults int, preferLive bool) (nodes nodesByDistance) {
|
||||||
|
nodes.target = target
|
||||||
tab.mutex.Lock()
|
tab.mutex.Lock()
|
||||||
defer tab.mutex.Unlock()
|
defer tab.mutex.Unlock()
|
||||||
|
|
||||||
// Scan all buckets. There might be a better way to do this, but there aren't that many
|
// Scan all buckets. There might be a better way to do this, but there aren't that many
|
||||||
// buckets, so this solution should be fine. The worst-case complexity of this loop
|
// buckets, so this solution should be fine. The worst-case complexity of this loop
|
||||||
// is O(tab.len() * nresults).
|
// is O(tab.len() * nresults).
|
||||||
nodes := &nodesByDistance{target: target}
|
if preferLive {
|
||||||
liveNodes := &nodesByDistance{target: target}
|
for _, b := range &tab.buckets {
|
||||||
for _, b := range &tab.buckets {
|
for _, n := range b.entries {
|
||||||
for _, n := range b.entries {
|
if n.isValidatedLive {
|
||||||
nodes.push(n.Node, nresults)
|
nodes.push(n.Node, nresults)
|
||||||
if preferLive && n.isValidatedLive {
|
}
|
||||||
liveNodes.push(n.Node, nresults)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(nodes.entries) > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if preferLive && len(liveNodes.entries) > 0 {
|
for _, b := range &tab.buckets {
|
||||||
return liveNodes
|
for _, n := range b.entries {
|
||||||
|
nodes.push(n.Node, nresults)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nodes
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// appendBucketNodes adds nodes at the given distance to the result slice.
|
// appendBucketNodes adds nodes at the given distance to the result slice.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue