mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
Update sync.go
This commit is contained in:
parent
ff54ca02de
commit
e408e6cd8f
1 changed files with 8 additions and 2 deletions
|
|
@ -18,7 +18,8 @@ package dnsdisc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math/rand"
|
crand "crypto/rand"
|
||||||
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/mclock"
|
"github.com/ethereum/go-ethereum/common/mclock"
|
||||||
|
|
@ -131,7 +132,12 @@ func (ct *clientTree) syncNextLink(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *clientTree) syncNextRandomENR(ctx context.Context) (*enode.Node, error) {
|
func (ct *clientTree) syncNextRandomENR(ctx context.Context) (*enode.Node, error) {
|
||||||
index := rand.Intn(len(ct.enrs.missing))
|
// Use CSPRNG to avoid deterministic selection across processes.
|
||||||
|
n, err := crand.Int(crand.Reader, big.NewInt(int64(len(ct.enrs.missing))))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
index := int(n.Int64())
|
||||||
hash := ct.enrs.missing[index]
|
hash := ct.enrs.missing[index]
|
||||||
e, err := ct.enrs.resolveNext(ctx, hash)
|
e, err := ct.enrs.resolveNext(ctx, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue