Commit 4ba51bde authored by Kevin Atkinson's avatar Kevin Atkinson

gx update and fix code to use new Cid type

parent bbc2201e
...@@ -25,7 +25,7 @@ var ErrNotFound = errors.New("blockservice: key not found") ...@@ -25,7 +25,7 @@ var ErrNotFound = errors.New("blockservice: key not found")
// the blockservice. // the blockservice.
type BlockGetter interface { type BlockGetter interface {
// GetBlock gets the requested block. // GetBlock gets the requested block.
GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, error)
// GetBlocks does a batch request for the given cids, returning blocks as // GetBlocks does a batch request for the given cids, returning blocks as
// they are found, in no particular order. // they are found, in no particular order.
...@@ -34,7 +34,7 @@ type BlockGetter interface { ...@@ -34,7 +34,7 @@ type BlockGetter interface {
// be canceled). In that case, it will close the channel early. It is up // be canceled). In that case, it will close the channel early. It is up
// to the consumer to detect this situation and keep track which blocks // to the consumer to detect this situation and keep track which blocks
// it has received and which it hasn't. // it has received and which it hasn't.
GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block
} }
// BlockService is a hybrid block datastore. It stores data in a local // BlockService is a hybrid block datastore. It stores data in a local
...@@ -58,7 +58,7 @@ type BlockService interface { ...@@ -58,7 +58,7 @@ type BlockService interface {
AddBlocks(bs []blocks.Block) error AddBlocks(bs []blocks.Block) error
// DeleteBlock deletes the given block from the blockservice. // DeleteBlock deletes the given block from the blockservice.
DeleteBlock(o *cid.Cid) error DeleteBlock(o cid.Cid) error
} }
type blockService struct { type blockService struct {
...@@ -196,7 +196,7 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error { ...@@ -196,7 +196,7 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
// GetBlock retrieves a particular block from the service, // GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash). // Getting it from the datastore using the key (hash).
func (s *blockService) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error) { func (s *blockService) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, error) {
log.Debugf("BlockService GetBlock: '%s'", c) log.Debugf("BlockService GetBlock: '%s'", c)
var f exchange.Fetcher var f exchange.Fetcher
...@@ -207,7 +207,7 @@ func (s *blockService) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, ...@@ -207,7 +207,7 @@ func (s *blockService) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block,
return getBlock(ctx, c, s.blockstore, f) // hash security return getBlock(ctx, c, s.blockstore, f) // hash security
} }
func getBlock(ctx context.Context, c *cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) (blocks.Block, error) { func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) (blocks.Block, error) {
err := verifcid.ValidateCid(c) // hash security err := verifcid.ValidateCid(c) // hash security
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -244,11 +244,11 @@ func getBlock(ctx context.Context, c *cid.Cid, bs blockstore.Blockstore, f excha ...@@ -244,11 +244,11 @@ func getBlock(ctx context.Context, c *cid.Cid, bs blockstore.Blockstore, f excha
// GetBlocks gets a list of blocks asynchronously and returns through // GetBlocks gets a list of blocks asynchronously and returns through
// the returned channel. // the returned channel.
// NB: No guarantees are made about order. // NB: No guarantees are made about order.
func (s *blockService) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block { func (s *blockService) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block {
return getBlocks(ctx, ks, s.blockstore, s.exchange) // hash security return getBlocks(ctx, ks, s.blockstore, s.exchange) // hash security
} }
func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) <-chan blocks.Block { func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) <-chan blocks.Block {
out := make(chan blocks.Block) out := make(chan blocks.Block)
go func() { go func() {
...@@ -266,7 +266,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e ...@@ -266,7 +266,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
} }
ks = ks[:k] ks = ks[:k]
var misses []*cid.Cid var misses []cid.Cid
for _, c := range ks { for _, c := range ks {
hit, err := bs.Get(c) hit, err := bs.Get(c)
if err != nil { if err != nil {
...@@ -303,7 +303,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e ...@@ -303,7 +303,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
} }
// DeleteBlock deletes a block in the blockservice from the datastore // DeleteBlock deletes a block in the blockservice from the datastore
func (s *blockService) DeleteBlock(c *cid.Cid) error { func (s *blockService) DeleteBlock(c cid.Cid) error {
err := s.blockstore.DeleteBlock(c) err := s.blockstore.DeleteBlock(c)
if err == nil { if err == nil {
log.Event(context.TODO(), "BlockService.BlockDeleted", c) log.Event(context.TODO(), "BlockService.BlockDeleted", c)
...@@ -323,12 +323,12 @@ type Session struct { ...@@ -323,12 +323,12 @@ type Session struct {
} }
// GetBlock gets a block in the context of a request session // GetBlock gets a block in the context of a request session
func (s *Session) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error) { func (s *Session) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, error) {
return getBlock(ctx, c, s.bs, s.ses) // hash security return getBlock(ctx, c, s.bs, s.ses) // hash security
} }
// GetBlocks gets blocks in the context of a request session // GetBlocks gets blocks in the context of a request session
func (s *Session) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block { func (s *Session) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block {
return getBlocks(ctx, ks, s.bs, s.ses) // hash security return getBlocks(ctx, ks, s.bs, s.ses) // hash security
} }
......
...@@ -9,15 +9,15 @@ ...@@ -9,15 +9,15 @@
"gxDependencies": [ "gxDependencies": [
{ {
"author": "why", "author": "why",
"hash": "QmVDDgboX5nPUE4pBcK2xC1b9XbStA4t2KrUWBRMr9AiFd", "hash": "QmQPWVDYeWvxN75cP4MGrbMVpADm2XqpM4KxgvbxkYk16u",
"name": "go-bitswap", "name": "go-bitswap",
"version": "1.0.15" "version": "1.1.0"
}, },
{ {
"author": "hsanjuan", "author": "hsanjuan",
"hash": "QmPuLWvxK1vg6ckKUpT53Dow9VLCcQGdL5Trwxa8PTLp7r", "hash": "QmXHsHBveZF6ueKzDJbUg476gmrbzoR1yijiyH5SZAEuDT",
"name": "go-ipfs-exchange-offline", "name": "go-ipfs-exchange-offline",
"version": "0.0.17" "version": "0.1.0"
}, },
{ {
"author": "jbenet", "author": "jbenet",
...@@ -27,21 +27,21 @@ ...@@ -27,21 +27,21 @@
}, },
{ {
"author": "hsanjuan", "author": "hsanjuan",
"hash": "Qmeg56ecxRnVv7VWViMrDeEMoBHaNFMs4vQnyQrJ79Zz7i", "hash": "QmeMussyD8s3fQ3pM19ZsfbxvomEqPV9FvczLMWyBDYSnS",
"name": "go-ipfs-blockstore", "name": "go-ipfs-blockstore",
"version": "0.0.20" "version": "0.1.0"
}, },
{ {
"author": "stebalien", "author": "stebalien",
"hash": "QmWAzSEoqZ6xU6pu8yL8e5WaMb7wtbfbhhN4p1DknUPtr3", "hash": "QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM",
"name": "go-block-format", "name": "go-block-format",
"version": "0.1.11" "version": "0.2.0"
}, },
{ {
"author": "why", "author": "why",
"hash": "QmVUhfewLZpSaAiBYCpw2krYMaiVmFuhr2iurQLuRoU6sD", "hash": "QmVkMRSkXrpjqrroEXWuYBvDBnXCdMMY6gsKicBGVGUqKT",
"name": "go-verifcid", "name": "go-verifcid",
"version": "0.0.4" "version": "0.1.0"
} }
], ],
"gxVersion": "0.12.1", "gxVersion": "0.12.1",
......
...@@ -71,7 +71,7 @@ func TestGetBlocksSequential(t *testing.T) { ...@@ -71,7 +71,7 @@ func TestGetBlocksSequential(t *testing.T) {
} }
objs := makeObjects(50) objs := makeObjects(50)
var cids []*cid.Cid var cids []cid.Cid
for _, o := range objs { for _, o := range objs {
cids = append(cids, o.Cid()) cids = append(cids, o.Cid())
servs[0].AddBlock(o) servs[0].AddBlock(o)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment