p2p/discover: rename

This commit is contained in:
Felix Lange 2024-05-14 22:26:49 +02:00
parent 008ff21cdf
commit f96f5965e6

View file

@ -189,12 +189,12 @@ type revalidationList struct {
} }
// get returns a random node from the queue. Nodes in the 'exclude' map are not returned. // get returns a random node from the queue. Nodes in the 'exclude' map are not returned.
func (rq *revalidationList) get(now mclock.AbsTime, rand randomSource, exclude map[enode.ID]struct{}) *node { func (list *revalidationList) get(now mclock.AbsTime, rand randomSource, exclude map[enode.ID]struct{}) *node {
if now < rq.nextTime || len(rq.nodes) == 0 { if now < list.nextTime || len(list.nodes) == 0 {
return nil return nil
} }
for i := 0; i < len(rq.nodes)*3; i++ { for i := 0; i < len(list.nodes)*3; i++ {
n := rq.nodes[rand.Intn(len(rq.nodes))] n := list.nodes[rand.Intn(len(list.nodes))]
_, excluded := exclude[n.ID()] _, excluded := exclude[n.ID()]
if !excluded { if !excluded {
return n return n
@ -203,25 +203,25 @@ func (rq *revalidationList) get(now mclock.AbsTime, rand randomSource, exclude m
return nil return nil
} }
func (rq *revalidationList) schedule(now mclock.AbsTime, rand randomSource) { func (list *revalidationList) schedule(now mclock.AbsTime, rand randomSource) {
rq.nextTime = now.Add(time.Duration(rand.Int63n(int64(rq.interval)))) list.nextTime = now.Add(time.Duration(rand.Int63n(int64(list.interval))))
} }
func (rq *revalidationList) push(n *node, now mclock.AbsTime, rand randomSource) { func (list *revalidationList) push(n *node, now mclock.AbsTime, rand randomSource) {
rq.nodes = append(rq.nodes, n) list.nodes = append(list.nodes, n)
if rq.nextTime == never { if list.nextTime == never {
rq.schedule(now, rand) list.schedule(now, rand)
} }
} }
func (rq *revalidationList) remove(n *node) bool { func (list *revalidationList) remove(n *node) bool {
i := slices.Index(rq.nodes, n) i := slices.Index(list.nodes, n)
if i == -1 { if i == -1 {
return false return false
} }
rq.nodes = slices.Delete(rq.nodes, i, i+1) list.nodes = slices.Delete(list.nodes, i, i+1)
if len(rq.nodes) == 0 { if len(list.nodes) == 0 {
rq.nextTime = never list.nextTime = never
} }
return true return true
} }