Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #28 from libp2p/fix/windows-tests-utils
Browse files Browse the repository at this point in the history
fix RandTestKeyPair on windows
  • Loading branch information
Stebalien authored Feb 1, 2018
2 parents 76c5a8e + 29ee8c4 commit 296ae64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3: QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS
2.2.4: QmQnuSxgSFubscHgkgSeayLxKmVcmNhFUaZw4gHtV3tJ15
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"license": "MIT",
"name": "go-libp2p-peer",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "2.2.3"
"version": "2.2.4"
}

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 296ae64

Please sign in to comment.