fix: protect rng with a mutex

This commit is contained in:
Adin Schmahmann 2020-03-20 05:31:06 -04:00
parent 42addc4c24
commit 075afe8528
2 changed files with 3 additions and 0 deletions

1
dht.go
View File

@ -66,6 +66,7 @@ type IpfsDHT struct {
birth time.Time // When this peer started up
rng *rand.Rand // Source of randomness
rnglk sync.Mutex // Rand does not support concurrency
Validator record.Validator

View File

@ -59,9 +59,11 @@ func (dht *IpfsDHT) runDisjointQueries(ctx context.Context, d int, target string
return nil, kb.ErrLookupFailure
}
dht.rnglk.Lock()
dht.rng.Shuffle(len(seedPeers), func(i, j int) {
seedPeers[i], seedPeers[j] = seedPeers[j], seedPeers[i]
})
dht.rnglk.Unlock()
// create "d" disjoint queries
queries := make([]*query, d)