blockstore.ErrNotFound, and proper wantlist sorting
Jeromy committed
Dec 10, 2014 at 23:01 UTC
50aa37fec42e1c6f28e7786343cf3fd0fbd8968d
4 files changed
+9
-6
blocks/blockstore/blockstore.go
+6
-1
@@ -6,14 +6,16 @@ import (
6
"errors"
7
8
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
9
-
9
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
10
+
11
blocks "github.com/jbenet/go-ipfs/blocks"
12
u "github.com/jbenet/go-ipfs/util"
13
)
14
15
var ValueTypeMismatch = errors.New("The retrieved value is not a Block")
16
17
+var ErrNotFound = errors.New("blockstore: block not found")
18
+
19
// Blockstore wraps a ThreadSafeDatastore
20
type Blockstore interface {
21
DeleteBlock(u.Key) error
@@ -34,6 +36,9 @@ type blockstore struct {
36
37
func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) {
38
maybeData, err := bs.datastore.Get(k.DsKey())
39
+ if err == ds.ErrNotFound {
40
+ return nil, ErrNotFound
41
+ }
42
if err != nil {
43
return nil, err
44
}
blockservice/blockservice.go
+1
-3
@@ -8,8 +8,6 @@ import (
8
"fmt"
9
10
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
11
- ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
12
-
11
blocks "github.com/jbenet/go-ipfs/blocks"
12
"github.com/jbenet/go-ipfs/blocks/blockstore"
13
exchange "github.com/jbenet/go-ipfs/exchange"
@@ -67,7 +65,7 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
65
return block, nil
66
// TODO be careful checking ErrNotFound. If the underlying
67
// implementation changes, this will break.
70
- } else if err == ds.ErrNotFound && s.Exchange != nil {
68
+ } else if err == blockstore.ErrNotFound && s.Exchange != nil {
69
log.Debug("Blockservice: Searching bitswap.")
70
blk, err := s.Exchange.GetBlock(ctx, k)
71
if err != nil {
exchange/bitswap/strategy/strategy.go
+1
-1
@@ -68,7 +68,7 @@ func (s *strategist) getSendableBlocks(wantlist *wl.Wantlist, bs bstore.Blocksto
68
var outblocks []*blocks.Block
69
for _, e := range wantlist.Entries() {
70
block, err := bs.Get(e.Value)
71
- if err == u.ErrNotFound {
71
+ if err == bstore.ErrNotFound {
72
continue
73
}
74
if err != nil {
exchange/bitswap/wantlist/wantlist.go
+1
-1
@@ -43,7 +43,7 @@ type entrySlice []*Entry
43
44
func (es entrySlice) Len() int { return len(es) }
45
func (es entrySlice) Swap(i, j int) { es[i], es[j] = es[j], es[i] }
46
-func (es entrySlice) Less(i, j int) bool { return es[i].Priority < es[j].Priority }
46
+func (es entrySlice) Less(i, j int) bool { return es[i].Priority > es[j].Priority }
47
48
func (w *Wantlist) Entries() []*Entry {
49
var es entrySlice