@cryptotaxi247 / kubo / commits / c5df8f079

apply the megacheck tool to improve code quality

License: MIT Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>

zramsay committed May 31, 2017 at 16:56 UTC c5df8f0796fa5bc252f3311deb03eccf0266f546
76 files changed +179 -377
blocks/blocks_test.go
+1 -2
@@ -91,9 +91,8 @@ func TestManualHash(t *testing.T) {
91
92 u.Debug = true
93
94 - block, err = NewBlockWithCid(data, c)
94 + _, err = NewBlockWithCid(data, c)
95 if err != ErrWrongHash {
96 t.Fatal(err)
97 }
98 -
98 }
blocks/blockstore/arc_cache_test.go
+1 -1
@@ -30,7 +30,7 @@ func testArcCached(ctx context.Context, bs Blockstore) (*arccache, error) {
30 func createStores(t *testing.T) (*arccache, Blockstore, *callbackDatastore) {
31 cd := &callbackDatastore{f: func() {}, ds: ds.NewMapDatastore()}
32 bs := NewBlockstore(syncds.MutexWrap(cd))
33 - arc, err := testArcCached(nil, bs)
33 + arc, err := testArcCached(context.TODO(), bs)
34 if err != nil {
35 t.Fatal(err)
36 }
blocks/blockstore/bloom_cache.go
+1 -1
@@ -118,7 +118,7 @@ func (b *bloomcache) hasCached(k *cid.Cid) (has bool, ok bool) {
118 }
119 if b.BloomActive() {
120 blr := b.bloom.HasTS(k.Bytes())
121 - if blr == false { // not contained in bloom is only conclusive answer bloom gives
121 + if !blr { // not contained in bloom is only conclusive answer bloom gives
122 b.hits.Inc()
123 return false, true
124 }
blocks/blockstore/bloom_cache_test.go
+5 -2
@@ -34,6 +34,9 @@ func TestPutManyAddsToBloom(t *testing.T) {
34 defer cancel()
35
36 cachedbs, err := testBloomCached(ctx, bs)
37 + if err != nil {
38 + t.Fatal(err)
39 + }
40
41 select {
42 case <-cachedbs.rebuildChan:
@@ -49,7 +52,7 @@ func TestPutManyAddsToBloom(t *testing.T) {
52 if err != nil {
53 t.Fatal(err)
54 }
52 - if has == false {
55 + if !has {
56 t.Fatal("added block is reported missing")
57 }
58
@@ -57,7 +60,7 @@ func TestPutManyAddsToBloom(t *testing.T) {
60 if err != nil {
61 t.Fatal(err)
62 }
60 - if has == true {
63 + if has {
64 t.Fatal("not added block is reported to be in blockstore")
65 }
66 }
blocks/blockstore/caching_test.go
+8 -5
@@ -1,26 +1,29 @@
1 package blockstore
2
3 -import "testing"
3 +import (
4 + "context"
5 + "testing"
6 +)
7
8 func TestCachingOptsLessThanZero(t *testing.T) {
9 opts := DefaultCacheOpts()
10 opts.HasARCCacheSize = -1
11
9 - if _, err := CachedBlockstore(nil, nil, opts); err == nil {
12 + if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
13 t.Error("wrong ARC setting was not detected")
14 }
15
16 opts = DefaultCacheOpts()
17 opts.HasBloomFilterSize = -1
18
16 - if _, err := CachedBlockstore(nil, nil, opts); err == nil {
19 + if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
20 t.Error("negative bloom size was not detected")
21 }
22
23 opts = DefaultCacheOpts()
24 opts.HasBloomFilterHashes = -1
25
23 - if _, err := CachedBlockstore(nil, nil, opts); err == nil {
26 + if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
27 t.Error("negative hashes setting was not detected")
28 }
29 }
@@ -29,7 +32,7 @@ func TestBloomHashesAtZero(t *testing.T) {
32 opts := DefaultCacheOpts()
33 opts.HasBloomFilterHashes = 0
34
32 - if _, err := CachedBlockstore(nil, nil, opts); err == nil {
35 + if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
36 t.Error("zero hashes setting with positive size was not detected")
37 }
38 }
blocks/set/set.go
-3
@@ -4,14 +4,11 @@
4 package set
5
6 import (
7 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
7 cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
8
9 "github.com/ipfs/go-ipfs/blocks/bloom"
10 )
11
13 -var log = logging.Logger("blockset")
14 -
12 // BlockSet represents a mutable set of blocks CIDs.
13 type BlockSet interface {
14 AddBlock(*cid.Cid)
blocks/set/set_test.go
+4 -4
@@ -25,15 +25,15 @@ func exampleKeys() []*cid.Cid {
25 func checkSet(set BlockSet, keySlice []*cid.Cid, t *testing.T) {
26 for i, key := range keySlice {
27 if i&tReAdd == 0 {
28 - if set.HasKey(key) == false {
28 + if !set.HasKey(key) {
29 t.Error("key should be in the set")
30 }
31 } else if i&tRemove == 0 {
32 - if set.HasKey(key) == true {
32 + if set.HasKey(key) {
33 t.Error("key shouldn't be in the set")
34 }
35 } else if i&tAdd == 0 {
36 - if set.HasKey(key) == false {
36 + if !set.HasKey(key) {
37 t.Error("key should be in the set")
38 }
39 }
@@ -70,7 +70,7 @@ func TestSetWorks(t *testing.T) {
70 bloom := set.GetBloomFilter()
71
72 for _, key := range addedKeys {
73 - if bloom.Find(key.Bytes()) == false {
73 + if !bloom.Find(key.Bytes()) {
74 t.Error("bloom doesn't contain expected key")
75 }
76 }
blockservice/blockservice.go
+1 -1
@@ -172,7 +172,7 @@ func (s *blockService) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block,
172 // the returned channel.
173 // NB: No guarantees are made about order.
174 func (s *blockService) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block {
175 - out := make(chan blocks.Block, 0)
175 + out := make(chan blocks.Block)
176 go func() {
177 defer close(out)
178 var misses []*cid.Cid
cmd/ipfs/daemon.go
+3 -6
@@ -201,11 +201,9 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
201 ctx := req.InvocContext()
202
203 go func() {
204 - select {
205 - case <-req.Context().Done():
206 - fmt.Println("Received interrupt signal, shutting down...")
207 - fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
208 - }
204 + <-req.Context().Done()
205 + fmt.Println("Received interrupt signal, shutting down...")
206 + fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
207 }()
208
209 // check transport encryption flag.
@@ -418,7 +416,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
416 res.SetError(err, cmds.ErrNormal)
417 }
418 }
421 - return
419 }
420
421 // serveHTTPApi collects options, creates listener, prints status message and starts serving requests
cmd/ipfs/ipfs.go
+4 -11
@@ -44,12 +44,6 @@ func init() {
44 }
45 }
46
47 -// isLocal returns true if the command should only be run locally (not sent to daemon), otherwise false
48 -func isLocal(cmd *cmds.Command) bool {
49 - _, found := localMap[cmd]
50 - return found
51 -}
52 -
47 // NB: when necessary, properties are described using negatives in order to
48 // provide desirable defaults
49 type cmdDetails struct {
@@ -85,11 +79,10 @@ func (d *cmdDetails) Loggable() map[string]interface{} {
79 }
80 }
81
88 -func (d *cmdDetails) usesConfigAsInput() bool { return !d.doesNotUseConfigAsInput }
89 -func (d *cmdDetails) doesNotPreemptAutoUpdate() bool { return !d.preemptsAutoUpdate }
90 -func (d *cmdDetails) canRunOnClient() bool { return !d.cannotRunOnClient }
91 -func (d *cmdDetails) canRunOnDaemon() bool { return !d.cannotRunOnDaemon }
92 -func (d *cmdDetails) usesRepo() bool { return !d.doesNotUseRepo }
82 +func (d *cmdDetails) usesConfigAsInput() bool { return !d.doesNotUseConfigAsInput }
83 +func (d *cmdDetails) canRunOnClient() bool { return !d.cannotRunOnClient }
84 +func (d *cmdDetails) canRunOnDaemon() bool { return !d.cannotRunOnDaemon }
85 +func (d *cmdDetails) usesRepo() bool { return !d.doesNotUseRepo }
86
87 // "What is this madness!?" you ask. Our commands have the unfortunate problem of
88 // not being able to run on all the same contexts. This map describes these
cmd/ipfs/main.go
+6 -6
@@ -38,16 +38,16 @@ import (
38 var log = logging.Logger("cmd/ipfs")
39
40 var (
41 - errUnexpectedApiOutput = errors.New("api returned unexpected output")
42 - errApiVersionMismatch = errors.New("api version mismatch")
43 - errRequestCanceled = errors.New("request canceled")
41 + // errUnexpectedApiOutput = errors.New("api returned unexpected output")
42 + // errApiVersionMismatch = errors.New("api version mismatch")
43 + errRequestCanceled = errors.New("request canceled")
44 )
45
46 const (
47 EnvEnableProfiling = "IPFS_PROF"
48 cpuProfile = "ipfs.cpuprof"
49 heapProfile = "ipfs.memprof"
50 - errorFormat = "ERROR: %v\n\n"
50 + // errorFormat = "ERROR: %v\n\n"
51 )
52
53 type cmdInvocation struct {
@@ -492,7 +492,7 @@ func startProfiling() (func(), error) {
492 }
493 pprof.StartCPUProfile(ofi)
494 go func() {
495 - for _ = range time.NewTicker(time.Second * 30).C {
495 + for range time.NewTicker(time.Second * 30).C {
496 err := writeHeapProfileToFile()
497 if err != nil {
498 log.Error(err)
@@ -546,7 +546,7 @@ func (ih *IntrHandler) Handle(handler func(count int, ih *IntrHandler), sigs ...
546 go func() {
547 defer ih.wg.Done()
548 count := 0
549 - for _ = range ih.sig {
549 + for range ih.sig {
550 count++
551 handler(count, ih)
552 }
cmd/ipfswatch/main.go
+3 -5
@@ -7,6 +7,7 @@ import (
7 "os"
8 "os/signal"
9 "path/filepath"
10 + "syscall"
11
12 commands "github.com/ipfs/go-ipfs/commands"
13 core "github.com/ipfs/go-ipfs/core"
@@ -99,7 +100,7 @@ func run(ipfsPath, watchPath string) error {
100 }
101
102 interrupts := make(chan os.Signal)
102 - signal.Notify(interrupts, os.Interrupt, os.Kill)
103 + signal.Notify(interrupts, os.Interrupt, syscall.SIGTERM)
104
105 for {
106 select {
@@ -167,10 +168,7 @@ func addTree(w *fsnotify.Watcher, root string) error {
168 }
169 return nil
170 })
170 - if err != nil {
171 - return err
172 - }
173 - return nil
171 + return err
172 }
173
174 func IsDirectory(path string) (bool, error) {
commands/cli/helptext.go
+1 -13
@@ -16,9 +16,6 @@ const (
16 variadicArg = "%v..."
17 shortFlag = "-%v"
18 longFlag = "--%v"
19 - optionType = "(%v)"
20 -
21 - whitespace = "\r\n\t "
19
20 indentStr = " "
21 )
@@ -295,9 +292,7 @@ func optionText(cmd ...*cmds.Command) []string {
292 // get a slice of the options we want to list out
293 options := make([]cmds.Option, 0)
294 for _, c := range cmd {
298 - for _, opt := range c.Options {
299 - options = append(options, opt)
300 - }
295 + options = append(options, c.Options...)
296 }
297
298 // add option names to output (with each name aligned)
@@ -427,13 +422,6 @@ func align(lines []string) []string {
422 return lines
423 }
424
430 -func indent(lines []string, prefix string) []string {
431 - for i, line := range lines {
432 - lines[i] = prefix + indentString(line, prefix)
433 - }
434 - return lines
435 -}
436 -
425 func indentString(line string, prefix string) string {
426 return prefix + strings.Replace(line, "\n", "\n"+prefix, -1)
427 }
commands/cli/parse.go
+1 -4
@@ -59,11 +59,8 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
59 }
60
61 err = cmd.CheckArguments(req)
62 - if err != nil {
63 - return req, cmd, path, err
64 - }
62
66 - return req, cmd, path, nil
63 + return req, cmd, path, err
64 }
65
66 func ParseArgs(req cmds.Request, inputs []string, stdin *os.File, argDefs []cmds.Argument, root *cmds.Command) ([]string, []files.File, error) {
commands/cli/parse_test.go
+1 -1
@@ -204,7 +204,7 @@ func TestArgumentParsing(t *testing.T) {
204
205 test := func(cmd words, f *os.File, res words) {
206 if f != nil {
207 - if _, err := f.Seek(0, os.SEEK_SET); err != nil {
207 + if _, err := f.Seek(0, io.SeekStart); err != nil {
208 t.Fatal(err)
209 }
210 }
commands/command_test.go
-1
@@ -3,7 +3,6 @@ package commands
3 import "testing"
4
5 func noop(req Request, res Response) {
6 - return
6 }
7
8 func TestOptionValidation(t *testing.T) {
commands/files/multipartfile.go
+1 -1
@@ -10,7 +10,7 @@ import (
10
11 const (
12 multipartFormdataType = "multipart/form-data"
13 - multipartMixedType = "multipart/mixed"
13 + // multipartMixedType = "multipart/mixed"
14
15 applicationDirectory = "application/x-directory"
16 applicationSymlink = "application/symlink"
commands/http/handler.go
+6 -6
@@ -47,12 +47,12 @@ const (
47 extraContentLengthHeader = "X-Content-Length"
48 uaHeader = "User-Agent"
49 contentTypeHeader = "Content-Type"
50 - contentDispHeader = "Content-Disposition"
51 - transferEncodingHeader = "Transfer-Encoding"
52 - applicationJson = "application/json"
53 - applicationOctetStream = "application/octet-stream"
54 - plainText = "text/plain"
55 - originHeader = "origin"
50 + // contentDispHeader = "Content-Disposition"
51 + // transferEncodingHeader = "Transfer-Encoding"
52 + applicationJson = "application/json"
53 + applicationOctetStream = "application/octet-stream"
54 + plainText = "text/plain"
55 + // originHeader = "origin"
56 )
57
58 var AllowedExposedHeadersArr = []string{streamHeader, channelHeader, extraContentLengthHeader}
core/bootstrap.go
+1 -4
@@ -147,10 +147,7 @@ func bootstrapRound(ctx context.Context, host host.Host, cfg BootstrapConfig) er
147
148 defer log.EventBegin(ctx, "bootstrapStart", id).Done()
149 log.Debugf("%s bootstrapping to %d nodes: %s", id, numToDial, randSubset)
150 - if err := bootstrapConnect(ctx, host, randSubset); err != nil {
151 - return err
152 - }
153 - return nil
150 + return bootstrapConnect(ctx, host, randSubset)
151 }
152
153 func bootstrapConnect(ctx context.Context, ph host.Host, peers []pstore.PeerInfo) error {
core/builder.go
+2 -6
@@ -65,6 +65,7 @@ func (cfg *BuildCfg) fillDefaults() error {
65 if cfg.Repo == nil {
66 var d ds.Datastore
67 d = ds.NewMapDatastore()
68 +
69 if cfg.NilRepo {
70 d = ds.NewNullDatastore()
71 }
@@ -230,10 +231,5 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
231 }
232 n.Resolver = path.NewBasicResolver(n.DAG)
233
233 - err = n.loadFilesRoot()
234 - if err != nil {
235 - return err
236 - }
237 -
238 - return nil
234 + return n.loadFilesRoot()
235 }
core/commands/active.go
+1 -1
@@ -70,7 +70,7 @@ Lists running and recently run commands.
70
71 var live time.Duration
72 if req.Active {
73 - live = time.Now().Sub(req.StartTime)
73 + live = time.Since(req.StartTime)
74 } else {
75 live = req.EndTime.Sub(req.StartTime)
76 }
core/commands/block.go
+1 -4
@@ -288,10 +288,7 @@ It takes a list of base58 encoded multihashs to remove.
288 }
289
290 err := util.ProcRmOutput(outChan, res.Stdout(), res.Stderr())
291 - if err != nil {
292 - return nil, err
293 - }
294 - return nil, nil
291 + return nil, err
292 },
293 },
294 Type: util.RemovedBlock{},
core/commands/bootstrap.go
-1
@@ -315,7 +315,6 @@ var bootstrapListCmd = &cmds.Command{
315 return
316 }
317 res.SetOutput(&BootstrapOutput{config.BootstrapPeerStrings(peers)})
318 - return
318 },
319 Type: BootstrapOutput{},
320 Marshalers: cmds.MarshalerMap{
core/commands/files/files.go
+2 -2
@@ -472,7 +472,7 @@ Examples:
472 return
473 }
474
475 - _, err = rfd.Seek(int64(offset), os.SEEK_SET)
475 + _, err = rfd.Seek(int64(offset), io.SeekStart)
476 if err != nil {
477 res.SetError(err, cmds.ErrNormal)
478 return
@@ -651,7 +651,7 @@ stat' on the file or any of its ancestors.
651 return
652 }
653
654 - _, err = wfd.Seek(int64(offset), os.SEEK_SET)
654 + _, err = wfd.Seek(int64(offset), io.SeekStart)
655 if err != nil {
656 log.Error("seekfail: ", err)
657 res.SetError(err, cmds.ErrNormal)
core/commands/swarm.go
+4
@@ -676,6 +676,10 @@ remove your filters from the ipfs config file.
676 }
677
678 removed, err := filtersRemove(r, cfg, req.Arguments())
679 + if err != nil {
680 + res.SetError(err, cmds.ErrNormal)
681 + return
682 + }
683
684 res.SetOutput(&stringList{removed})
685 },
core/core.go
+3 -7
@@ -73,7 +73,8 @@ import (
73 )
74
75 const IpnsValidatorTag = "ipns"
76 -const kSizeBlockstoreWriteCache = 100
76 +
77 +// const kSizeBlockstoreWriteCache = 100
78 const kReprovideFrequency = time.Hour * 12
79 const discoveryConnTimeout = time.Second * 30
80
@@ -341,12 +342,7 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
342 n.Namesys = namesys.NewNameSystem(n.Routing, n.Repo.Datastore(), size)
343
344 // setup ipns republishing
344 - err = n.setupIpnsRepublisher()
345 - if err != nil {
346 - return err
347 - }
348 -
349 - return nil
345 + return n.setupIpnsRepublisher()
346 }
347
348 // getCacheSize returns cache life and cache size
core/corehttp/gateway_test.go
-5
@@ -427,11 +427,6 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
427 req.Host = "example.net"
428 req.Header.Set("X-Ipfs-Gateway-Prefix", "/bad-prefix")
429
430 - res, err = doWithoutRedirect(req)
431 - if err != nil {
432 - t.Fatal(err)
433 - }
434 -
430 // make request to directory listing with evil prefix
431 req, err = http.NewRequest("GET", ts.URL, nil)
432 if err != nil {
core/corerouting/core.go
+4 -4
@@ -19,10 +19,10 @@ import (
19 // the core if it's going to be the default)
20
21 var (
22 - errHostMissing = errors.New("supernode routing client requires a Host component")
23 - errIdentityMissing = errors.New("supernode routing server requires a peer ID identity")
24 - errPeerstoreMissing = errors.New("supernode routing server requires a peerstore")
25 - errServersMissing = errors.New("supernode routing client requires at least 1 server peer")
22 + // errHostMissing = errors.New("supernode routing client requires a Host component")
23 + // errIdentityMissing = errors.New("supernode routing server requires a peer ID identity")
24 + // errPeerstoreMissing = errors.New("supernode routing server requires a peerstore")
25 + errServersMissing = errors.New("supernode routing client requires at least 1 server peer")
26 )
27
28 // SupernodeServer returns a configuration for a routing server that stores
core/coreunix/add_test.go
+4 -8
@@ -120,14 +120,10 @@ func TestAddGCLive(t *testing.T) {
120 pipew.Close()
121
122 // receive next object from adder
123 - select {
124 - case o := <-out:
125 - addedHashes[o.(*AddedObject).Hash] = struct{}{}
126 - }
123 + o := <-out
124 + addedHashes[o.(*AddedObject).Hash] = struct{}{}
125
128 - select {
129 - case <-gcstarted:
130 - }
126 + <-gcstarted
127
128 for r := range gcout {
129 if r.Error != nil {
@@ -197,7 +193,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) {
193 t.Fatal(err)
194 }
195 }()
200 - for _ = range adder.Out {
196 + for range adder.Out {
197 }
198
199 exp := 0
exchange/bitswap/bitswap.go
+3 -3
@@ -37,9 +37,9 @@ const (
37 // TODO: if a 'non-nice' strategy is implemented, consider increasing this value
38 maxProvidersPerRequest = 3
39 providerRequestTimeout = time.Second * 10
40 - hasBlockTimeout = time.Second * 15
41 - provideTimeout = time.Second * 15
42 - sizeBatchRequestChan = 32
40 + // hasBlockTimeout = time.Second * 15
41 + provideTimeout = time.Second * 15
42 + sizeBatchRequestChan = 32
43 // kMaxPriority is the max priority as defined by the bitswap protocol
44 kMaxPriority = math.MaxInt32
45 )
exchange/bitswap/bitswap_test.go
+1 -11
@@ -199,7 +199,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
199 if err != nil {
200 errs <- err
201 }
202 - for _ = range outch {
202 + for range outch {
203 }
204 }(inst)
205 }
@@ -226,16 +226,6 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
226 }
227 }
228
229 -func getOrFail(bitswap Instance, b blocks.Block, t *testing.T, wg *sync.WaitGroup) {
230 - if _, err := bitswap.Blockstore().Get(b.Cid()); err != nil {
231 - _, err := bitswap.Exchange.GetBlock(context.Background(), b.Cid())
232 - if err != nil {
233 - t.Fatal(err)
234 - }
235 - }
236 - wg.Done()
237 -}
238 -
229 // TODO simplify this test. get to the _essence_!
230 func TestSendToWantingPeer(t *testing.T) {
231 if testing.Short() {
exchange/bitswap/message/message.go
+2 -8
@@ -220,19 +220,13 @@ func (m *impl) ToProtoV1() *pb.Message {
220 func (m *impl) ToNetV0(w io.Writer) error {
221 pbw := ggio.NewDelimitedWriter(w)
222
223 - if err := pbw.WriteMsg(m.ToProtoV0()); err != nil {
224 - return err
225 - }
226 - return nil
223 + return pbw.WriteMsg(m.ToProtoV0())
224 }
225
226 func (m *impl) ToNetV1(w io.Writer) error {
227 pbw := ggio.NewDelimitedWriter(w)
228
232 - if err := pbw.WriteMsg(m.ToProtoV1()); err != nil {
233 - return err
234 - }
235 - return nil
229 + return pbw.WriteMsg(m.ToProtoV1())
230 }
231
232 func (m *impl) Loggable() map[string]interface{} {
exchange/bitswap/testutils.go
+2 -2
@@ -88,8 +88,8 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
88 // just a much better idea.
89 func Session(ctx context.Context, net tn.Network, p testutil.Identity) Instance {
90 bsdelay := delay.Fixed(0)
91 - const bloomSize = 512
92 - const writeCacheElems = 100
91 + // const bloomSize = 512
92 + // const writeCacheElems = 100
93
94 adapter := net.Adapter(p)
95 dstore := ds_sync.MutexWrap(datastore2.WithDelay(ds.NewMapDatastore(), bsdelay))
exchange/bitswap/wantmanager.go
+2 -2
@@ -55,7 +55,7 @@ func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantMana
55 }
56 }
57
58 -type msgPair struct {
58 +/*type msgPair struct {
59 to peer.ID
60 msg bsmsg.BitSwapMessage
61 }
@@ -63,7 +63,7 @@ type msgPair struct {
63 type cancellation struct {
64 who peer.ID
65 blk *cid.Cid
66 -}
66 +}*/
67
68 type msgQueue struct {
69 p peer.ID
exchange/offline/offline.go
+1 -1
@@ -42,7 +42,7 @@ func (_ *offlineExchange) Close() error {
42 }
43
44 func (e *offlineExchange) GetBlocks(ctx context.Context, ks []*cid.Cid) (<-chan blocks.Block, error) {
45 - out := make(chan blocks.Block, 0)
45 + out := make(chan blocks.Block)
46 go func() {
47 defer close(out)
48 var misses []*cid.Cid
exchange/offline/offline_test.go
+1 -1
@@ -67,7 +67,7 @@ func TestGetBlocks(t *testing.T) {
67 }
68
69 var count int
70 - for _ = range received {
70 + for range received {
71 count++
72 }
73 if len(expected) != count {
filestore/fsrefstore.go
+1 -1
@@ -162,7 +162,7 @@ func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
162 }
163 defer fi.Close()
164
165 - _, err = fi.Seek(int64(d.GetOffset()), os.SEEK_SET)
165 + _, err = fi.Seek(int64(d.GetOffset()), io.SeekStart)
166 if err != nil {
167 return nil, &CorruptReferenceError{StatusFileError, err}
168 }
fuse/ipns/common.go
+1 -4
@@ -33,9 +33,6 @@ func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
33 }
34
35 pub := nsys.NewRoutingPublisher(n.Routing, n.Repo.Datastore())
36 - if err := pub.Publish(ctx, key, path.FromCid(nodek)); err != nil {
37 - return err
38 - }
36
40 - return nil
37 + return pub.Publish(ctx, key, path.FromCid(nodek))
38 }
fuse/ipns/ipns_test.go
+1 -1
@@ -198,7 +198,7 @@ func TestFilePersistence(t *testing.T) {
198 mnt.Close()
199
200 t.Log("Closed, opening new fs")
201 - node, mnt = setupIpnsTest(t, node)
201 + _, mnt = setupIpnsTest(t, node)
202 defer mnt.Close()
203
204 rbuf, err := ioutil.ReadFile(mnt.Dir + fname)
fuse/ipns/ipns_unix.go
+3 -2
@@ -8,6 +8,7 @@ import (
8 "context"
9 "errors"
10 "fmt"
11 + "io"
12 "os"
13
14 core "github.com/ipfs/go-ipfs/core"
@@ -346,7 +347,7 @@ func (dir *Directory) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
347 }
348
349 func (fi *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
349 - _, err := fi.fi.Seek(req.Offset, os.SEEK_SET)
350 + _, err := fi.fi.Seek(req.Offset, io.SeekStart)
351 if err != nil {
352 return err
353 }
@@ -473,7 +474,7 @@ func (fi *FileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.
474 return nil, fuse.ENOTSUP
475 }
476
476 - _, err := fd.Seek(0, os.SEEK_END)
477 + _, err := fd.Seek(0, io.SeekEnd)
478 if err != nil {
479 log.Error("seek reset failed: ", err)
480 return nil, err
fuse/node/mount_unix.go
+1 -6
@@ -49,12 +49,7 @@ func Mount(node *core.IpfsNode, fsdir, nsdir string) error {
49 return err
50 }
51
52 - var err error
53 - if err = doMount(node, fsdir, nsdir); err != nil {
54 - return err
55 - }
56 -
57 - return nil
52 + return doMount(node, fsdir, nsdir)
53 }
54
55 func doMount(node *core.IpfsNode, fsdir, nsdir string) error {
fuse/readonly/readonly_unix.go
+1 -1
@@ -190,7 +190,7 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
190 if err != nil {
191 return err
192 }
193 - o, err := r.Seek(req.Offset, os.SEEK_SET)
193 + o, err := r.Seek(req.Offset, io.SeekStart)
194 lm["res_offset"] = o
195 if err != nil {
196 return err
importer/balanced/balanced_test.go
+7 -14
@@ -6,7 +6,6 @@ import (
6 "io"
7 "io/ioutil"
8 mrand "math/rand"
9 - "os"
9 "testing"
10
11 chunk "github.com/ipfs/go-ipfs/importer/chunk"
@@ -62,12 +61,6 @@ func TestSizeBasedSplit(t *testing.T) {
61 testFileConsistency(t, 31*4095, 4096)
62 }
63
65 -func dup(b []byte) []byte {
66 - o := make([]byte, len(b))
67 - copy(o, b)
68 - return o
69 -}
70 -
64 func testFileConsistency(t *testing.T, nbytes int64, blksize int64) {
65 ds := mdtest.Mock()
66 nd, should := getTestDag(t, ds, nbytes, blksize)
@@ -166,7 +159,7 @@ func TestSeekingBasic(t *testing.T) {
159 }
160
161 start := int64(4000)
169 - n, err := rs.Seek(start, os.SEEK_SET)
162 + n, err := rs.Seek(start, io.SeekStart)
163 if err != nil {
164 t.Fatal(err)
165 }
@@ -194,7 +187,7 @@ func TestSeekToBegin(t *testing.T) {
187 t.Fatal("Copy didnt copy enough bytes")
188 }
189
197 - seeked, err := rs.Seek(0, os.SEEK_SET)
190 + seeked, err := rs.Seek(0, io.SeekStart)
191 if err != nil {
192 t.Fatal(err)
193 }
@@ -222,7 +215,7 @@ func TestSeekToAlmostBegin(t *testing.T) {
215 t.Fatal("Copy didnt copy enough bytes")
216 }
217
225 - seeked, err := rs.Seek(1, os.SEEK_SET)
218 + seeked, err := rs.Seek(1, io.SeekStart)
219 if err != nil {
220 t.Fatal(err)
221 }
@@ -243,7 +236,7 @@ func TestSeekEnd(t *testing.T) {
236 t.Fatal(err)
237 }
238
246 - seeked, err := rs.Seek(0, os.SEEK_END)
239 + seeked, err := rs.Seek(0, io.SeekEnd)
240 if err != nil {
241 t.Fatal(err)
242 }
@@ -262,7 +255,7 @@ func TestSeekEndSingleBlockFile(t *testing.T) {
255 t.Fatal(err)
256 }
257
265 - seeked, err := rs.Seek(0, os.SEEK_END)
258 + seeked, err := rs.Seek(0, io.SeekEnd)
259 if err != nil {
260 t.Fatal(err)
261 }
@@ -285,7 +278,7 @@ func TestSeekingStress(t *testing.T) {
278 for i := 0; i < 50; i++ {
279 offset := mrand.Intn(int(nbytes))
280 l := int(nbytes) - offset
288 - n, err := rs.Seek(int64(offset), os.SEEK_SET)
281 + n, err := rs.Seek(int64(offset), io.SeekStart)
282 if err != nil {
283 t.Fatal(err)
284 }
@@ -323,7 +316,7 @@ func TestSeekingConsistency(t *testing.T) {
316
317 for coff := nbytes - 4096; coff >= 0; coff -= 4096 {
318 t.Log(coff)
326 - n, err := rs.Seek(coff, os.SEEK_SET)
319 + n, err := rs.Seek(coff, io.SeekStart)
320 if err != nil {
321 t.Fatal(err)
322 }
importer/helpers/helpers.go
+1 -4
@@ -113,11 +113,8 @@ func (n *UnixfsNode) AddChild(child *UnixfsNode, db *DagBuilderHelper) error {
113 }
114
115 _, err = db.batch.Add(childnode)
116 - if err != nil {
117 - return err
118 - }
116
120 - return nil
117 + return err
118 }
119
120 // Removes the child node at the given index
importer/importer.go
-3
@@ -13,12 +13,9 @@ import (
13 trickle "github.com/ipfs/go-ipfs/importer/trickle"
14 dag "github.com/ipfs/go-ipfs/merkledag"
15
16 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
16 node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
17 )
18
20 -var log = logging.Logger("importer")
21 -
19 // Builds a DAG from the given file, writing created blocks to disk as they are
20 // created
21 func BuildDagFromFile(fpath string, ds dag.DAGService) (node.Node, error) {
importer/trickle/trickle_test.go
+7 -8
@@ -7,7 +7,6 @@ import (
7 "io"
8 "io/ioutil"
9 mrand "math/rand"
10 - "os"
10 "testing"
11
12 chunk "github.com/ipfs/go-ipfs/importer/chunk"
@@ -178,7 +177,7 @@ func TestSeekingBasic(t *testing.T) {
177 }
178
179 start := int64(4000)
181 - n, err := rs.Seek(start, os.SEEK_SET)
180 + n, err := rs.Seek(start, io.SeekStart)
181 if err != nil {
182 t.Fatal(err)
183 }
@@ -222,7 +221,7 @@ func TestSeekToBegin(t *testing.T) {
221 t.Fatal("Copy didnt copy enough bytes")
222 }
223
225 - seeked, err := rs.Seek(0, os.SEEK_SET)
224 + seeked, err := rs.Seek(0, io.SeekStart)
225 if err != nil {
226 t.Fatal(err)
227 }
@@ -266,7 +265,7 @@ func TestSeekToAlmostBegin(t *testing.T) {
265 t.Fatal("Copy didnt copy enough bytes")
266 }
267
269 - seeked, err := rs.Seek(1, os.SEEK_SET)
268 + seeked, err := rs.Seek(1, io.SeekStart)
269 if err != nil {
270 t.Fatal(err)
271 }
@@ -302,7 +301,7 @@ func TestSeekEnd(t *testing.T) {
301 t.Fatal(err)
302 }
303
305 - seeked, err := rs.Seek(0, os.SEEK_END)
304 + seeked, err := rs.Seek(0, io.SeekEnd)
305 if err != nil {
306 t.Fatal(err)
307 }
@@ -328,7 +327,7 @@ func TestSeekEndSingleBlockFile(t *testing.T) {
327 t.Fatal(err)
328 }
329
331 - seeked, err := rs.Seek(0, os.SEEK_END)
330 + seeked, err := rs.Seek(0, io.SeekEnd)
331 if err != nil {
332 t.Fatal(err)
333 }
@@ -358,7 +357,7 @@ func TestSeekingStress(t *testing.T) {
357 for i := 0; i < 50; i++ {
358 offset := mrand.Intn(int(nbytes))
359 l := int(nbytes) - offset
361 - n, err := rs.Seek(int64(offset), os.SEEK_SET)
360 + n, err := rs.Seek(int64(offset), io.SeekStart)
361 if err != nil {
362 t.Fatal(err)
363 }
@@ -403,7 +402,7 @@ func TestSeekingConsistency(t *testing.T) {
402
403 for coff := nbytes - 4096; coff >= 0; coff -= 4096 {
404 t.Log(coff)
406 - n, err := rs.Seek(coff, os.SEEK_SET)
405 + n, err := rs.Seek(coff, io.SeekStart)
406 if err != nil {
407 t.Fatal(err)
408 }
keystore/keystore.go
+1 -4
@@ -104,11 +104,8 @@ func (ks *FSKeystore) Put(name string, k ci.PrivKey) error {
104 defer fi.Close()
105
106 _, err = fi.Write(b)
107 - if err != nil {
108 - return err
109 - }
107
111 - return nil
108 + return err
109 }
110
111 // Get retrieve a key from the Keystore
merkledag/merkledag.go
-2
@@ -12,12 +12,10 @@ import (
12 offline "github.com/ipfs/go-ipfs/exchange/offline"
13
14 ipldcbor "gx/ipfs/QmNrbCt8j9DT5W9Pmjy2SdudT9k8GpaDr4sRuFix3BXhgR/go-ipld-cbor"
15 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
15 cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
16 node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
17 )
18
20 -var log = logging.Logger("merkledag")
19 var ErrNotFound = fmt.Errorf("merkledag: not found")
20
21 // DAGService is an IPFS Merkle DAG service.
merkledag/merkledag_test.go
-6
@@ -209,12 +209,6 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
209 }
210 }
211
212 -func assertCanGet(t *testing.T, ds DAGService, n node.Node) {
213 - if _, err := ds.Get(context.Background(), n.Cid()); err != nil {
214 - t.Fatal(err)
215 - }
216 -}
217 -
212 func TestCantGet(t *testing.T) {
213 ds := dstest.Mock()
214 a := NodeWithData([]byte("A"))
merkledag/node.go
+2 -3
@@ -215,9 +215,8 @@ func (n *ProtoNode) SetData(d []byte) {
215 // that. If a link of the same name existed, it is removed.
216 func (n *ProtoNode) UpdateNodeLink(name string, that *ProtoNode) (*ProtoNode, error) {
217 newnode := n.Copy().(*ProtoNode)
218 - err := newnode.RemoveNodeLink(name)
219 - err = nil // ignore error
220 - err = newnode.AddNodeLink(name, that)
218 + _ = newnode.RemoveNodeLink(name) // ignore error
219 + err := newnode.AddNodeLink(name, that)
220 return newnode, err
221 }
222
mfs/dir.go
+1 -6
@@ -326,12 +326,7 @@ func (d *Directory) Unlink(name string) error {
326 delete(d.childDirs, name)
327 delete(d.files, name)
328
329 - err := d.dirbuilder.RemoveChild(d.ctx, name)
330 - if err != nil {
331 - return err
332 - }
333 -
334 - return nil
329 + return d.dirbuilder.RemoveChild(d.ctx, name)
330 }
331
332 func (d *Directory) Flush() error {
mfs/mfs_test.go
+11 -32
@@ -396,6 +396,9 @@ func TestMfsFile(t *testing.T) {
396
397 // assert size is as expected
398 size, err := fi.Size()
399 + if err != nil {
400 + t.Fatal(err)
401 + }
402 if size != int64(fisize) {
403 t.Fatal("size isnt correct")
404 }
@@ -419,12 +422,15 @@ func TestMfsFile(t *testing.T) {
422
423 // make sure size hasnt changed
424 size, err = wfd.Size()
425 + if err != nil {
426 + t.Fatal(err)
427 + }
428 if size != int64(fisize) {
429 t.Fatal("size isnt correct")
430 }
431
432 // seek back to beginning
427 - ns, err := wfd.Seek(0, os.SEEK_SET)
433 + ns, err := wfd.Seek(0, io.SeekStart)
434 if err != nil {
435 t.Fatal(err)
436 }
@@ -561,13 +567,9 @@ func actorMakeFile(d *Directory) error {
567 return err
568 }
569
564 - err = wfd.Close()
565 - if err != nil {
566 - return err
567 - }
568 -
569 - return nil
570 + return wfd.Close()
571 }
572 +
573 func actorMkdir(d *Directory) error {
574 d, err := randomWalk(d, rand.Intn(7))
575 if err != nil {
@@ -575,31 +577,8 @@ func actorMkdir(d *Directory) error {
577 }
578
579 _, err = d.Mkdir(randomName())
578 - if err != nil {
579 - return err
580 - }
581 -
582 - return nil
583 -}
584 -
585 -func actorRemoveFile(d *Directory) error {
586 - d, err := randomWalk(d, rand.Intn(7))
587 - if err != nil {
588 - return err
589 - }
590 -
591 - ents, err := d.List(context.Background())
592 - if err != nil {
593 - return err
594 - }
595 -
596 - if len(ents) == 0 {
597 - return nil
598 - }
599 -
600 - re := ents[rand.Intn(len(ents))]
580
602 - return d.Unlink(re.Name)
581 + return err
582 }
583
584 func randomFile(d *Directory) (*File, error) {
@@ -895,7 +874,7 @@ func readFile(rt *Root, path string, offset int64, buf []byte) error {
874 return err
875 }
876
898 - _, err = fd.Seek(offset, os.SEEK_SET)
877 + _, err = fd.Seek(offset, io.SeekStart)
878 if err != nil {
879 return err
880 }
mfs/ops.go
+1 -6
@@ -65,12 +65,7 @@ func Mv(r *Root, src, dst string) error {
65 return err
66 }
67
68 - err = srcDirObj.Unlink(srcFname)
69 - if err != nil {
70 - return err
71 - }
72 -
73 - return nil
68 + return srcDirObj.Unlink(srcFname)
69 }
70
71 func lookupDir(r *Root, path string) (*Directory, error) {
mfs/system.go
-13
@@ -170,12 +170,6 @@ type Republisher struct {
170 lastpub *cid.Cid
171 }
172
173 -func (rp *Republisher) getVal() *cid.Cid {
174 - rp.lk.Lock()
175 - defer rp.lk.Unlock()
176 - return rp.val
177 -}
178 -
173 // NewRepublisher creates a new Republisher object to republish the given root
174 // using the given short and long time intervals
175 func NewRepublisher(ctx context.Context, pf PubFunc, tshort, tlong time.Duration) *Republisher {
@@ -197,13 +191,6 @@ func (p *Republisher) setVal(c *cid.Cid) {
191 p.val = c
192 }
193
200 -func (p *Republisher) pubNow() {
201 - select {
202 - case p.pubnowch <- nil:
203 - default:
204 - }
205 -}
206 -
194 func (p *Republisher) WaitPub() {
195 p.lk.Lock()
196 consistent := p.lastpub == p.val
namesys/publisher.go
+2 -11
@@ -192,12 +192,7 @@ func PublishPublicKey(ctx context.Context, r routing.ValueStore, k string, pubk
192 // Store associated public key
193 timectx, cancel := context.WithTimeout(ctx, PublishPutValTimeout)
194 defer cancel()
195 - err = r.PutValue(timectx, k, pkbytes)
196 - if err != nil {
197 - return err
198 - }
199 -
200 - return nil
195 + return r.PutValue(timectx, k, pkbytes)
196 }
197
198 func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec *pb.IpnsEntry) error {
@@ -211,11 +206,7 @@ func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec
206
207 log.Debugf("Storing ipns entry at: %s", ipnskey)
208 // Store ipns entry at "/ipns/"+b58(h(pubkey))
214 - if err := r.PutValue(timectx, ipnskey, data); err != nil {
215 - return err
216 - }
217 -
218 - return nil
209 + return r.PutValue(timectx, ipnskey, data)
210 }
211
212 func CreateRoutingEntryData(pk ci.PrivKey, val path.Path, seq uint64, eol time.Time) (*pb.IpnsEntry, error) {
pin/gc/gc.go
-3
@@ -9,13 +9,10 @@ import (
9 dag "github.com/ipfs/go-ipfs/merkledag"
10 pin "github.com/ipfs/go-ipfs/pin"
11
12 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
12 cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
13 node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
14 )
15
17 -var log = logging.Logger("gc")
18 -
16 // Result represents an incremental output from a garbage collection
17 // run. It contains either an error, or the cid of a removed object.
18 type Result struct {
pin/pin.go
+1 -3
@@ -528,9 +528,7 @@ func (p *pinner) InternalPins() []*cid.Cid {
528 p.lock.Lock()
529 defer p.lock.Unlock()
530 var out []*cid.Cid
531 - for _, c := range p.internalPin.Keys() {
532 - out = append(out, c)
533 - }
531 + out = append(out, p.internalPin.Keys()...)
532 return out
533 }
534
pin/pin_test.go
+2 -2
@@ -183,8 +183,8 @@ func TestIsPinnedLookup(t *testing.T) {
183 // TODO does pinner need to share datastore with blockservice?
184 p := NewPinner(dstore, dserv, dserv)
185
186 - aNodes := make([]*mdag.ProtoNode, aBranchLen, aBranchLen)
187 - aKeys := make([]*cid.Cid, aBranchLen, aBranchLen)
186 + aNodes := make([]*mdag.ProtoNode, aBranchLen)
187 + aKeys := make([]*cid.Cid, aBranchLen)
188 for i := 0; i < aBranchLen; i++ {
189 a, _ := randNode()
190 if i >= 1 {
repo/config/config.go
-3
@@ -10,11 +10,8 @@ import (
10 "strings"
11
12 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
13 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
13 )
14
16 -var log = logging.Logger("config")
17 -
15 // Config is used to load ipfs config files.
16 type Config struct {
17 Identity Identity // local node's peer identity
repo/fsrepo/fsrepo.go
+3 -5
@@ -37,11 +37,12 @@ var RepoVersion = 5
37 var migrationInstructions = `See https://github.com/ipfs/fs-repo-migrations/blob/master/run.md
38 Sorry for the inconvenience. In the future, these will run automatically.`
39
40 +/*
41 var errIncorrectRepoFmt = `Repo has incorrect version: %s
42 Program version is: %s
43 Please run the ipfs migration tool before continuing.
44 ` + migrationInstructions
44 -
45 +*/
46 var programTooLowMessage = `Your programs version (%d) is lower than your repos (%d).
47 Please update ipfs to a version that supports the existing repo, or run
48 a migration in reverse.
@@ -411,10 +412,7 @@ func (r *FSRepo) Close() error {
412 // logging.Configure(logging.Output(os.Stderr))
413
414 r.closed = true
414 - if err := r.lockfile.Close(); err != nil {
415 - return err
416 - }
417 - return nil
415 + return r.lockfile.Close()
416 }
417
418 // Result when not Open is undefined. The method may panic if it pleases.
repo/fsrepo/fsrepo_test.go
+1 -1
@@ -100,7 +100,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
100 actual, ok := v.([]byte)
101 assert.True(ok, t, "value should be the []byte from r1's Put")
102 assert.Nil(r2.Close(), t)
103 - assert.True(bytes.Compare(expected, actual) == 0, t, "data should match")
103 + assert.True(bytes.Equal(expected, actual), t, "data should match")
104 }
105
106 func TestOpenMoreThanOnceInSameProcess(t *testing.T) {
repo/fsrepo/migrations/unpack.go
+1 -4
@@ -70,11 +70,8 @@ func writeToPath(rc io.Reader, out string) error {
70 defer binfi.Close()
71
72 _, err = io.Copy(binfi, rc)
73 - if err != nil {
74 - return err
75 - }
73
77 - return nil
74 + return err
75 }
76
77 func unpackZip(dist, binnom, path, out string) error {
repo/fsrepo/serialize/serialize.go
-3
@@ -9,13 +9,10 @@ import (
9 "path/filepath"
10
11 "github.com/ipfs/go-ipfs/repo/config"
12 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
12 "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
13 "gx/ipfs/QmdYwCmx8pZRkzdcd8MhmLJqYVoVTC1aGsy5Q4reMGLNLg/atomicfile"
14 )
15
17 -var log = logging.Logger("fsrepo")
18 -
16 // ReadConfigFile reads the config from `filename` into `cfg`.
17 func ReadConfigFile(filename string, cfg interface{}) error {
18 f, err := os.Open(filename)
routing/mock/centralized_server.go
+1 -1
@@ -66,7 +66,7 @@ func (rs *s) Providers(c *cid.Cid) []pstore.PeerInfo {
66 return ret
67 }
68 for _, r := range records {
69 - if time.Now().Sub(r.Created) > rs.delayConf.ValueVisibility.Get() {
69 + if time.Since(r.Created) > rs.delayConf.ValueVisibility.Get() {
70 ret = append(ret, r.Peer)
71 }
72 }
routing/mock/centralized_test.go
+3 -3
@@ -45,7 +45,7 @@ func TestClientFindProviders(t *testing.T) {
45 providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
46 isInClient := false
47 for pi := range providersFromClient {
48 - if pi.ID == pi.ID {
48 + if pi.ID == pi.ID { // <-- typo?
49 isInClient = true
50 }
51 }
@@ -72,7 +72,7 @@ func TestClientOverMax(t *testing.T) {
72
73 providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
74 i := 0
75 - for _ = range providersFromClient {
75 + for range providersFromClient {
76 i++
77 }
78 if i != max {
@@ -128,7 +128,7 @@ func TestCanceledContext(t *testing.T) {
128 providers := client.FindProvidersAsync(ctx, k, max)
129
130 numProvidersReturned := 0
131 - for _ = range providers {
131 + for range providers {
132 numProvidersReturned++
133 }
134 t.Log(numProvidersReturned)
routing/none/none_client.go
-3
@@ -7,15 +7,12 @@ import (
7 repo "github.com/ipfs/go-ipfs/repo"
8
9 routing "gx/ipfs/QmNdaQ8itUU9jEZUwTsG4gHMaPmRfi6FEe89QjQAFbep3M/go-libp2p-routing"
10 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
10 p2phost "gx/ipfs/QmUywuGNZoUKV8B9iyvup9bPkLiMrhTsyVMkeSXW5VxAfC/go-libp2p-host"
11 pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
12 cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
13 peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
14 )
15
17 -var log = logging.Logger("mockrouter")
18 -
16 type nilclient struct {
17 }
18
routing/offline/offline.go
-3
@@ -10,7 +10,6 @@ import (
10 routing "gx/ipfs/QmNdaQ8itUU9jEZUwTsG4gHMaPmRfi6FEe89QjQAFbep3M/go-libp2p-routing"
11 ci "gx/ipfs/QmP1DfoUjiWH2ZBo1PBH6FupdBucbDepx3HpWmEY6JMUpY/go-libp2p-crypto"
12 ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
13 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
13 record "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record"
14 pb "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record/pb"
15 pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
@@ -19,8 +18,6 @@ import (
18 "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
19 )
20
22 -var log = logging.Logger("offlinerouting")
23 -
21 var ErrOffline = errors.New("routing system in offline mode")
22
23 func NewOfflineRouter(dstore ds.Datastore, privkey ci.PrivKey) routing.IpfsRouting {
routing/offline/offline_test.go
+4 -2
@@ -15,12 +15,14 @@ func TestOfflineRouterStorage(t *testing.T) {
15 privkey, _, _ := testutil.RandTestKeyPair(128)
16 offline := NewOfflineRouter(nds, privkey)
17
18 - err := offline.PutValue(ctx, "key", []byte("testing 1 2 3"))
19 - if err != nil {
18 + if err := offline.PutValue(ctx, "key", []byte("testing 1 2 3")); err != nil {
19 t.Fatal(err)
20 }
21
22 val, err := offline.GetValue(ctx, "key")
23 + if err != nil {
24 + t.Fatal(err)
25 + }
26 if !bytes.Equal([]byte("testing 1 2 3"), val) {
27 t.Fatal("OfflineRouter does not properly store")
28 }
routing/supernode/proxy/standard.go
+1 -4
@@ -104,10 +104,7 @@ func (px *standard) sendMessage(ctx context.Context, m *dhtpb.Message, remote pe
104 }
105 defer s.Close()
106 pbw := ggio.NewDelimitedWriter(s)
107 - if err := pbw.WriteMsg(m); err != nil {
108 - return err
109 - }
110 - return nil
107 + return pbw.WriteMsg(m)
108 }
109
110 // SendRequest sends the request to each remote sequentially (randomized order),
routing/supernode/server.go
+1 -22
@@ -10,7 +10,6 @@ import (
10
11 datastore "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
12 dhtpb "gx/ipfs/QmRmroYSdievxnjiuy99C8BzShNstdEWcEF3LQHF7fUbez/go-libp2p-kad-dht/pb"
13 - record "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record"
13 pb "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record/pb"
14 pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
15 proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
@@ -140,10 +139,7 @@ func putRoutingRecord(ds datastore.Datastore, k string, value *pb.Record) error
139 }
140 dskey := dshelp.NewKeyFromBinary([]byte(k))
141 // TODO namespace
143 - if err := ds.Put(dskey, data); err != nil {
144 - return err
145 - }
146 - return nil
142 + return ds.Put(dskey, data)
143 }
144
145 func putRoutingProviders(ds datastore.Datastore, k string, newRecords []*dhtpb.Message_Peer) error {
@@ -204,20 +200,3 @@ func getRoutingProviders(ds datastore.Datastore, k string) ([]*dhtpb.Message_Pee
200 func providerKey(k string) datastore.Key {
201 return datastore.KeyWithNamespaces([]string{"routing", "providers", k})
202 }
207 -
208 -func verify(ps pstore.Peerstore, r *pb.Record) error {
209 - v := make(record.Validator)
210 - v["pk"] = record.PublicKeyValidator
211 - p := peer.ID(r.GetAuthor())
212 - pk := ps.PubKey(p)
213 - if pk == nil {
214 - return fmt.Errorf("do not have public key for %s", p)
215 - }
216 - if err := record.CheckRecordSig(r, pk); err != nil {
217 - return err
218 - }
219 - if err := v.VerifyRecord(r); err != nil {
220 - return err
221 - }
222 - return nil
223 -}
test/integration/three_legged_cat_test.go
+1 -1
@@ -65,7 +65,7 @@ func TestThreeLeggedCat100MBMacbookCoastToCoast(t *testing.T) {
65 func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
66 ctx, cancel := context.WithCancel(context.Background())
67 defer cancel()
68 - const numPeers = 3
68 + // const numPeers = 3
69
70 // create network
71 mn := mocknet.New(ctx)
thirdparty/tar/extractor.go
+2 -12
@@ -79,12 +79,7 @@ func (te *Extractor) extractDir(h *tar.Header, depth int) error {
79 te.Path = path
80 }
81
82 - err := os.MkdirAll(path, 0755)
83 - if err != nil {
84 - return err
85 - }
86 -
87 - return nil
82 + return os.MkdirAll(path, 0755)
83 }
84
85 func (te *Extractor) extractSymlink(h *tar.Header) error {
@@ -112,12 +107,7 @@ func (te *Extractor) extractFile(h *tar.Header, r *tar.Reader, depth int, rootEx
107 }
108 defer file.Close()
109
115 - err = copyWithProgress(file, r, te.Progress)
116 - if err != nil {
117 - return err
118 - }
119 -
120 - return nil
110 + return copyWithProgress(file, r, te.Progress)
111 }
112
113 func copyWithProgress(to io.Writer, from io.Reader, cb func(int64) int64) error {
unixfs/io/dagreader_test.go
+5 -5
@@ -2,8 +2,8 @@ package io
2
3 import (
4 "bytes"
5 + "io"
6 "io/ioutil"
6 - "os"
7 "strings"
8 "testing"
9
@@ -54,7 +54,7 @@ func TestSeekAndRead(t *testing.T) {
54 }
55
56 for i := 255; i >= 0; i-- {
57 - reader.Seek(int64(i), os.SEEK_SET)
57 + reader.Seek(int64(i), io.SeekStart)
58
59 if reader.Offset() != int64(i) {
60 t.Fatal("expected offset to be increased by one after read")
@@ -100,14 +100,14 @@ func TestRelativeSeek(t *testing.T) {
100 t.Fatalf("expected to read: %d at %d, read %d", i, reader.Offset()-1, out)
101 }
102 if i != 255 {
103 - _, err := reader.Seek(3, os.SEEK_CUR)
103 + _, err := reader.Seek(3, io.SeekCurrent)
104 if err != nil {
105 t.Fatal(err)
106 }
107 }
108 }
109
110 - _, err = reader.Seek(4, os.SEEK_END)
110 + _, err = reader.Seek(4, io.SeekEnd)
111 if err != nil {
112 t.Fatal(err)
113 }
@@ -120,7 +120,7 @@ func TestRelativeSeek(t *testing.T) {
120 if int(out) != 255-i {
121 t.Fatalf("expected to read: %d at %d, read %d", 255-i, reader.Offset()-1, out)
122 }
123 - reader.Seek(-5, os.SEEK_CUR) // seek 4 bytes but we read one byte every time so 5 bytes
123 + reader.Seek(-5, io.SeekCurrent) // seek 4 bytes but we read one byte every time so 5 bytes
124 }
125
126 }
unixfs/io/pbdagreader.go
+6 -7
@@ -5,7 +5,6 @@ import (
5 "errors"
6 "fmt"
7 "io"
8 - "os"
8
9 mdag "github.com/ipfs/go-ipfs/merkledag"
10 ft "github.com/ipfs/go-ipfs/unixfs"
@@ -185,7 +184,7 @@ func (dr *pbDagReader) Offset() int64 {
184 // recreations that need to happen.
185 func (dr *pbDagReader) Seek(offset int64, whence int) (int64, error) {
186 switch whence {
188 - case os.SEEK_SET:
187 + case io.SeekStart:
188 if offset < 0 {
189 return -1, errors.New("Invalid offset")
190 }
@@ -226,7 +225,7 @@ func (dr *pbDagReader) Seek(offset int64, whence int) (int64, error) {
225 }
226
227 // set proper offset within child readseeker
229 - n, err := dr.buf.Seek(left, os.SEEK_SET)
228 + n, err := dr.buf.Seek(left, io.SeekStart)
229 if err != nil {
230 return -1, err
231 }
@@ -238,13 +237,13 @@ func (dr *pbDagReader) Seek(offset int64, whence int) (int64, error) {
237 }
238 dr.offset = offset
239 return offset, nil
241 - case os.SEEK_CUR:
240 + case io.SeekCurrent:
241 // TODO: be smarter here
242 noffset := dr.offset + offset
244 - return dr.Seek(noffset, os.SEEK_SET)
245 - case os.SEEK_END:
243 + return dr.Seek(noffset, io.SeekStart)
244 + case io.SeekEnd:
245 noffset := int64(dr.pbdata.GetFilesize()) - offset
247 - return dr.Seek(noffset, os.SEEK_SET)
246 + return dr.Seek(noffset, io.SeekStart)
247 default:
248 return 0, errors.New("invalid whence")
249 }
unixfs/mod/dagmodifier.go
+4 -8
@@ -5,7 +5,6 @@ import (
5 "context"
6 "errors"
7 "io"
8 - "os"
8
9 chunk "github.com/ipfs/go-ipfs/importer/chunk"
10 help "github.com/ipfs/go-ipfs/importer/helpers"
@@ -14,7 +13,6 @@ import (
13 ft "github.com/ipfs/go-ipfs/unixfs"
14 uio "github.com/ipfs/go-ipfs/unixfs/io"
15
17 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
16 cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
17 proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
18 node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
@@ -26,8 +24,6 @@ var ErrUnrecognizedWhence = errors.New("unrecognized whence")
24 // 2MB
25 var writebufferSize = 1 << 21
26
29 -var log = logging.Logger("dagio")
30 -
27 // DagModifier is the only struct licensed and able to correctly
28 // perform surgery on a DAG 'file'
29 // Dear god, please rename this to something more pleasant
@@ -340,7 +336,7 @@ func (dm *DagModifier) readPrep() error {
336 return err
337 }
338
343 - i, err := dr.Seek(int64(dm.curWrOff), os.SEEK_SET)
339 + i, err := dr.Seek(int64(dm.curWrOff), io.SeekStart)
340 if err != nil {
341 cancel()
342 return err
@@ -397,11 +393,11 @@ func (dm *DagModifier) Seek(offset int64, whence int) (int64, error) {
393
394 var newoffset uint64
395 switch whence {
400 - case os.SEEK_CUR:
396 + case io.SeekCurrent:
397 newoffset = dm.curWrOff + uint64(offset)
402 - case os.SEEK_SET:
398 + case io.SeekStart:
399 newoffset = uint64(offset)
404 - case os.SEEK_END:
400 + case io.SeekEnd:
401 newoffset = uint64(fisize) - uint64(offset)
402 default:
403 return 0, ErrUnrecognizedWhence
unixfs/mod/dagmodifier_test.go
+21 -12
@@ -2,8 +2,8 @@ package mod
2
3 import (
4 "fmt"
5 + "io"
6 "io/ioutil"
6 - "os"
7 "testing"
8
9 "github.com/ipfs/go-ipfs/blocks/blockstore"
@@ -384,7 +384,7 @@ func TestDagTruncate(t *testing.T) {
384 t.Fatal("size was incorrect!")
385 }
386
387 - _, err = dagmod.Seek(0, os.SEEK_SET)
387 + _, err = dagmod.Seek(0, io.SeekStart)
388 if err != nil {
389 t.Fatal(err)
390 }
@@ -450,7 +450,7 @@ func TestSparseWrite(t *testing.T) {
450 t.Fatal("incorrect write amount")
451 }
452
453 - _, err = dagmod.Seek(0, os.SEEK_SET)
453 + _, err = dagmod.Seek(0, io.SeekStart)
454 if err != nil {
455 t.Fatal(err)
456 }
@@ -479,7 +479,7 @@ func TestSeekPastEndWrite(t *testing.T) {
479 buf := make([]byte, 5000)
480 u.NewTimeSeededRand().Read(buf[2500:])
481
482 - nseek, err := dagmod.Seek(2500, os.SEEK_SET)
482 + nseek, err := dagmod.Seek(2500, io.SeekStart)
483 if err != nil {
484 t.Fatal(err)
485 }
@@ -497,7 +497,7 @@ func TestSeekPastEndWrite(t *testing.T) {
497 t.Fatal("incorrect write amount")
498 }
499
500 - _, err = dagmod.Seek(0, os.SEEK_SET)
500 + _, err = dagmod.Seek(0, io.SeekStart)
501 if err != nil {
502 t.Fatal(err)
503 }
@@ -525,7 +525,7 @@ func TestRelativeSeek(t *testing.T) {
525
526 for i := 0; i < 64; i++ {
527 dagmod.Write([]byte{byte(i)})
528 - if _, err := dagmod.Seek(1, os.SEEK_CUR); err != nil {
528 + if _, err := dagmod.Seek(1, io.SeekCurrent); err != nil {
529 t.Fatal(err)
530 }
531 }
@@ -576,17 +576,26 @@ func TestEndSeek(t *testing.T) {
576 t.Fatal(err)
577 }
578
579 - offset, err := dagmod.Seek(0, os.SEEK_CUR)
579 + offset, err := dagmod.Seek(0, io.SeekCurrent)
580 + if err != nil {
581 + t.Fatal(err)
582 + }
583 if offset != 100 {
584 t.Fatal("expected the relative seek 0 to return current location")
585 }
586
584 - offset, err = dagmod.Seek(0, os.SEEK_SET)
587 + offset, err = dagmod.Seek(0, io.SeekStart)
588 + if err != nil {
589 + t.Fatal(err)
590 + }
591 if offset != 0 {
592 t.Fatal("expected the absolute seek to set offset at 0")
593 }
594
589 - offset, err = dagmod.Seek(0, os.SEEK_END)
595 + offset, err = dagmod.Seek(0, io.SeekEnd)
596 + if err != nil {
597 + t.Fatal(err)
598 + }
599 if offset != 100 {
600 t.Fatal("expected the end seek to set offset at end")
601 }
@@ -612,7 +621,7 @@ func TestReadAndSeek(t *testing.T) {
621 }
622
623 readBuf := make([]byte, 4)
615 - offset, err := dagmod.Seek(0, os.SEEK_SET)
624 + offset, err := dagmod.Seek(0, io.SeekStart)
625 if offset != 0 {
626 t.Fatal("expected offset to be 0")
627 }
@@ -636,7 +645,7 @@ func TestReadAndSeek(t *testing.T) {
645 }
646
647 // skip 4
639 - _, err = dagmod.Seek(1, os.SEEK_CUR)
648 + _, err = dagmod.Seek(1, io.SeekCurrent)
649 if err != nil {
650 t.Fatalf("error: %s, offset %d, reader offset %d", err, dagmod.curWrOff, dagmod.read.Offset())
651 }
@@ -676,7 +685,7 @@ func TestCtxRead(t *testing.T) {
685 if err != nil {
686 t.Fatal(err)
687 }
679 - dagmod.Seek(0, os.SEEK_SET)
688 + dagmod.Seek(0, io.SeekStart)
689
690 readBuf := make([]byte, 4)
691 _, err = dagmod.CtxReadFull(ctx, readBuf)