mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-03-22 12:50:07 +08:00
remove go-ipfs-util dep
This commit is contained in:
parent
e54fbe83d4
commit
aa7305d39f
@ -7,12 +7,6 @@
|
||||
"dvcsimport": "github.com/libp2p/go-libp2p-peerstore"
|
||||
},
|
||||
"gxDependencies": [
|
||||
{
|
||||
"author": "whyrusleeping",
|
||||
"hash": "QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n",
|
||||
"name": "go-ipfs-util",
|
||||
"version": "1.2.4"
|
||||
},
|
||||
{
|
||||
"author": "whyrusleeping",
|
||||
"hash": "QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52",
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
)
|
||||
|
||||
func TestQueue(t *testing.T) {
|
||||
@ -64,7 +64,7 @@ func TestQueue(t *testing.T) {
|
||||
|
||||
func newPeerTime(t time.Time) peer.ID {
|
||||
s := fmt.Sprintf("hmmm time: %v", t)
|
||||
h := u.Hash([]byte(s))
|
||||
h, _ := mh.Sum([]byte(s), mh.SHA2_256, -1)
|
||||
return peer.ID(h)
|
||||
}
|
||||
|
||||
|
@ -2,25 +2,35 @@ package testutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
ci "github.com/libp2p/go-libp2p-crypto"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
)
|
||||
|
||||
func timeSeededRand() io.Reader {
|
||||
return rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
}
|
||||
|
||||
func RandPeerID() (peer.ID, error) {
|
||||
buf := make([]byte, 16)
|
||||
if _, err := io.ReadFull(u.NewTimeSeededRand(), buf); err != nil {
|
||||
if _, err := io.ReadFull(timeSeededRand(), buf); err != nil {
|
||||
return "", err
|
||||
}
|
||||
h := u.Hash(buf)
|
||||
h, err := mh.Sum(buf, mh.SHA2_256, -1)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return peer.ID(h), nil
|
||||
}
|
||||
|
||||
func RandTestKeyPair(bits int) (ci.PrivKey, ci.PubKey, error) {
|
||||
return ci.GenerateKeyPairWithReader(ci.RSA, bits, u.NewTimeSeededRand())
|
||||
return ci.GenerateKeyPairWithReader(ci.RSA, bits, timeSeededRand())
|
||||
}
|
||||
|
||||
func SeededTestKeyPair(seed int64) (ci.PrivKey, ci.PubKey, error) {
|
||||
return ci.GenerateKeyPairWithReader(ci.RSA, 512, u.NewSeededRand(seed))
|
||||
return ci.GenerateKeyPairWithReader(ci.RSA, 512, rand.New(rand.NewSource(seed)))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user