diff --git a/blocks/blockstore/blockstore.go b/blocks/blockstore/blockstore.go index d4849cb43..e203ffc50 100644 --- a/blocks/blockstore/blockstore.go +++ b/blocks/blockstore/blockstore.go @@ -6,14 +6,16 @@ import ( "errors" ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" - mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" + blocks "github.com/jbenet/go-ipfs/blocks" u "github.com/jbenet/go-ipfs/util" ) var ValueTypeMismatch = errors.New("The retrieved value is not a Block") +var ErrNotFound = errors.New("blockstore: block not found") + // Blockstore wraps a ThreadSafeDatastore type Blockstore interface { DeleteBlock(u.Key) error @@ -34,6 +36,9 @@ type blockstore struct { func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) { maybeData, err := bs.datastore.Get(k.DsKey()) + if err == ds.ErrNotFound { + return nil, ErrNotFound + } if err != nil { return nil, err } diff --git a/blockservice/blockservice.go b/blockservice/blockservice.go index f44eaa0f5..9014cab46 100644 --- a/blockservice/blockservice.go +++ b/blockservice/blockservice.go @@ -8,8 +8,6 @@ import ( "fmt" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" - ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" - blocks "github.com/jbenet/go-ipfs/blocks" "github.com/jbenet/go-ipfs/blocks/blockstore" exchange "github.com/jbenet/go-ipfs/exchange" @@ -67,7 +65,7 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er return block, nil // TODO be careful checking ErrNotFound. If the underlying // implementation changes, this will break. - } else if err == ds.ErrNotFound && s.Exchange != nil { + } else if err == blockstore.ErrNotFound && s.Exchange != nil { log.Debug("Blockservice: Searching bitswap.") blk, err := s.Exchange.GetBlock(ctx, k) if err != nil { diff --git a/exchange/bitswap/strategy/strategy.go b/exchange/bitswap/strategy/strategy.go index d425fcc77..ff7f4d74d 100644 --- a/exchange/bitswap/strategy/strategy.go +++ b/exchange/bitswap/strategy/strategy.go @@ -68,7 +68,7 @@ func (s *strategist) getSendableBlocks(wantlist *wl.Wantlist, bs bstore.Blocksto var outblocks []*blocks.Block for _, e := range wantlist.Entries() { block, err := bs.Get(e.Value) - if err == u.ErrNotFound { + if err == bstore.ErrNotFound { continue } if err != nil { diff --git a/exchange/bitswap/wantlist/wantlist.go b/exchange/bitswap/wantlist/wantlist.go index f9cf52eb2..d57b9d523 100644 --- a/exchange/bitswap/wantlist/wantlist.go +++ b/exchange/bitswap/wantlist/wantlist.go @@ -43,7 +43,7 @@ type entrySlice []*Entry func (es entrySlice) Len() int { return len(es) } func (es entrySlice) Swap(i, j int) { es[i], es[j] = es[j], es[i] } -func (es entrySlice) Less(i, j int) bool { return es[i].Priority < es[j].Priority } +func (es entrySlice) Less(i, j int) bool { return es[i].Priority > es[j].Priority } func (w *Wantlist) Entries() []*Entry { var es entrySlice