mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-23 05:35:58 +08:00
blockstore.ErrNotFound, and proper wantlist sorting
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user