提交 0494a4db 作者: Juan Batiz-Benet

Merge pull request #1327 from rht/cleanup-rand

Swap all 'crypto/rand' rng in tests with 'math/rand'
......@@ -64,7 +64,7 @@ it contains, with the following format:
paths := req.Arguments()
dagnodes := make([]*merkledag.Node, 0)
var dagnodes []*merkledag.Node
for _, fpath := range paths {
dagnode, err := core.Resolve(req.Context().Context, node, path.Path(fpath))
if err != nil {
......
......@@ -223,9 +223,8 @@ func doMount(node *core.IpfsNode, fsdir, nsdir string) error {
if err1 != nil {
return fmtFuseErr(err1)
} else {
return fmtFuseErr(err2)
}
return fmtFuseErr(err2)
}
// setup node state, so that it can be cancelled
......
......@@ -253,7 +253,7 @@ Defaults to "direct".
if typeStr == "indirect" && count {
for k, v := range keys.Keys {
if quiet {
fmt.Fprintf(out, "%s\n", k, v.Count)
fmt.Fprintf(out, "%s %d\n", k, v.Count)
} else {
fmt.Fprintf(out, "%s %s %d\n", k, v.Type, v.Count)
}
......
......@@ -222,9 +222,8 @@ type RefWriter struct {
func (rw *RefWriter) WriteRefs(n *dag.Node) (int, error) {
if rw.Recursive {
return rw.writeRefsRecursive(n)
} else {
return rw.writeRefsSingle(n)
}
return rw.writeRefsSingle(n)
}
func (rw *RefWriter) writeRefsRecursive(n *dag.Node) (int, error) {
......
......@@ -4,7 +4,6 @@ package ipns
import (
"bytes"
"crypto/rand"
"fmt"
"io/ioutil"
mrand "math/rand"
......@@ -19,6 +18,7 @@ import (
core "github.com/ipfs/go-ipfs/core"
coremock "github.com/ipfs/go-ipfs/core/mock"
nsfs "github.com/ipfs/go-ipfs/ipnsfs"
u "github.com/ipfs/go-ipfs/util"
ci "github.com/ipfs/go-ipfs/util/testutil/ci"
)
......@@ -30,7 +30,7 @@ func maybeSkipFuseTests(t *testing.T) {
func randBytes(size int) []byte {
b := make([]byte, size)
rand.Read(b)
u.NewTimeSeededRand().Read(b)
return b
}
......
......@@ -2,7 +2,6 @@ package balanced
import (
"bytes"
"crypto/rand"
"fmt"
"io"
"io/ioutil"
......@@ -130,7 +129,7 @@ func TestRabinBlockSize(t *testing.T) {
}
buf := new(bytes.Buffer)
nbytes := 1024 * 1024
io.CopyN(buf, rand.Reader, int64(nbytes))
io.CopyN(buf, u.NewTimeSeededRand(), int64(nbytes))
rab := chunk.NewMaybeRabin(4096)
blkch := rab.Split(buf)
......
......@@ -2,14 +2,15 @@ package chunk
import (
"bytes"
"crypto/rand"
"io"
"testing"
u "github.com/ipfs/go-ipfs/util"
)
func randBuf(t *testing.T, size int) []byte {
buf := make([]byte, size)
if _, err := rand.Read(buf); err != nil {
if _, err := u.NewTimeSeededRand().Read(buf); err != nil {
t.Fatal("failed to read enough randomness")
}
return buf
......
......@@ -2,7 +2,6 @@ package trickle
import (
"bytes"
"crypto/rand"
"fmt"
"io"
"io/ioutil"
......@@ -136,7 +135,7 @@ func TestRabinBlockSize(t *testing.T) {
}
buf := new(bytes.Buffer)
nbytes := 1024 * 1024
io.CopyN(buf, rand.Reader, int64(nbytes))
io.CopyN(buf, u.NewTimeSeededRand(), int64(nbytes))
rab := chunk.NewMaybeRabin(4096)
blkch := rab.Split(buf)
......
package backpressure_tests
import (
crand "crypto/rand"
"io"
"math/rand"
"testing"
......@@ -15,6 +14,7 @@ import (
eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
u "github.com/ipfs/go-ipfs/util"
)
var log = eventlog.Logger("backpressure")
......@@ -236,7 +236,7 @@ func TestStBackpressureStreamWrite(t *testing.T) {
// ready a buffer of random data
buf := make([]byte, 65536)
crand.Read(buf)
u.NewTimeSeededRand().Read(buf)
for {
// send a randomly sized subchunk
......
package reconnect
import (
crand "crypto/rand"
"io"
"math/rand"
"sync"
......@@ -14,6 +13,7 @@ import (
protocol "github.com/ipfs/go-ipfs/p2p/protocol"
testutil "github.com/ipfs/go-ipfs/p2p/test/util"
eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
u "github.com/ipfs/go-ipfs/util"
ps "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
......@@ -66,7 +66,7 @@ func newSender() (chan sendChans, func(s inet.Stream)) {
buf := make([]byte, 65536)
buf2 := make([]byte, 65536)
crand.Read(buf)
u.NewTimeSeededRand().Read(buf)
for {
select {
......
......@@ -2,7 +2,6 @@ package testutil
import (
"bytes"
crand "crypto/rand"
"errors"
"fmt"
"io"
......@@ -44,7 +43,7 @@ func SeededTestKeyPair(seed int64) (ci.PrivKey, ci.PubKey, error) {
// id, _ := peer.IDFromPublicKey(pk)
func RandPeerID() (peer.ID, error) {
buf := make([]byte, 16)
if _, err := io.ReadFull(crand.Reader, buf); err != nil {
if _, err := io.ReadFull(u.NewTimeSeededRand(), buf); err != nil {
return "", err
}
h := u.Hash(buf)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论