mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
fix: protect rng with a mutex
This commit is contained in:
parent
42addc4c24
commit
075afe8528
1
dht.go
1
dht.go
@ -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
|
||||
|
||||
|
2
query.go
2
query.go
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user