Skip to content

Commit

Permalink
fix RandTestKeyPair on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored and Stebalien committed Feb 1, 2018
1 parent 76c5a8e commit cc85f1c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package testutil
import (
"io"
"math/rand"
"sync/atomic"
"time"

ci "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
mh "github.com/multiformats/go-multihash"
)

var generatedPairs int64 = 0

func RandPeerID() (peer.ID, error) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
buf := make([]byte, 16)
Expand All @@ -21,7 +24,12 @@ func RandPeerID() (peer.ID, error) {
}

func RandTestKeyPair(bits int) (ci.PrivKey, ci.PubKey, error) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seed := time.Now().UnixNano()

// workaround for low time resolution
seed += atomic.AddInt64(&generatedPairs, 1) << 32

r := rand.New(rand.NewSource(seed))
return ci.GenerateKeyPairWithReader(ci.RSA, bits, r)
}

Expand Down

0 comments on commit cc85f1c

Please sign in to comment.