mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 20:37:53 +08:00
Merge pull request #6140 from ipfs/fix/golangci-lint
chore: fix a bunch of issues caught by golangci-lint
This commit is contained in:
commit
fd15c62d47
@ -530,7 +530,7 @@ func printSwarmAddrs(node *core.IpfsNode) {
|
||||
for _, addr := range ifaceAddrs {
|
||||
lisAddrs = append(lisAddrs, addr.String())
|
||||
}
|
||||
sort.Sort(sort.StringSlice(lisAddrs))
|
||||
sort.Strings(lisAddrs)
|
||||
for _, addr := range lisAddrs {
|
||||
fmt.Printf("Swarm listening on %s\n", addr)
|
||||
}
|
||||
@ -539,7 +539,7 @@ func printSwarmAddrs(node *core.IpfsNode) {
|
||||
for _, addr := range node.PeerHost.Addrs() {
|
||||
addrs = append(addrs, addr.String())
|
||||
}
|
||||
sort.Sort(sort.StringSlice(addrs))
|
||||
sort.Strings(addrs)
|
||||
for _, addr := range addrs {
|
||||
fmt.Printf("Swarm announcing %s\n", addr)
|
||||
}
|
||||
|
||||
@ -37,8 +37,6 @@ import (
|
||||
// log is the command logger
|
||||
var log = logging.Logger("cmd/ipfs")
|
||||
|
||||
var errRequestCanceled = errors.New("request canceled")
|
||||
|
||||
// declared as a var for testing purposes
|
||||
var dnsResolver = madns.DefaultResolver
|
||||
|
||||
@ -325,7 +323,11 @@ func startProfiling() (func(), error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pprof.StartCPUProfile(ofi)
|
||||
err = pprof.StartCPUProfile(ofi)
|
||||
if err != nil {
|
||||
ofi.Close()
|
||||
return nil, err
|
||||
}
|
||||
go func() {
|
||||
for range time.NewTicker(time.Second * 30).C {
|
||||
err := writeHeapProfileToFile()
|
||||
|
||||
@ -103,7 +103,7 @@ func run(ipfsPath, watchPath string) error {
|
||||
})
|
||||
}
|
||||
|
||||
interrupts := make(chan os.Signal)
|
||||
interrupts := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupts, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
for {
|
||||
@ -129,7 +129,9 @@ func run(ipfsPath, watchPath string) error {
|
||||
switch e.Op {
|
||||
case fsnotify.Create:
|
||||
if isDir {
|
||||
addTree(watcher, e.Name)
|
||||
if err := addTree(watcher, e.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
proc.Go(func(p process.Process) {
|
||||
@ -167,6 +169,10 @@ func run(ipfsPath, watchPath string) error {
|
||||
|
||||
func addTree(w *fsnotify.Watcher, root string) error {
|
||||
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
}
|
||||
isDir, err := IsDirectory(path)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
@ -129,8 +129,14 @@ func setupPeer(a args) (peer.ID, pstore.Peerstore, error) {
|
||||
}
|
||||
|
||||
ps := pstoremem.NewPeerstore()
|
||||
ps.AddPrivKey(p, sk)
|
||||
ps.AddPubKey(p, pk)
|
||||
err = ps.AddPrivKey(p, sk)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
err = ps.AddPubKey(p, pk)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
out("local peer id: %s", p)
|
||||
return p, ps, nil
|
||||
|
||||
@ -44,8 +44,6 @@ func (rl *ReqLog) AddEntry(rle *ReqLogEntry) {
|
||||
if rle == nil || !rle.Active {
|
||||
rl.maybeCleanup()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// ClearInactive removes stale entries
|
||||
|
||||
@ -78,10 +78,10 @@ func (cfg *BuildCfg) fillDefaults() error {
|
||||
|
||||
if cfg.Repo == nil {
|
||||
var d ds.Datastore
|
||||
d = ds.NewMapDatastore()
|
||||
|
||||
if cfg.NilRepo {
|
||||
d = ds.NewNullDatastore()
|
||||
} else {
|
||||
d = ds.NewMapDatastore()
|
||||
}
|
||||
r, err := defaultRepo(dsync.MutexWrap(d))
|
||||
if err != nil {
|
||||
|
||||
@ -230,7 +230,7 @@ You can now check what blocks have been created by:
|
||||
opts = append(opts, options.Unixfs.Layout(options.TrickleLayout))
|
||||
}
|
||||
|
||||
errCh := make(chan error)
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
var err error
|
||||
defer func() { errCh <- err }()
|
||||
@ -255,12 +255,14 @@ You can now check what blocks have been created by:
|
||||
output.Name = path.Join(name, output.Name)
|
||||
}
|
||||
|
||||
res.Emit(&AddEvent{
|
||||
if err := res.Emit(&AddEvent{
|
||||
Name: output.Name,
|
||||
Hash: h,
|
||||
Bytes: output.Bytes,
|
||||
Size: output.Size,
|
||||
})
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return <-errCh
|
||||
|
||||
@ -239,8 +239,7 @@ var basesCmd = &cmds.Command{
|
||||
for code, name := range mbase.EncodingToStr {
|
||||
res = append(res, CodeAndName{int(code), name})
|
||||
}
|
||||
cmds.EmitOnce(resp, res)
|
||||
return nil
|
||||
return cmds.EmitOnce(resp, res)
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, val []CodeAndName) error {
|
||||
@ -287,8 +286,7 @@ var codecsCmd = &cmds.Command{
|
||||
for code, name := range cid.CodecToStr {
|
||||
res = append(res, CodeAndName{int(code), name})
|
||||
}
|
||||
cmds.EmitOnce(resp, res)
|
||||
return nil
|
||||
return cmds.EmitOnce(resp, res)
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, val []CodeAndName) error {
|
||||
@ -321,8 +319,7 @@ var hashesCmd = &cmds.Command{
|
||||
}
|
||||
res = append(res, CodeAndName{int(code), name})
|
||||
}
|
||||
cmds.EmitOnce(resp, res)
|
||||
return nil
|
||||
return cmds.EmitOnce(resp, res)
|
||||
},
|
||||
Encoders: codecsCmd.Encoders,
|
||||
Type: codecsCmd.Type,
|
||||
|
||||
@ -12,8 +12,6 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
|
||||
"github.com/ipfs/go-ipfs-cmdkit"
|
||||
cmds "github.com/ipfs/go-ipfs-cmds"
|
||||
)
|
||||
@ -129,28 +127,10 @@ func cmdPathStrings(cmd *Command, showOptions bool) []string {
|
||||
}
|
||||
|
||||
recurse("", cmd)
|
||||
sort.Sort(sort.StringSlice(cmds))
|
||||
sort.Strings(cmds)
|
||||
return cmds
|
||||
}
|
||||
|
||||
// changes here will also need to be applied at
|
||||
// - ./dag/dag.go
|
||||
// - ./object/object.go
|
||||
// - ./files/files.go
|
||||
// - ./unixfs/unixfs.go
|
||||
func unwrapOutput(i interface{}) (interface{}, error) {
|
||||
var (
|
||||
ch <-chan interface{}
|
||||
ok bool
|
||||
)
|
||||
|
||||
if ch, ok = i.(<-chan interface{}); !ok {
|
||||
return nil, e.TypeErr(ch, i)
|
||||
}
|
||||
|
||||
return <-ch, nil
|
||||
}
|
||||
|
||||
type nonFatalError string
|
||||
|
||||
// streamResult is a helper function to stream results that possibly
|
||||
|
||||
@ -134,8 +134,8 @@ Set the value of the 'Datastore.Path' key:
|
||||
}
|
||||
buf = append(buf, byte('\n'))
|
||||
|
||||
w.Write(buf)
|
||||
return nil
|
||||
_, err = w.Write(buf)
|
||||
return err
|
||||
}),
|
||||
},
|
||||
Type: ConfigField{},
|
||||
@ -185,9 +185,8 @@ NOTE: For security reasons, this command will omit your private key. If you woul
|
||||
return err
|
||||
}
|
||||
buf = append(buf, byte('\n'))
|
||||
w.Write(buf)
|
||||
|
||||
return nil
|
||||
_, err = w.Write(buf)
|
||||
return err
|
||||
}),
|
||||
},
|
||||
}
|
||||
@ -352,9 +351,8 @@ var configProfileApplyCmd = &cmds.Command{
|
||||
diff := jsondiff.Compare(out.OldCfg, out.NewCfg)
|
||||
buf := jsondiff.Format(diff)
|
||||
|
||||
w.Write(buf)
|
||||
|
||||
return nil
|
||||
_, err := w.Write(buf)
|
||||
return err
|
||||
}),
|
||||
},
|
||||
Type: ConfigUpdateOutput{},
|
||||
|
||||
@ -168,6 +168,9 @@ var filesStatCmd = &cmds.Command{
|
||||
}
|
||||
|
||||
local, sizeLocal, err := walkBlock(req.Context, dagserv, nd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.WithLocality = true
|
||||
o.Local = local
|
||||
|
||||
@ -274,7 +274,7 @@ func fileArchive(f files.Node, name string, archive bool, compression int) (io.R
|
||||
piper, pipew := io.Pipe()
|
||||
checkErrAndClosePipe := func(err error) bool {
|
||||
if err != nil {
|
||||
pipew.CloseWithError(err)
|
||||
_ = pipew.CloseWithError(err)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@ -149,8 +149,11 @@ func parseIpfsAddr(addr string) ([]ipfsaddr.IPFSAddr, error) {
|
||||
}
|
||||
// resolve mutiladdr whose protocol is not ma.P_IPFS
|
||||
ctx, cancel := context.WithTimeout(context.Background(), resolveTimeout)
|
||||
defer cancel()
|
||||
addrs, err := madns.Resolve(ctx, mutiladdr)
|
||||
cancel()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(addrs) == 0 {
|
||||
return nil, errors.New("fail to resolve the multiaddr:" + mutiladdr.String())
|
||||
}
|
||||
|
||||
@ -98,7 +98,10 @@ order to reclaim hard disk space.
|
||||
}
|
||||
} else {
|
||||
err := corerepo.CollectResult(req.Context, gcOutChan, func(k cid.Cid) {
|
||||
re.Emit(&GcResult{Key: k})
|
||||
// Nothing to do with this error, really. This
|
||||
// most likely means that the client is gone but
|
||||
// we still need to let the GC finish.
|
||||
_ = re.Emit(&GcResult{Key: k})
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -163,10 +166,9 @@ Version string The repo version.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmds.EmitOnce(res, &corerepo.Stat{
|
||||
return cmds.EmitOnce(res, &corerepo.Stat{
|
||||
SizeStat: sizeStat,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
stat, err := corerepo.RepoStat(req.Context, n)
|
||||
@ -396,9 +398,9 @@ var repoVersionCmd = &cmds.Command{
|
||||
quiet, _ := req.Options[repoQuietOptionName].(bool)
|
||||
|
||||
if quiet {
|
||||
fmt.Fprintf(w, fmt.Sprintf("fs-repo@%s\n", out.Version))
|
||||
fmt.Fprintf(w, "fs-repo@%s\n", out.Version)
|
||||
} else {
|
||||
fmt.Fprintf(w, fmt.Sprintf("ipfs repo version fs-repo@%s\n", out.Version))
|
||||
fmt.Fprintf(w, "ipfs repo version fs-repo@%s\n", out.Version)
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
|
||||
@ -256,7 +256,7 @@ var swarmAddrsCmd = &cmds.Command{
|
||||
for p := range am.Addrs {
|
||||
ids = append(ids, p)
|
||||
}
|
||||
sort.Sort(sort.StringSlice(ids))
|
||||
sort.Strings(ids)
|
||||
|
||||
for _, p := range ids {
|
||||
paddrs := am.Addrs[p]
|
||||
@ -307,7 +307,7 @@ var swarmAddrsLocalCmd = &cmds.Command{
|
||||
}
|
||||
addrs = append(addrs, saddr)
|
||||
}
|
||||
sort.Sort(sort.StringSlice(addrs))
|
||||
sort.Strings(addrs)
|
||||
return cmds.EmitOnce(res, &stringList{addrs})
|
||||
},
|
||||
Type: stringList{},
|
||||
@ -338,7 +338,7 @@ var swarmAddrsListenCmd = &cmds.Command{
|
||||
for _, addr := range maddrs {
|
||||
addrs = append(addrs, addr.String())
|
||||
}
|
||||
sort.Sort(sort.StringSlice(addrs))
|
||||
sort.Strings(addrs)
|
||||
|
||||
return cmds.EmitOnce(res, &stringList{addrs})
|
||||
},
|
||||
|
||||
10
core/core.go
10
core/core.go
@ -399,7 +399,7 @@ func makeAddrsFactory(cfg config.Addresses) (p2pbhost.AddrsFactory, error) {
|
||||
var out []ma.Multiaddr
|
||||
for _, maddr := range addrs {
|
||||
// check for exact matches
|
||||
ok, _ := noAnnAddrs[maddr.String()]
|
||||
ok := noAnnAddrs[maddr.String()]
|
||||
// check for /ipcidr matches
|
||||
if !ok && !filters.AddrBlocked(maddr) {
|
||||
out = append(out, maddr)
|
||||
@ -814,9 +814,13 @@ func (n *IpfsNode) loadPrivateKey() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := n.Peerstore.AddPrivKey(n.Identity, sk); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := n.Peerstore.AddPubKey(n.Identity, sk.GetPublic()); err != nil {
|
||||
return err
|
||||
}
|
||||
n.PrivateKey = sk
|
||||
n.Peerstore.AddPrivKey(n.Identity, n.PrivateKey)
|
||||
n.Peerstore.AddPubKey(n.Identity, sk.GetPublic())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -48,14 +48,7 @@ func (api *PubSubAPI) Peers(ctx context.Context, opts ...caopts.PubSubPeersOptio
|
||||
return nil, err
|
||||
}
|
||||
|
||||
peers := api.pubSub.ListPeers(settings.Topic)
|
||||
out := make([]peer.ID, len(peers))
|
||||
|
||||
for i, peer := range peers {
|
||||
out[i] = peer
|
||||
}
|
||||
|
||||
return out, nil
|
||||
return api.pubSub.ListPeers(settings.Topic), nil
|
||||
}
|
||||
|
||||
func (api *PubSubAPI) Publish(ctx context.Context, topic string, data []byte) error {
|
||||
@ -69,6 +62,9 @@ func (api *PubSubAPI) Publish(ctx context.Context, topic string, data []byte) er
|
||||
|
||||
func (api *PubSubAPI) Subscribe(ctx context.Context, topic string, opts ...caopts.PubSubSubscribeOption) (coreiface.PubSubSubscription, error) {
|
||||
options, err := caopts.PubSubSubscribeOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r, err := api.checkNode()
|
||||
if err != nil {
|
||||
|
||||
@ -23,9 +23,8 @@ type connInfo struct {
|
||||
conn net.Conn
|
||||
dir net.Direction
|
||||
|
||||
addr ma.Multiaddr
|
||||
peer peer.ID
|
||||
muxer string
|
||||
addr ma.Multiaddr
|
||||
peer peer.ID
|
||||
}
|
||||
|
||||
func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
|
||||
@ -83,9 +82,7 @@ func (api *SwarmAPI) KnownAddrs(context.Context) (map[peer.ID][]ma.Multiaddr, er
|
||||
addrs := make(map[peer.ID][]ma.Multiaddr)
|
||||
ps := api.peerHost.Network().Peerstore()
|
||||
for _, p := range ps.Peers() {
|
||||
for _, a := range ps.Addrs(p) {
|
||||
addrs[p] = append(addrs[p], a)
|
||||
}
|
||||
addrs[p] = append(addrs[p], ps.Addrs(p)...)
|
||||
sort.Slice(addrs[p], func(i, j int) bool {
|
||||
return addrs[p][i].String() < addrs[p][j].String()
|
||||
})
|
||||
|
||||
@ -43,7 +43,7 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re
|
||||
depth = ^uint(0)
|
||||
}
|
||||
for strings.HasPrefix(name, "/ipns/") {
|
||||
if depth <= 0 {
|
||||
if depth == 0 {
|
||||
return value, namesys.ErrResolveRecursion
|
||||
}
|
||||
depth--
|
||||
@ -235,9 +235,6 @@ func TestGatewayGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIPNSHostnameRedirect(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
ns := mockNamesys{}
|
||||
ts, api, ctx := newTestServerAndNode(t, ns)
|
||||
t.Logf("test server url: %s", ts.URL)
|
||||
@ -326,9 +323,6 @@ func TestIPNSHostnameRedirect(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIPNSHostnameBacklinks(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
ns := mockNamesys{}
|
||||
ts, api, ctx := newTestServerAndNode(t, ns)
|
||||
t.Logf("test server url: %s", ts.URL)
|
||||
|
||||
@ -20,7 +20,7 @@ func MutexFractionOption(path string) ServeOption {
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
_, _ = w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ func MutexFractionOption(path string) ServeOption {
|
||||
fr, err := strconv.Atoi(asfr)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
_, _ = w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
log.Infof("Setting MutexProfileFraction to %d", fr)
|
||||
|
||||
@ -52,7 +52,9 @@ func TestCheckVersionOption(t *testing.T) {
|
||||
if !tc.shouldHandle {
|
||||
t.Error("handler was called even though version didn't match")
|
||||
} else {
|
||||
io.WriteString(w, "check!")
|
||||
if _, err := io.WriteString(w, "check!"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -40,11 +40,15 @@ func NewGC(n *core.IpfsNode) (*GC, error) {
|
||||
// TODO: there should be a general check for all of the cfg fields
|
||||
// maybe distinguish between user config file and default struct?
|
||||
if cfg.Datastore.StorageMax == "" {
|
||||
r.SetConfigKey("Datastore.StorageMax", "10GB")
|
||||
if err := r.SetConfigKey("Datastore.StorageMax", "10GB"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg.Datastore.StorageMax = "10GB"
|
||||
}
|
||||
if cfg.Datastore.StorageGCWatermark == 0 {
|
||||
r.SetConfigKey("Datastore.StorageGCWatermark", 90)
|
||||
if err := r.SetConfigKey("Datastore.StorageGCWatermark", 90); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg.Datastore.StorageGCWatermark = 90
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ func TestAddGCLive(t *testing.T) {
|
||||
_, err := adder.AddAllAndPin(slf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}()
|
||||
@ -93,7 +93,9 @@ func TestAddGCLive(t *testing.T) {
|
||||
}()
|
||||
|
||||
// gc shouldnt start until we let the add finish its current file.
|
||||
pipew.Write([]byte("some data for file b"))
|
||||
if _, err := pipew.Write([]byte("some data for file b")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-gcstarted:
|
||||
@ -178,7 +180,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) {
|
||||
defer close(adder.Out)
|
||||
_, err = adder.AddAllAndPin(file)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
for range out {
|
||||
@ -227,7 +229,7 @@ func (bs *testBlockstore) PutMany(blocks []blocks.Block) error {
|
||||
return bs.GCBlockstore.PutMany(blocks)
|
||||
}
|
||||
|
||||
func (bs *testBlockstore) CheckForPosInfo(block blocks.Block) error {
|
||||
func (bs *testBlockstore) CheckForPosInfo(block blocks.Block) {
|
||||
fsn, ok := block.(*pi.FilestoreNode)
|
||||
if ok {
|
||||
posInfo := fsn.PosInfo
|
||||
@ -240,7 +242,6 @@ func (bs *testBlockstore) CheckForPosInfo(block blocks.Block) error {
|
||||
bs.countAtOffsetNonZero += 1
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type dummyFileInfo struct {
|
||||
|
||||
@ -3,6 +3,7 @@ package coreunix
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
@ -35,7 +36,10 @@ func TestMetadata(t *testing.T) {
|
||||
// Make some random node
|
||||
ds := getDagserv(t)
|
||||
data := make([]byte, 1000)
|
||||
u.NewTimeSeededRand().Read(data)
|
||||
_, err := io.ReadFull(u.NewTimeSeededRand(), data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := bytes.NewReader(data)
|
||||
nd, err := importer.BuildDagFromReader(ds, chunker.DefaultSplitter(r))
|
||||
if err != nil {
|
||||
|
||||
@ -139,8 +139,8 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e
|
||||
out = append(out, subc)
|
||||
}
|
||||
}
|
||||
cleanA.RemoveNodeLink(l.Name)
|
||||
cleanB.RemoveNodeLink(l.Name)
|
||||
_ = cleanA.RemoveNodeLink(l.Name)
|
||||
_ = cleanB.RemoveNodeLink(l.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@ func (e *Editor) rmLink(ctx context.Context, root *dag.ProtoNode, path []string)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
e.tmp.Remove(ctx, root.Cid())
|
||||
_ = e.tmp.Remove(ctx, root.Cid())
|
||||
|
||||
_ = root.RemoveNodeLink(path[0])
|
||||
err = root.AddNodeLink(path[0], nnode)
|
||||
|
||||
@ -30,11 +30,14 @@ func TestReprovide(t *testing.T) {
|
||||
bstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
|
||||
|
||||
blk := blocks.NewBlock([]byte("this is a test"))
|
||||
bstore.Put(blk)
|
||||
err := bstore.Put(blk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
keyProvider := NewBlockstoreProvider(bstore)
|
||||
reprov := NewReprovider(ctx, clA, keyProvider)
|
||||
err := reprov.Reprovide()
|
||||
err = reprov.Reprovide()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
mrand "math/rand"
|
||||
"os"
|
||||
@ -30,7 +31,10 @@ func maybeSkipFuseTests(t *testing.T) {
|
||||
|
||||
func randBytes(size int) []byte {
|
||||
b := make([]byte, size)
|
||||
u.NewTimeSeededRand().Read(b)
|
||||
_, err := io.ReadFull(u.NewTimeSeededRand(), b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
@ -41,31 +45,18 @@ func mkdir(t *testing.T, path string) {
|
||||
}
|
||||
}
|
||||
|
||||
func writeFile(t *testing.T, size int, path string) []byte {
|
||||
return writeFileData(t, randBytes(size), path)
|
||||
func writeFileOrFail(t *testing.T, size int, path string) []byte {
|
||||
data, err := writeFile(size, path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func writeFileData(t *testing.T, data []byte, path string) []byte {
|
||||
fi, err := os.Create(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
n, err := fi.Write(data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if n != len(data) {
|
||||
t.Fatal("Didnt write proper amount!")
|
||||
}
|
||||
|
||||
err = fi.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return data
|
||||
func writeFile(size int, path string) ([]byte, error) {
|
||||
data := randBytes(size)
|
||||
err := ioutil.WriteFile(path, data, 0666)
|
||||
return data, err
|
||||
}
|
||||
|
||||
func verifyFile(t *testing.T, path string, wantData []byte) {
|
||||
@ -168,7 +159,7 @@ func TestIpnsBasicIO(t *testing.T) {
|
||||
defer closeMount(mnt)
|
||||
|
||||
fname := mnt.Dir + "/local/testfile"
|
||||
data := writeFile(t, 10, fname)
|
||||
data := writeFileOrFail(t, 10, fname)
|
||||
|
||||
rbuf, err := ioutil.ReadFile(fname)
|
||||
if err != nil {
|
||||
@ -198,7 +189,7 @@ func TestFilePersistence(t *testing.T) {
|
||||
node, mnt := setupIpnsTest(t, nil)
|
||||
|
||||
fname := "/local/atestfile"
|
||||
data := writeFile(t, 127, mnt.Dir+fname)
|
||||
data := writeFileOrFail(t, 127, mnt.Dir+fname)
|
||||
|
||||
mnt.Close()
|
||||
|
||||
@ -226,7 +217,7 @@ func TestMultipleDirs(t *testing.T) {
|
||||
checkExists(t, mnt.Dir+dir1)
|
||||
|
||||
t.Log("write a file in it")
|
||||
data1 := writeFile(t, 4000, mnt.Dir+dir1+"/file1")
|
||||
data1 := writeFileOrFail(t, 4000, mnt.Dir+dir1+"/file1")
|
||||
|
||||
verifyFile(t, mnt.Dir+dir1+"/file1", data1)
|
||||
|
||||
@ -236,7 +227,7 @@ func TestMultipleDirs(t *testing.T) {
|
||||
checkExists(t, mnt.Dir+dir1+"/dir2")
|
||||
|
||||
t.Log("file in that subdirectory")
|
||||
data2 := writeFile(t, 5000, mnt.Dir+dir1+"/dir2/file2")
|
||||
data2 := writeFileOrFail(t, 5000, mnt.Dir+dir1+"/dir2/file2")
|
||||
|
||||
verifyFile(t, mnt.Dir+dir1+"/dir2/file2", data2)
|
||||
|
||||
@ -262,7 +253,7 @@ func TestFileSizeReporting(t *testing.T) {
|
||||
defer mnt.Close()
|
||||
|
||||
fname := mnt.Dir + "/local/sizecheck"
|
||||
data := writeFile(t, 5555, fname)
|
||||
data := writeFileOrFail(t, 5555, fname)
|
||||
|
||||
finfo, err := os.Stat(fname)
|
||||
if err != nil {
|
||||
@ -302,7 +293,7 @@ func TestAppendFile(t *testing.T) {
|
||||
defer mnt.Close()
|
||||
|
||||
fname := mnt.Dir + "/local/file"
|
||||
data := writeFile(t, 1300, fname)
|
||||
data := writeFileOrFail(t, 1300, fname)
|
||||
|
||||
fi, err := os.OpenFile(fname, os.O_RDWR|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
@ -360,7 +351,11 @@ func TestConcurrentWrites(t *testing.T) {
|
||||
go func(n int) {
|
||||
defer wg.Done()
|
||||
for j := 0; j < filesPerActor; j++ {
|
||||
out := writeFile(t, fileSize, mnt.Dir+fmt.Sprintf("/local/%dFILE%d", n, j))
|
||||
out, err := writeFile(fileSize, mnt.Dir+fmt.Sprintf("/local/%dFILE%d", n, j))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
data[n][j] = out
|
||||
}
|
||||
}(i)
|
||||
@ -369,6 +364,10 @@ func TestConcurrentWrites(t *testing.T) {
|
||||
|
||||
for i := 0; i < nactors; i++ {
|
||||
for j := 0; j < filesPerActor; j++ {
|
||||
if data[i][j] == nil {
|
||||
// Error already reported.
|
||||
continue
|
||||
}
|
||||
verifyFile(t, mnt.Dir+fmt.Sprintf("/local/%dFILE%d", i, j), data[i][j])
|
||||
}
|
||||
}
|
||||
@ -410,7 +409,8 @@ func TestFSThrash(t *testing.T) {
|
||||
newDir := fmt.Sprintf("%s/dir%d-%d", dir, worker, j)
|
||||
err := os.Mkdir(newDir, os.ModeDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
dirlock.Lock()
|
||||
dirs = append(dirs, newDir)
|
||||
@ -432,7 +432,11 @@ func TestFSThrash(t *testing.T) {
|
||||
|
||||
newFileName := fmt.Sprintf("%s/file%d-%d", dir, worker, j)
|
||||
|
||||
data := writeFile(t, 2000+mrand.Intn(5000), newFileName)
|
||||
data, err := writeFile(2000+mrand.Intn(5000), newFileName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
filelock.Lock()
|
||||
files[newFileName] = data
|
||||
filelock.Unlock()
|
||||
@ -444,11 +448,11 @@ func TestFSThrash(t *testing.T) {
|
||||
for name, data := range files {
|
||||
out, err := ioutil.ReadFile(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(data, out) {
|
||||
t.Fatal("Data didnt match")
|
||||
t.Errorf("Data didnt match in %s: expected %v, got %v", name, data, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ func NewMount(p goprocess.Process, fsys fs.FS, mountpoint string, allow_other bo
|
||||
|
||||
// launch the mounting process.
|
||||
if err := m.mount(); err != nil {
|
||||
m.Unmount() // just in case.
|
||||
_ = m.Unmount() // just in case.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@ -35,10 +35,12 @@ func Mount(node *core.IpfsNode, fsdir, nsdir string) error {
|
||||
// if the user said "Mount", then there must be something wrong.
|
||||
// so, close them and try again.
|
||||
if node.Mounts.Ipfs != nil && node.Mounts.Ipfs.IsActive() {
|
||||
node.Mounts.Ipfs.Unmount()
|
||||
// best effort
|
||||
_ = node.Mounts.Ipfs.Unmount()
|
||||
}
|
||||
if node.Mounts.Ipns != nil && node.Mounts.Ipns.IsActive() {
|
||||
node.Mounts.Ipns.Unmount()
|
||||
// best effort
|
||||
_ = node.Mounts.Ipns.Unmount()
|
||||
}
|
||||
|
||||
if err := platformFuseChecks(node); err != nil {
|
||||
@ -95,10 +97,10 @@ func doMount(node *core.IpfsNode, fsdir, nsdir string) error {
|
||||
|
||||
if err1 != nil || err2 != nil {
|
||||
if fsmount != nil {
|
||||
fsmount.Unmount()
|
||||
_ = fsmount.Unmount()
|
||||
}
|
||||
if nsmount != nil {
|
||||
nsmount.Unmount()
|
||||
_ = nsmount.Unmount()
|
||||
}
|
||||
|
||||
if err1 != nil {
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
@ -41,7 +42,10 @@ func maybeSkipFuseTests(t *testing.T) {
|
||||
|
||||
func randObj(t *testing.T, nd *core.IpfsNode, size int64) (ipld.Node, []byte) {
|
||||
buf := make([]byte, size)
|
||||
u.NewTimeSeededRand().Read(buf)
|
||||
_, err := io.ReadFull(u.NewTimeSeededRand(), buf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
read := bytes.NewReader(buf)
|
||||
obj, err := importer.BuildTrickleDagFromReader(nd.DAG, chunker.DefaultSplitter(read))
|
||||
if err != nil {
|
||||
|
||||
@ -198,7 +198,7 @@ func TestInvalidKeyFiles(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if exist, err = ks.Has(".invalid"); err == nil {
|
||||
if _, err = ks.Has(".invalid"); err == nil {
|
||||
t.Fatal("shouldnt be able to put a key with a 'hidden' name")
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.
|
||||
return err
|
||||
}
|
||||
ttl := DefaultResolverCacheTTL
|
||||
if ttEol := eol.Sub(time.Now()); ttEol < ttl {
|
||||
if ttEol := time.Until(eol); ttEol < ttl {
|
||||
ttl = ttEol
|
||||
}
|
||||
ns.cacheSet(peer.IDB58Encode(id), value, ttl)
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
ci "github.com/libp2p/go-libp2p-crypto"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
pstoremem "github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
||||
record "github.com/libp2p/go-libp2p-record"
|
||||
)
|
||||
|
||||
type mockResolver struct {
|
||||
@ -97,12 +98,18 @@ func TestPublishWithCache0(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
routing := offroute.NewOfflineRouter(dst, ipns.Validator{KeyBook: ps})
|
||||
routing := offroute.NewOfflineRouter(dst, record.NamespacedValidator{
|
||||
"ipns": ipns.Validator{KeyBook: ps},
|
||||
"pk": record.PublicKeyValidator{},
|
||||
})
|
||||
|
||||
nsys := NewNameSystem(routing, dst, 0)
|
||||
p, err := path.ParsePath(unixfs.EmptyDirNode().Cid().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nsys.Publish(context.Background(), priv, p)
|
||||
err = nsys.Publish(context.Background(), priv, p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,9 @@ func TestRepublish(t *testing.T) {
|
||||
nodes = append(nodes, nd)
|
||||
}
|
||||
|
||||
mn.LinkAll()
|
||||
if err := mn.LinkAll(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bsinf := core.BootstrapConfigWithPeers(
|
||||
[]pstore.PeerInfo{
|
||||
|
||||
@ -137,7 +137,7 @@ func (r *IpnsResolver) resolveOnceAsync(ctx context.Context, name string, option
|
||||
case ipns.ErrUnrecognizedValidity:
|
||||
// No EOL.
|
||||
case nil:
|
||||
ttEol := eol.Sub(time.Now())
|
||||
ttEol := time.Until(eol)
|
||||
if ttEol < 0 {
|
||||
// It *was* valid when we first resolved it.
|
||||
ttl = 0
|
||||
|
||||
@ -48,7 +48,7 @@ func (p2p *P2P) ForwardRemote(ctx context.Context, proto protocol.ID, addr ma.Mu
|
||||
func (l *remoteListener) handleStream(remote net.Stream) {
|
||||
local, err := manet.Dial(l.addr)
|
||||
if err != nil {
|
||||
remote.Reset()
|
||||
_ = remote.Reset()
|
||||
return
|
||||
}
|
||||
|
||||
@ -56,14 +56,14 @@ func (l *remoteListener) handleStream(remote net.Stream) {
|
||||
|
||||
if l.reportRemote {
|
||||
if _, err := fmt.Fprintf(local, "%s\n", peer.Pretty()); err != nil {
|
||||
remote.Reset()
|
||||
_ = remote.Reset()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
peerMa, err := ma.NewMultiaddr(maPrefix + peer.Pretty())
|
||||
if err != nil {
|
||||
remote.Reset()
|
||||
_ = remote.Reset()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -31,15 +31,13 @@ type Stream struct {
|
||||
}
|
||||
|
||||
// close stream endpoints and deregister it
|
||||
func (s *Stream) close() error {
|
||||
func (s *Stream) close() {
|
||||
s.Registry.Close(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
// reset closes stream endpoints and deregisters it
|
||||
func (s *Stream) reset() error {
|
||||
func (s *Stream) reset() {
|
||||
s.Registry.Reset(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Stream) startStreaming() {
|
||||
@ -108,17 +106,15 @@ func (r *StreamRegistry) Deregister(streamID uint64) {
|
||||
}
|
||||
|
||||
// Close stream endpoints and deregister it
|
||||
func (r *StreamRegistry) Close(s *Stream) error {
|
||||
s.Local.Close()
|
||||
s.Remote.Close()
|
||||
func (r *StreamRegistry) Close(s *Stream) {
|
||||
_ = s.Local.Close()
|
||||
_ = s.Remote.Close()
|
||||
s.Registry.Deregister(s.id)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset closes stream endpoints and deregisters it
|
||||
func (r *StreamRegistry) Reset(s *Stream) error {
|
||||
s.Local.Close()
|
||||
s.Remote.Reset()
|
||||
func (r *StreamRegistry) Reset(s *Stream) {
|
||||
_ = s.Local.Close()
|
||||
_ = s.Remote.Reset()
|
||||
s.Registry.Deregister(s.id)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package pin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -21,7 +22,10 @@ var rand = util.NewTimeSeededRand()
|
||||
func randNode() (*mdag.ProtoNode, cid.Cid) {
|
||||
nd := new(mdag.ProtoNode)
|
||||
nd.SetData(make([]byte, 32))
|
||||
rand.Read(nd.Data())
|
||||
_, err := io.ReadFull(rand, nd.Data())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
k := nd.Cid()
|
||||
return nd, k
|
||||
}
|
||||
@ -111,11 +115,11 @@ func TestPinnerBasic(t *testing.T) {
|
||||
assertPinned(t, p, bk, "Recursively pinned node not found..")
|
||||
|
||||
d, _ := randNode()
|
||||
d.AddNodeLink("a", a)
|
||||
d.AddNodeLink("c", c)
|
||||
_ = d.AddNodeLink("a", a)
|
||||
_ = d.AddNodeLink("c", c)
|
||||
|
||||
e, _ := randNode()
|
||||
d.AddNodeLink("e", e)
|
||||
_ = d.AddNodeLink("e", e)
|
||||
|
||||
// Must be in dagserv for unpin to work
|
||||
err = dserv.Add(ctx, e)
|
||||
@ -385,8 +389,12 @@ func TestPinUpdate(t *testing.T) {
|
||||
n1, c1 := randNode()
|
||||
n2, c2 := randNode()
|
||||
|
||||
dserv.Add(ctx, n1)
|
||||
dserv.Add(ctx, n2)
|
||||
if err := dserv.Add(ctx, n1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := dserv.Add(ctx, n2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := p.Pin(ctx, n1, true); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@ -115,7 +115,7 @@ func (loader *PluginLoader) Start(iface coreiface.CoreAPI) error {
|
||||
if pl, ok := pl.(plugin.PluginDaemon); ok {
|
||||
err := pl.Start(iface)
|
||||
if err != nil {
|
||||
closePlugins(loader.plugins[i:])
|
||||
_ = closePlugins(loader.plugins[i:])
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,11 +62,6 @@ func (q *Queue) Dequeue() <-chan cid.Cid {
|
||||
return q.dequeue
|
||||
}
|
||||
|
||||
type entry struct {
|
||||
cid cid.Cid
|
||||
key datastore.Key
|
||||
}
|
||||
|
||||
// Look for next Cid in the queue and return it. Skip over gaps and mangled data
|
||||
func (q *Queue) nextEntry() (datastore.Key, cid.Cid) {
|
||||
for {
|
||||
@ -91,6 +86,9 @@ func (q *Queue) nextEntry() (datastore.Key, cid.Cid) {
|
||||
log.Warningf("Error marshalling Cid from queue: ", err)
|
||||
q.head++
|
||||
err = q.ds.Delete(key)
|
||||
if err != nil {
|
||||
log.Warningf("Provider queue failed to delete: %s", key)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -99,6 +99,9 @@ func TestMangledData(t *testing.T) {
|
||||
|
||||
// remove entries in the middle
|
||||
err = queue.ds.Put(queue.queueKey(5), []byte("borked"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := append(cids[:5], cids[6:]...)
|
||||
assertOrdered(expected, queue, t)
|
||||
|
||||
@ -80,7 +80,10 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
random.WritePseudoRandomBytes(amount, f, seed)
|
||||
if err := random.WritePseudoRandomBytes(amount, f, seed); err != nil {
|
||||
benchmarkError = err
|
||||
b.Fatal(err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
benchmarkError = err
|
||||
b.Fatal(err)
|
||||
@ -95,8 +98,10 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
|
||||
benchmarkError = err
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer daemonCmd.Wait()
|
||||
defer daemonCmd.Process.Signal(os.Interrupt)
|
||||
defer func() {
|
||||
_ = daemonCmd.Process.Signal(os.Interrupt)
|
||||
_ = daemonCmd.Wait()
|
||||
}()
|
||||
}
|
||||
|
||||
b.StartTimer()
|
||||
|
||||
@ -62,7 +62,10 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
random.WritePseudoRandomBytes(amount, f, seed)
|
||||
err = random.WritePseudoRandomBytes(amount, f, seed)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
@ -81,12 +81,15 @@ func app() int {
|
||||
defer conn.Close()
|
||||
switch mode {
|
||||
case "recv":
|
||||
io.Copy(os.Stdout, conn)
|
||||
_, err = io.Copy(os.Stdout, conn)
|
||||
case "send":
|
||||
io.Copy(conn, os.Stdin)
|
||||
_, err = io.Copy(conn, os.Stdin)
|
||||
default:
|
||||
return 1
|
||||
}
|
||||
if err != nil {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@ -84,8 +84,11 @@ func AddCatPowers(conf testutil.LatencyConfig, megabytesMax int64) error {
|
||||
}
|
||||
|
||||
func RandomBytes(n int64) []byte {
|
||||
data := new(bytes.Buffer)
|
||||
random.WritePseudoRandomBytes(n, data, kSeed)
|
||||
var data bytes.Buffer
|
||||
err := random.WritePseudoRandomBytes(n, &data, kSeed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return data.Bytes()
|
||||
}
|
||||
|
||||
@ -155,13 +158,15 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
|
||||
}
|
||||
|
||||
// verify
|
||||
bufout := new(bytes.Buffer)
|
||||
io.Copy(bufout, readerCatted.(io.Reader))
|
||||
if 0 != bytes.Compare(bufout.Bytes(), data) {
|
||||
var bufout bytes.Buffer
|
||||
_, err = io.Copy(&bufout, readerCatted.(io.Reader))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(bufout.Bytes(), data) {
|
||||
return errors.New("catted data does not match added data")
|
||||
}
|
||||
|
||||
cancel()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -102,9 +102,12 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
|
||||
}
|
||||
|
||||
// verify
|
||||
bufout := new(bytes.Buffer)
|
||||
io.Copy(bufout, readerCatted.(io.Reader))
|
||||
if 0 != bytes.Compare(bufout.Bytes(), data) {
|
||||
var bufout bytes.Buffer
|
||||
_, err = io.Copy(&bufout, readerCatted.(io.Reader))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(bufout.Bytes(), data) {
|
||||
return errors.New("catted data does not match added data")
|
||||
}
|
||||
return nil
|
||||
|
||||
@ -35,7 +35,10 @@ func TestBitswapWithoutRouting(t *testing.T) {
|
||||
nodes = append(nodes, n)
|
||||
}
|
||||
|
||||
mn.LinkAll()
|
||||
err := mn.LinkAll()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// connect them
|
||||
for _, n1 := range nodes {
|
||||
|
||||
@ -112,7 +112,10 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
mn.LinkAll()
|
||||
err = mn.LinkAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
|
||||
bcfg := core.BootstrapConfigWithPeers([]pstore.PeerInfo{bis})
|
||||
@ -134,11 +137,13 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
|
||||
}
|
||||
|
||||
// verify
|
||||
bufout := new(bytes.Buffer)
|
||||
io.Copy(bufout, readerCatted.(io.Reader))
|
||||
if 0 != bytes.Compare(bufout.Bytes(), data) {
|
||||
var bufout bytes.Buffer
|
||||
_, err = io.Copy(&bufout, readerCatted.(io.Reader))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(bufout.Bytes(), data) {
|
||||
return errors.New("catted data does not match added data")
|
||||
}
|
||||
cancel()
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user