Adopt api.Cid type - replaces cid.Cid everwhere.

This commit introduces an api.Cid type and replaces the usage of cid.Cid
everywhere.

The main motivation here is to override MarshalJSON so that Cids are
JSON-ified as '"Qm...."' instead of '{ "/": "Qm....." }', as this "ipld"
representation of IDs is horrible to work with, and our APIs are not issuing
IPLD objects to start with.

Unfortunately, there is no way to do this cleanly, and the best way is to just
switch everything to our own type.
This commit is contained in:
Hector Sanjuan 2022-04-07 13:53:30 +02:00
parent a2b89f9b3b
commit a97ed10d0b
60 changed files with 369 additions and 367 deletions

View File

@ -29,7 +29,7 @@ follow:
check: check:
go vet ./... go vet ./...
staticcheck ./... staticcheck --checks all ./...
test: test:
go test -v ./... go test -v ./...

View File

@ -42,7 +42,7 @@ type ClusterDAGService interface {
ipld.DAGService ipld.DAGService
// Finalize receives the IPFS content root CID as // Finalize receives the IPFS content root CID as
// returned by the ipfs adder. // returned by the ipfs adder.
Finalize(ctx context.Context, ipfsRoot cid.Cid) (cid.Cid, error) Finalize(ctx context.Context, ipfsRoot api.Cid) (api.Cid, error)
// Allocations returns the allocations made by the cluster DAG service // Allocations returns the allocations made by the cluster DAG service
// for the added content. // for the added content.
Allocations() []peer.ID Allocations() []peer.ID
@ -51,7 +51,7 @@ type ClusterDAGService interface {
// A dagFormatter can create dags from files.Node. It can keep state // A dagFormatter can create dags from files.Node. It can keep state
// to add several files to the same dag. // to add several files to the same dag.
type dagFormatter interface { type dagFormatter interface {
Add(name string, f files.Node) (cid.Cid, error) Add(name string, f files.Node) (api.Cid, error)
} }
// Adder is used to add content to IPFS Cluster using an implementation of // Adder is used to add content to IPFS Cluster using an implementation of
@ -103,12 +103,12 @@ func (a *Adder) setContext(ctx context.Context) {
// FromMultipart adds content from a multipart.Reader. The adder will // FromMultipart adds content from a multipart.Reader. The adder will
// no longer be usable after calling this method. // no longer be usable after calling this method.
func (a *Adder) FromMultipart(ctx context.Context, r *multipart.Reader) (cid.Cid, error) { func (a *Adder) FromMultipart(ctx context.Context, r *multipart.Reader) (api.Cid, error) {
logger.Debugf("adding from multipart with params: %+v", a.params) logger.Debugf("adding from multipart with params: %+v", a.params)
f, err := files.NewFileFromPartReader(r, "multipart/form-data") f, err := files.NewFileFromPartReader(r, "multipart/form-data")
if err != nil { if err != nil {
return cid.Undef, err return api.CidUndef, err
} }
defer f.Close() defer f.Close()
return a.FromFiles(ctx, f) return a.FromFiles(ctx, f)
@ -116,12 +116,12 @@ func (a *Adder) FromMultipart(ctx context.Context, r *multipart.Reader) (cid.Cid
// FromFiles adds content from a files.Directory. The adder will no longer // FromFiles adds content from a files.Directory. The adder will no longer
// be usable after calling this method. // be usable after calling this method.
func (a *Adder) FromFiles(ctx context.Context, f files.Directory) (cid.Cid, error) { func (a *Adder) FromFiles(ctx context.Context, f files.Directory) (api.Cid, error) {
logger.Debug("adding from files") logger.Debug("adding from files")
a.setContext(ctx) a.setContext(ctx)
if a.ctx.Err() != nil { // don't allow running twice if a.ctx.Err() != nil { // don't allow running twice
return cid.Undef, a.ctx.Err() return api.CidUndef, a.ctx.Err()
} }
defer a.cancel() defer a.cancel()
@ -139,7 +139,7 @@ func (a *Adder) FromFiles(ctx context.Context, f files.Directory) (cid.Cid, erro
err = errors.New("bad dag formatter option") err = errors.New("bad dag formatter option")
} }
if err != nil { if err != nil {
return cid.Undef, err return api.CidUndef, err
} }
// setup wrapping // setup wrapping
@ -150,18 +150,18 @@ func (a *Adder) FromFiles(ctx context.Context, f files.Directory) (cid.Cid, erro
} }
it := f.Entries() it := f.Entries()
var adderRoot cid.Cid var adderRoot api.Cid
for it.Next() { for it.Next() {
select { select {
case <-a.ctx.Done(): case <-a.ctx.Done():
return cid.Undef, a.ctx.Err() return api.CidUndef, a.ctx.Err()
default: default:
logger.Debugf("ipfsAdder AddFile(%s)", it.Name()) logger.Debugf("ipfsAdder AddFile(%s)", it.Name())
adderRoot, err = dagFmtr.Add(it.Name(), it.Node()) adderRoot, err = dagFmtr.Add(it.Name(), it.Node())
if err != nil { if err != nil {
logger.Error("error adding to cluster: ", err) logger.Error("error adding to cluster: ", err)
return cid.Undef, err return api.CidUndef, err
} }
} }
// TODO (hector): We can only add a single CAR file for the // TODO (hector): We can only add a single CAR file for the
@ -171,13 +171,13 @@ func (a *Adder) FromFiles(ctx context.Context, f files.Directory) (cid.Cid, erro
} }
} }
if it.Err() != nil { if it.Err() != nil {
return cid.Undef, it.Err() return api.CidUndef, it.Err()
} }
clusterRoot, err := a.dgs.Finalize(a.ctx, adderRoot) clusterRoot, err := a.dgs.Finalize(a.ctx, adderRoot)
if err != nil { if err != nil {
logger.Error("error finalizing adder:", err) logger.Error("error finalizing adder:", err)
return cid.Undef, err return api.CidUndef, err
} }
logger.Infof("%s successfully added to cluster", clusterRoot) logger.Infof("%s successfully added to cluster", clusterRoot)
return clusterRoot, nil return clusterRoot, nil
@ -220,7 +220,7 @@ func newIpfsAdder(ctx context.Context, dgs ClusterDAGService, params api.AddPara
}, nil }, nil
} }
func (ia *ipfsAdder) Add(name string, f files.Node) (cid.Cid, error) { func (ia *ipfsAdder) Add(name string, f files.Node) (api.Cid, error) {
// In order to set the AddedOutput names right, we use // In order to set the AddedOutput names right, we use
// OutputPrefix: // OutputPrefix:
// //
@ -239,9 +239,9 @@ func (ia *ipfsAdder) Add(name string, f files.Node) (cid.Cid, error) {
nd, err := ia.AddAllAndPin(f) nd, err := ia.AddAllAndPin(f)
if err != nil { if err != nil {
return cid.Undef, err return api.CidUndef, err
} }
return nd.Cid(), nil return api.NewCid(nd.Cid()), nil
} }
// An adder to add CAR files. It is at the moment very basic, and can // An adder to add CAR files. It is at the moment very basic, and can
@ -267,22 +267,22 @@ func newCarAdder(ctx context.Context, dgs ClusterDAGService, params api.AddParam
// Add takes a node which should be a CAR file and nothing else and // Add takes a node which should be a CAR file and nothing else and
// adds its blocks using the ClusterDAGService. // adds its blocks using the ClusterDAGService.
func (ca *carAdder) Add(name string, fn files.Node) (cid.Cid, error) { func (ca *carAdder) Add(name string, fn files.Node) (api.Cid, error) {
if ca.params.Wrap { if ca.params.Wrap {
return cid.Undef, errors.New("cannot wrap a CAR file upload") return api.CidUndef, errors.New("cannot wrap a CAR file upload")
} }
f, ok := fn.(files.File) f, ok := fn.(files.File)
if !ok { if !ok {
return cid.Undef, errors.New("expected CAR file is not of type file") return api.CidUndef, errors.New("expected CAR file is not of type file")
} }
carReader, err := car.NewCarReader(f) carReader, err := car.NewCarReader(f)
if err != nil { if err != nil {
return cid.Undef, err return api.CidUndef, err
} }
if len(carReader.Header.Roots) != 1 { if len(carReader.Header.Roots) != 1 {
return cid.Undef, errors.New("only CAR files with a single root are supported") return api.CidUndef, errors.New("only CAR files with a single root are supported")
} }
root := carReader.Header.Roots[0] root := carReader.Header.Roots[0]
@ -292,7 +292,7 @@ func (ca *carAdder) Add(name string, fn files.Node) (cid.Cid, error) {
for { for {
block, err := carReader.Next() block, err := carReader.Next()
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
return cid.Undef, err return api.CidUndef, err
} else if block == nil { } else if block == nil {
break break
} }
@ -301,7 +301,7 @@ func (ca *carAdder) Add(name string, fn files.Node) (cid.Cid, error) {
nd, err := ipld.Decode(block) nd, err := ipld.Decode(block)
if err != nil { if err != nil {
return cid.Undef, err return api.CidUndef, err
} }
// If the root is in the CAR and the root is a UnixFS // If the root is in the CAR and the root is a UnixFS
@ -315,17 +315,17 @@ func (ca *carAdder) Add(name string, fn files.Node) (cid.Cid, error) {
err = ca.dgs.Add(ca.ctx, nd) err = ca.dgs.Add(ca.ctx, nd)
if err != nil { if err != nil {
return cid.Undef, err return api.CidUndef, err
} }
} }
ca.output <- api.AddedOutput{ ca.output <- api.AddedOutput{
Name: name, Name: name,
Cid: root, Cid: api.NewCid(root),
Bytes: bytes, Bytes: bytes,
Size: size, Size: size,
Allocations: ca.dgs.Allocations(), Allocations: ca.dgs.Allocations(),
} }
return root, nil return api.NewCid(root), nil
} }

View File

@ -28,7 +28,7 @@ func newMockCDAGServ() *mockCDAGServ {
} }
// noop // noop
func (dag *mockCDAGServ) Finalize(ctx context.Context, root cid.Cid) (cid.Cid, error) { func (dag *mockCDAGServ) Finalize(ctx context.Context, root api.Cid) (api.Cid, error) {
return root, nil return root, nil
} }
@ -152,7 +152,7 @@ func TestAdder_CAR(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
var carBuf bytes.Buffer var carBuf bytes.Buffer
err = car.WriteCar(ctx, dags, []cid.Cid{root}, &carBuf) err = car.WriteCar(ctx, dags, []cid.Cid{root.Cid}, &carBuf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -13,7 +13,6 @@ import (
"github.com/ipfs/ipfs-cluster/adder/single" "github.com/ipfs/ipfs-cluster/adder/single"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
rpc "github.com/libp2p/go-libp2p-gorpc" rpc "github.com/libp2p/go-libp2p-gorpc"
) )
@ -31,7 +30,7 @@ func AddMultipartHTTPHandler(
reader *multipart.Reader, reader *multipart.Reader,
w http.ResponseWriter, w http.ResponseWriter,
outputTransform func(api.AddedOutput) interface{}, outputTransform func(api.AddedOutput) interface{},
) (cid.Cid, error) { ) (api.Cid, error) {
var dags adder.ClusterDAGService var dags adder.ClusterDAGService
output := make(chan api.AddedOutput, 200) output := make(chan api.AddedOutput, 200)

View File

@ -446,7 +446,7 @@ func (adder *Adder) outputDagnode(out chan api.AddedOutput, name string, dn ipld
name = filepath.Join(adder.OutputPrefix, name) name = filepath.Join(adder.OutputPrefix, name)
out <- api.AddedOutput{ out <- api.AddedOutput{
Cid: dn.Cid(), Cid: api.NewCid(dn.Cid()),
Name: name, Name: name,
Size: s, Size: s,
Allocations: adder.allocsFun(), Allocations: adder.allocsFun(),

View File

@ -79,13 +79,13 @@ func (dgs *DAGService) Add(ctx context.Context, node ipld.Node) error {
// Finalize finishes sharding, creates the cluster DAG and pins it along // Finalize finishes sharding, creates the cluster DAG and pins it along
// with the meta pin for the root node of the content. // with the meta pin for the root node of the content.
func (dgs *DAGService) Finalize(ctx context.Context, dataRoot cid.Cid) (cid.Cid, error) { func (dgs *DAGService) Finalize(ctx context.Context, dataRoot api.Cid) (api.Cid, error) {
lastCid, err := dgs.flushCurrentShard(ctx) lastCid, err := dgs.flushCurrentShard(ctx)
if err != nil { if err != nil {
return lastCid, err return api.NewCid(lastCid), err
} }
if !lastCid.Equals(dataRoot) { if !lastCid.Equals(dataRoot.Cid) {
logger.Warnf("the last added CID (%s) is not the IPFS data root (%s). This is only normal when adding a single file without wrapping in directory.", lastCid, dataRoot) logger.Warnf("the last added CID (%s) is not the IPFS data root (%s). This is only normal when adding a single file without wrapping in directory.", lastCid, dataRoot)
} }
@ -124,13 +124,13 @@ func (dgs *DAGService) Finalize(ctx context.Context, dataRoot cid.Cid) (cid.Cid,
dgs.sendOutput(api.AddedOutput{ dgs.sendOutput(api.AddedOutput{
Name: fmt.Sprintf("%s-clusterDAG", dgs.addParams.Name), Name: fmt.Sprintf("%s-clusterDAG", dgs.addParams.Name),
Cid: clusterDAG, Cid: api.NewCid(clusterDAG),
Size: dgs.totalSize, Size: dgs.totalSize,
Allocations: nil, Allocations: nil,
}) })
// Pin the ClusterDAG // Pin the ClusterDAG
clusterDAGPin := api.PinWithOpts(clusterDAG, dgs.addParams.PinOptions) clusterDAGPin := api.PinWithOpts(api.NewCid(clusterDAG), dgs.addParams.PinOptions)
clusterDAGPin.ReplicationFactorMin = -1 clusterDAGPin.ReplicationFactorMin = -1
clusterDAGPin.ReplicationFactorMax = -1 clusterDAGPin.ReplicationFactorMax = -1
clusterDAGPin.MaxDepth = 0 // pin direct clusterDAGPin.MaxDepth = 0 // pin direct
@ -146,7 +146,8 @@ func (dgs *DAGService) Finalize(ctx context.Context, dataRoot cid.Cid) (cid.Cid,
// Pin the META pin // Pin the META pin
metaPin := api.PinWithOpts(dataRoot, dgs.addParams.PinOptions) metaPin := api.PinWithOpts(dataRoot, dgs.addParams.PinOptions)
metaPin.Type = api.MetaType metaPin.Type = api.MetaType
metaPin.Reference = &clusterDAG ref := api.NewCid(clusterDAG)
metaPin.Reference = &ref
metaPin.MaxDepth = 0 // irrelevant. Meta-pins are not pinned metaPin.MaxDepth = 0 // irrelevant. Meta-pins are not pinned
err = adder.Pin(ctx, dgs.rpcClient, metaPin) err = adder.Pin(ctx, dgs.rpcClient, metaPin)
if err != nil { if err != nil {
@ -238,7 +239,7 @@ func (dgs *DAGService) ingestBlock(ctx context.Context, n ipld.Node) error {
return dgs.ingestBlock(ctx, n) // <-- retry ingest return dgs.ingestBlock(ctx, n) // <-- retry ingest
} }
func (dgs *DAGService) logStats(metaPin, clusterDAGPin cid.Cid) { func (dgs *DAGService) logStats(metaPin, clusterDAGPin api.Cid) {
duration := time.Since(dgs.startTime) duration := time.Since(dgs.startTime)
seconds := uint64(duration) / uint64(time.Second) seconds := uint64(duration) / uint64(time.Second)
var rate string var rate string
@ -294,7 +295,7 @@ func (dgs *DAGService) flushCurrentShard(ctx context.Context) (cid.Cid, error) {
dgs.currentShard = nil dgs.currentShard = nil
dgs.sendOutput(api.AddedOutput{ dgs.sendOutput(api.AddedOutput{
Name: fmt.Sprintf("shard-%d", lens), Name: fmt.Sprintf("shard-%d", lens),
Cid: shardCid, Cid: api.NewCid(shardCid),
Size: shard.Size(), Size: shard.Size(),
Allocations: shard.Allocations(), Allocations: shard.Allocations(),
}) })

View File

@ -11,7 +11,6 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
rpc "github.com/libp2p/go-libp2p-gorpc" rpc "github.com/libp2p/go-libp2p-gorpc"
@ -51,7 +50,7 @@ func (rpcs *testRPC) BlockAllocate(ctx context.Context, in api.Pin, out *[]peer.
return nil return nil
} }
func (rpcs *testRPC) PinGet(ctx context.Context, c cid.Cid) (api.Pin, error) { func (rpcs *testRPC) PinGet(ctx context.Context, c api.Cid) (api.Pin, error) {
pI, ok := rpcs.pins.Load(c.String()) pI, ok := rpcs.pins.Load(c.String())
if !ok { if !ok {
return api.Pin{}, errors.New("not found") return api.Pin{}, errors.New("not found")
@ -59,7 +58,7 @@ func (rpcs *testRPC) PinGet(ctx context.Context, c cid.Cid) (api.Pin, error) {
return pI.(api.Pin), nil return pI.(api.Pin), nil
} }
func (rpcs *testRPC) BlockGet(ctx context.Context, c cid.Cid) ([]byte, error) { func (rpcs *testRPC) BlockGet(ctx context.Context, c api.Cid) ([]byte, error) {
bI, ok := rpcs.blocks.Load(c.String()) bI, ok := rpcs.blocks.Load(c.String())
if !ok { if !ok {
return nil, errors.New("not found") return nil, errors.New("not found")

View File

@ -122,12 +122,13 @@ func (sh *shard) Flush(ctx context.Context, shardN int, prev cid.Cid) (cid.Cid,
} }
rootCid := nodes[0].Cid() rootCid := nodes[0].Cid()
pin := api.PinWithOpts(rootCid, sh.pinOptions) pin := api.PinWithOpts(api.NewCid(rootCid), sh.pinOptions)
pin.Name = fmt.Sprintf("%s-shard-%d", sh.pinOptions.Name, shardN) pin.Name = fmt.Sprintf("%s-shard-%d", sh.pinOptions.Name, shardN)
// this sets allocations as priority allocation // this sets allocations as priority allocation
pin.Allocations = sh.allocations pin.Allocations = sh.allocations
pin.Type = api.ShardType pin.Type = api.ShardType
pin.Reference = &prev ref := api.NewCid(prev)
pin.Reference = &ref
pin.MaxDepth = 1 pin.MaxDepth = 1
pin.ShardSize = sh.Size() // use current size, not the limit pin.ShardSize = sh.Size() // use current size, not the limit
if len(nodes) > len(sh.dagNode)+1 { // using an indirect graph if len(nodes) > len(sh.dagNode)+1 { // using an indirect graph

View File

@ -7,26 +7,24 @@ import (
"testing" "testing"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
cid "github.com/ipfs/go-cid"
) )
// MockPinStore is used in VerifyShards // MockPinStore is used in VerifyShards
type MockPinStore interface { type MockPinStore interface {
// Gets a pin // Gets a pin
PinGet(context.Context, cid.Cid) (api.Pin, error) PinGet(context.Context, api.Cid) (api.Pin, error)
} }
// MockBlockStore is used in VerifyShards // MockBlockStore is used in VerifyShards
type MockBlockStore interface { type MockBlockStore interface {
// Gets a block // Gets a block
BlockGet(context.Context, cid.Cid) ([]byte, error) BlockGet(context.Context, api.Cid) ([]byte, error)
} }
// VerifyShards checks that a sharded CID has been correctly formed and stored. // VerifyShards checks that a sharded CID has been correctly formed and stored.
// This is a helper function for testing. It returns a map with all the blocks // This is a helper function for testing. It returns a map with all the blocks
// from all shards. // from all shards.
func VerifyShards(t *testing.T, rootCid cid.Cid, pins MockPinStore, ipfs MockBlockStore, expectedShards int) (map[string]struct{}, error) { func VerifyShards(t *testing.T, rootCid api.Cid, pins MockPinStore, ipfs MockBlockStore, expectedShards int) (map[string]struct{}, error) {
ctx := context.Background() ctx := context.Background()
metaPin, err := pins.PinGet(ctx, rootCid) metaPin, err := pins.PinGet(ctx, rootCid)
if err != nil { if err != nil {
@ -69,7 +67,7 @@ func VerifyShards(t *testing.T, rootCid cid.Cid, pins MockPinStore, ipfs MockBlo
} }
shardBlocks := make(map[string]struct{}) shardBlocks := make(map[string]struct{})
var ref cid.Cid var ref api.Cid
// traverse shards in order // traverse shards in order
for i := 0; i < len(shards); i++ { for i := 0; i < len(shards); i++ {
sh, _, err := clusterDAGNode.ResolveLink([]string{fmt.Sprintf("%d", i)}) sh, _, err := clusterDAGNode.ResolveLink([]string{fmt.Sprintf("%d", i)})
@ -77,12 +75,12 @@ func VerifyShards(t *testing.T, rootCid cid.Cid, pins MockPinStore, ipfs MockBlo
return nil, err return nil, err
} }
shardPin, err := pins.PinGet(ctx, sh.Cid) shardPin, err := pins.PinGet(ctx, api.NewCid(sh.Cid))
if err != nil { if err != nil {
return nil, fmt.Errorf("shard was not pinned: %s %s", sh.Cid, err) return nil, fmt.Errorf("shard was not pinned: %s %s", sh.Cid, err)
} }
if ref != cid.Undef && !shardPin.Reference.Equals(ref) { if ref != api.CidUndef && !shardPin.Reference.Equals(ref) {
t.Errorf("Ref (%s) should point to previous shard (%s)", ref, shardPin.Reference) t.Errorf("Ref (%s) should point to previous shard (%s)", ref, shardPin.Reference)
} }
ref = shardPin.Cid ref = shardPin.Cid

View File

@ -110,7 +110,7 @@ func (dgs *DAGService) Add(ctx context.Context, node ipld.Node) error {
} }
// Finalize pins the last Cid added to this DAGService. // Finalize pins the last Cid added to this DAGService.
func (dgs *DAGService) Finalize(ctx context.Context, root cid.Cid) (cid.Cid, error) { func (dgs *DAGService) Finalize(ctx context.Context, root api.Cid) (api.Cid, error) {
close(dgs.blocks) close(dgs.blocks)
select { select {

View File

@ -110,7 +110,7 @@ func IpldNodeToNodeWithMeta(n ipld.Node) api.NodeWithMeta {
} }
return api.NodeWithMeta{ return api.NodeWithMeta{
Cid: n.Cid(), Cid: api.NewCid(n.Cid()),
Data: n.RawData(), Data: n.RawData(),
CumSize: size, CumSize: size,
} }
@ -125,7 +125,7 @@ func BlockAllocate(ctx context.Context, rpc *rpc.Client, pinOpts api.PinOptions)
"", "",
"Cluster", "Cluster",
"BlockAllocate", "BlockAllocate",
api.PinWithOpts(cid.Undef, pinOpts), api.PinWithOpts(api.CidUndef, pinOpts),
&allocsStr, &allocsStr,
) )
return allocsStr, err return allocsStr, err

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
"go.opencensus.io/trace" "go.opencensus.io/trace"
@ -57,7 +56,7 @@ type classifiedMetrics struct {
// into account if the given CID was previously in a "pin everywhere" mode, // into account if the given CID was previously in a "pin everywhere" mode,
// and will consider such Pins as currently unallocated ones, providing // and will consider such Pins as currently unallocated ones, providing
// new allocations as available. // new allocations as available.
func (c *Cluster) allocate(ctx context.Context, hash cid.Cid, currentPin api.Pin, rplMin, rplMax int, blacklist []peer.ID, priorityList []peer.ID) ([]peer.ID, error) { func (c *Cluster) allocate(ctx context.Context, hash api.Cid, currentPin api.Pin, rplMin, rplMax int, blacklist []peer.ID, priorityList []peer.ID) ([]peer.ID, error) {
ctx, span := trace.StartSpan(ctx, "cluster/allocate") ctx, span := trace.StartSpan(ctx, "cluster/allocate")
defer span.End() defer span.End()
@ -180,7 +179,7 @@ func (c *Cluster) filterMetrics(ctx context.Context, mSet api.MetricsSet, numMet
} }
// allocationError logs an allocation error // allocationError logs an allocation error
func allocationError(hash cid.Cid, needed, wanted int, candidatesValid []peer.ID) error { func allocationError(hash api.Cid, needed, wanted int, candidatesValid []peer.ID) error {
logger.Errorf("Not enough candidates to allocate %s:", hash) logger.Errorf("Not enough candidates to allocate %s:", hash)
logger.Errorf(" Needed: %d", needed) logger.Errorf(" Needed: %d", needed)
logger.Errorf(" Wanted: %d", wanted) logger.Errorf(" Wanted: %d", wanted)
@ -198,7 +197,7 @@ func allocationError(hash cid.Cid, needed, wanted int, candidatesValid []peer.ID
func (c *Cluster) obtainAllocations( func (c *Cluster) obtainAllocations(
ctx context.Context, ctx context.Context,
hash cid.Cid, hash api.Cid,
rplMin, rplMax int, rplMin, rplMax int,
metrics classifiedMetrics, metrics classifiedMetrics,
) ([]peer.ID, error) { ) ([]peer.ID, error) {

View File

@ -12,7 +12,6 @@ import (
"fmt" "fmt"
"sort" "sort"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
api "github.com/ipfs/ipfs-cluster/api" api "github.com/ipfs/ipfs-cluster/api"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
@ -254,7 +253,7 @@ func (pnedm *partitionedMetric) chooseNext() peer.ID {
// - Third, based on the AllocateBy order, it select the first metric // - Third, based on the AllocateBy order, it select the first metric
func (a *Allocator) Allocate( func (a *Allocator) Allocate(
ctx context.Context, ctx context.Context,
c cid.Cid, c api.Cid,
current, candidates, priority api.MetricsSet, current, candidates, priority api.MetricsSet,
) ([]peer.ID, error) { ) ([]peer.ID, error) {

View File

@ -17,7 +17,7 @@ var DefaultShardSize = uint64(100 * 1024 * 1024) // 100 MB
// indicating a node of a file has been added. // indicating a node of a file has been added.
type AddedOutput struct { type AddedOutput struct {
Name string `json:"name" codec:"n,omitempty"` Name string `json:"name" codec:"n,omitempty"`
Cid cid.Cid `json:"cid" codec:"c"` Cid Cid `json:"cid" codec:"c"`
Bytes uint64 `json:"bytes,omitempty" codec:"b,omitempty"` Bytes uint64 `json:"bytes,omitempty" codec:"b,omitempty"`
Size uint64 `json:"size,omitempty" codec:"s,omitempty"` Size uint64 `json:"size,omitempty" codec:"s,omitempty"`
Allocations []peer.ID `json:"allocations,omitempty" codec:"a,omitempty"` Allocations []peer.ID `json:"allocations,omitempty" codec:"a,omitempty"`
@ -120,7 +120,7 @@ func AddParamsFromQuery(query url.Values) (AddParams, error) {
return params, err return params, err
} }
params.PinOptions = *opts params.PinOptions = *opts
params.PinUpdate = cid.Undef // hardcode as does not make sense for adding params.PinUpdate.Cid = cid.Undef // hardcode as does not make sense for adding
layout := query.Get("layout") layout := query.Get("layout")
switch layout { switch layout {

View File

@ -27,7 +27,6 @@ import (
"sync" "sync"
"time" "time"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
gopath "github.com/ipfs/go-path" gopath "github.com/ipfs/go-path"
types "github.com/ipfs/ipfs-cluster/api" types "github.com/ipfs/ipfs-cluster/api"
@ -69,8 +68,8 @@ var (
ErrHTTPEndpointNotEnabled = errors.New("the HTTP endpoint is not enabled") ErrHTTPEndpointNotEnabled = errors.New("the HTTP endpoint is not enabled")
) )
// When passed to SendResponse(), it will figure out which http status // SetStatusAutomatically can be passed to SendResponse(), so that it will
// to set by itself. // figure out which http status to set by itself.
const SetStatusAutomatically = -1 const SetStatusAutomatically = -1
// API implements an API and aims to provides // API implements an API and aims to provides
@ -496,12 +495,12 @@ func (api *API) ParsePinPathOrFail(w http.ResponseWriter, r *http.Request) types
return pinPath return pinPath
} }
// ParsePidOrFail parses a Cid and returns it or makes the request fail. // ParseCidOrFail parses a Cid and returns it or makes the request fail.
func (api *API) ParseCidOrFail(w http.ResponseWriter, r *http.Request) types.Pin { func (api *API) ParseCidOrFail(w http.ResponseWriter, r *http.Request) types.Pin {
vars := mux.Vars(r) vars := mux.Vars(r)
hash := vars["hash"] hash := vars["hash"]
c, err := cid.Decode(hash) c, err := types.DecodeCid(hash)
if err != nil { if err != nil {
api.SendResponse(w, http.StatusBadRequest, errors.New("error decoding Cid: "+err.Error()), nil) api.SendResponse(w, http.StatusBadRequest, errors.New("error decoding Cid: "+err.Error()), nil)
return types.Pin{} return types.Pin{}
@ -697,8 +696,8 @@ func (api *API) Headers() map[string][]string {
return api.config.Headers return api.config.Headers
} }
// Controls the HTTP server Keep Alive settings. // SetKeepAlivesEnabled controls the HTTP server Keep Alive settings. Useful
// Useful for testing. // for testing.
func (api *API) SetKeepAlivesEnabled(b bool) { func (api *API) SetKeepAlivesEnabled(b bool) {
api.server.SetKeepAlivesEnabled(b) api.server.SetKeepAlivesEnabled(b)
} }

View File

@ -122,7 +122,7 @@ func CheckHeaders(t *testing.T, expected map[string][]string, url string, header
} }
} }
// This represents what an API is to us. // API represents what an API is to us.
type API interface { type API interface {
HTTPAddresses() ([]string, error) HTTPAddresses() ([]string, error)
Host() host.Host Host() host.Host
@ -286,7 +286,7 @@ func BothEndpoints(t *testing.T, test Func) {
}) })
} }
// HTTPSEndpoint runs the given test.Func against an HTTPs endpoint. // HTTPSEndPoint runs the given test.Func against an HTTPs endpoint.
func HTTPSEndPoint(t *testing.T, test Func) { func HTTPSEndPoint(t *testing.T, test Func) {
t.Run("in-parallel", func(t *testing.T) { t.Run("in-parallel", func(t *testing.T) {
t.Run("https", func(t *testing.T) { t.Run("https", func(t *testing.T) {

View File

@ -1,3 +1,9 @@
// Package ipfsproxy implements the Cluster API interface by providing an
// IPFS HTTP interface as exposed by the go-ipfs daemon.
//
// In this API, select endpoints like pin*, add*, and repo* endpoints are used
// to instead perform cluster operations. Requests for any other endpoints are
// passed to the underlying IPFS daemon.
package ipfsproxy package ipfsproxy
import ( import (
@ -396,7 +402,7 @@ func (proxy *Server) pinLsHandler(w http.ResponseWriter, r *http.Request) {
} }
if arg != "" { if arg != "" {
c, err := cid.Decode(arg) c, err := api.DecodeCid(arg)
if err != nil { if err != nil {
ipfsErrorResponder(w, err.Error(), -1) ipfsErrorResponder(w, err.Error(), -1)
return return
@ -526,7 +532,7 @@ func (proxy *Server) pinUpdateHandler(w http.ResponseWriter, r *http.Request) {
} }
// Resolve the FROM argument // Resolve the FROM argument
var fromCid cid.Cid var fromCid api.Cid
err = proxy.rpcClient.CallContext( err = proxy.rpcClient.CallContext(
ctx, ctx,
"", "",
@ -733,9 +739,9 @@ func (proxy *Server) repoGCHandler(w http.ResponseWriter, r *http.Request) {
for _, gc := range repoGC.PeerMap { for _, gc := range repoGC.PeerMap {
for _, key := range gc.Keys { for _, key := range gc.Keys {
if streamErrors { if streamErrors {
ipfsRepoGC = ipfsRepoGCResp{Key: key.Key, Error: key.Error} ipfsRepoGC = ipfsRepoGCResp{Key: key.Key.Cid, Error: key.Error}
} else { } else {
ipfsRepoGC = ipfsRepoGCResp{Key: key.Key} ipfsRepoGC = ipfsRepoGCResp{Key: key.Key.Cid}
if key.Error != "" { if key.Error != "" {
mError.add(key.Error) mError.add(key.Error)
} }

View File

@ -13,8 +13,6 @@ import (
"testing" "testing"
"time" "time"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
@ -100,7 +98,7 @@ func TestIPFSProxyPin(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
want cid.Cid want api.Cid
wantErr bool wantErr bool
}{ }{
{ {
@ -140,7 +138,7 @@ func TestIPFSProxyPin(t *testing.T) {
test.ErrorCid.String(), test.ErrorCid.String(),
http.StatusInternalServerError, http.StatusInternalServerError,
}, },
cid.Undef, api.CidUndef,
true, true,
}, },
{ {
@ -150,7 +148,7 @@ func TestIPFSProxyPin(t *testing.T) {
test.ErrorCid.String(), test.ErrorCid.String(),
http.StatusInternalServerError, http.StatusInternalServerError,
}, },
cid.Undef, api.CidUndef,
true, true,
}, },
} }
@ -218,7 +216,7 @@ func TestIPFSProxyUnpin(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
want cid.Cid want api.Cid
wantErr bool wantErr bool
}{ }{
{ {
@ -258,7 +256,7 @@ func TestIPFSProxyUnpin(t *testing.T) {
test.ErrorCid.String(), test.ErrorCid.String(),
http.StatusInternalServerError, http.StatusInternalServerError,
}, },
cid.Undef, api.CidUndef,
true, true,
}, },
{ {
@ -268,7 +266,7 @@ func TestIPFSProxyUnpin(t *testing.T) {
test.ErrorCid.String(), test.ErrorCid.String(),
http.StatusInternalServerError, http.StatusInternalServerError,
}, },
cid.Undef, api.CidUndef,
true, true,
}, },
} }
@ -583,7 +581,7 @@ func TestProxyRepoGC(t *testing.T) {
repoGC = append(repoGC, resp) repoGC = append(repoGC, resp)
} }
if !repoGC[0].Key.Equals(test.Cid1) { if !repoGC[0].Key.Equals(test.Cid1.Cid) {
t.Errorf("expected a different cid, expected: %s, found: %s", test.Cid1, repoGC[0].Key) t.Errorf("expected a different cid, expected: %s, found: %s", test.Cid1, repoGC[0].Key)
} }

View File

@ -10,7 +10,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/ipfs/go-cid"
types "github.com/ipfs/ipfs-cluster/api" types "github.com/ipfs/ipfs-cluster/api"
) )
@ -54,7 +53,7 @@ func (pname *PinName) UnmarshalJSON(data []byte) error {
// Pin contains basic information about a Pin and pinning options. // Pin contains basic information about a Pin and pinning options.
type Pin struct { type Pin struct {
Cid string `json:"cid"` // a cid.Cid does not json properly Cid types.Cid `json:"cid"`
Name PinName `json:"name"` Name PinName `json:"name"`
Origins []types.Multiaddr `json:"origins"` Origins []types.Multiaddr `json:"origins"`
Meta map[string]string `json:"meta"` Meta map[string]string `json:"meta"`
@ -62,7 +61,7 @@ type Pin struct {
// Defined returns if the pinis empty (Cid not set). // Defined returns if the pinis empty (Cid not set).
func (p Pin) Defined() bool { func (p Pin) Defined() bool {
return p.Cid != "" return p.Cid.Defined()
} }
// MatchesName returns in a pin status matches a name option with a given // MatchesName returns in a pin status matches a name option with a given
@ -233,7 +232,7 @@ type PinList struct {
// ListOptions represents possible options given to the List endpoint. // ListOptions represents possible options given to the List endpoint.
type ListOptions struct { type ListOptions struct {
Cids []cid.Cid Cids []types.Cid
Name string Name string
MatchingStrategy MatchingStrategy MatchingStrategy MatchingStrategy
Status Status Status Status
@ -243,11 +242,12 @@ type ListOptions struct {
Meta map[string]string Meta map[string]string
} }
// FromQuery parses ListOptions from url.Values.
func (lo *ListOptions) FromQuery(q url.Values) error { func (lo *ListOptions) FromQuery(q url.Values) error {
cidq := q.Get("cid") cidq := q.Get("cid")
if len(cidq) > 0 { if len(cidq) > 0 {
for _, cstr := range strings.Split(cidq, ",") { for _, cstr := range strings.Split(cidq, ",") {
c, err := cid.Decode(cstr) c, err := types.DecodeCid(cstr)
if err != nil { if err != nil {
return fmt.Errorf("error decoding cid %s: %w", cstr, err) return fmt.Errorf("error decoding cid %s: %w", cstr, err)
} }

View File

@ -15,7 +15,6 @@ import (
"sync" "sync"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/ipfs/go-cid"
types "github.com/ipfs/ipfs-cluster/api" types "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/api/common" "github.com/ipfs/ipfs-cluster/api/common"
"github.com/ipfs/ipfs-cluster/api/pinsvcapi/pinsvc" "github.com/ipfs/ipfs-cluster/api/pinsvcapi/pinsvc"
@ -79,11 +78,7 @@ func svcPinToClusterPin(p pinsvc.Pin) (types.Pin, error) {
Metadata: p.Meta, Metadata: p.Meta,
Mode: types.PinModeRecursive, Mode: types.PinModeRecursive,
} }
c, err := cid.Decode(p.Cid) return types.PinWithOpts(p.Cid, opts), nil
if err != nil {
return types.Pin{}, err
}
return types.PinWithOpts(c, opts), nil
} }
func globalPinInfoToSvcPinStatus( func globalPinInfoToSvcPinStatus(
@ -103,7 +98,7 @@ func globalPinInfoToSvcPinStatus(
status.Status = trackerStatusToSvcStatus(statusMask) status.Status = trackerStatusToSvcStatus(statusMask)
status.Created = gpi.Created status.Created = gpi.Created
status.Pin = pinsvc.Pin{ status.Pin = pinsvc.Pin{
Cid: gpi.Cid.String(), Cid: gpi.Cid,
Name: pinsvc.PinName(gpi.Name), Name: pinsvc.PinName(gpi.Name),
Origins: gpi.Origins, Origins: gpi.Origins,
Meta: gpi.Metadata, Meta: gpi.Metadata,
@ -131,7 +126,7 @@ func NewAPI(ctx context.Context, cfg *Config) (*API, error) {
return NewAPIWithHost(ctx, cfg, nil) return NewAPIWithHost(ctx, cfg, nil)
} }
// NewAPI creates a new REST API component using the given libp2p Host. // NewAPIWithHost creates a new REST API component using the given libp2p Host.
func NewAPIWithHost(ctx context.Context, cfg *Config, h host.Host) (*API, error) { func NewAPIWithHost(ctx context.Context, cfg *Config, h host.Host) (*API, error) {
api := API{ api := API{
config: cfg, config: cfg,
@ -191,13 +186,13 @@ func (api *API) parseBodyOrFail(w http.ResponseWriter, r *http.Request) pinsvc.P
return pin return pin
} }
func (api *API) parseRequestIDOrFail(w http.ResponseWriter, r *http.Request) (cid.Cid, bool) { func (api *API) parseRequestIDOrFail(w http.ResponseWriter, r *http.Request) (types.Cid, bool) {
vars := mux.Vars(r) vars := mux.Vars(r)
cStr, ok := vars["requestID"] cStr, ok := vars["requestID"]
if !ok { if !ok {
return cid.Undef, true return types.CidUndef, true
} }
c, err := cid.Decode(cStr) c, err := types.DecodeCid(cStr)
if err != nil { if err != nil {
api.SendResponse(w, http.StatusBadRequest, errors.New("error decoding requestID: "+err.Error()), nil) api.SendResponse(w, http.StatusBadRequest, errors.New("error decoding requestID: "+err.Error()), nil)
return c, false return c, false
@ -233,12 +228,12 @@ func (api *API) addPin(w http.ResponseWriter, r *http.Request) {
return return
} }
status := api.pinToSvcPinStatus(r.Context(), pin.Cid, pinObj) status := api.pinToSvcPinStatus(r.Context(), pin.Cid.String(), pinObj)
api.SendResponse(w, common.SetStatusAutomatically, nil, status) api.SendResponse(w, common.SetStatusAutomatically, nil, status)
} }
} }
func (api *API) getPinSvcStatus(ctx context.Context, c cid.Cid) (pinsvc.PinStatus, error) { func (api *API) getPinSvcStatus(ctx context.Context, c types.Cid) (pinsvc.PinStatus, error) {
var pinInfo types.GlobalPinInfo var pinInfo types.GlobalPinInfo
err := api.rpcClient.CallContext( err := api.rpcClient.CallContext(
@ -318,7 +313,7 @@ func (api *API) listPins(w http.ResponseWriter, r *http.Request) {
}() }()
for _, ci := range opts.Cids { for _, ci := range opts.Cids {
go func(c cid.Cid) { go func(c types.Cid) {
defer wg.Done() defer wg.Done()
st, err := api.getPinSvcStatus(r.Context(), c) st, err := api.getPinSvcStatus(r.Context(), c)
stCh <- statusResult{st: st, err: err} stCh <- statusResult{st: st, err: err}
@ -410,7 +405,7 @@ func (api *API) pinToSvcPinStatus(ctx context.Context, rID string, pin types.Pin
Status: pinsvc.StatusQueued, Status: pinsvc.StatusQueued,
Created: pin.Timestamp, Created: pin.Timestamp,
Pin: pinsvc.Pin{ Pin: pinsvc.Pin{
Cid: pin.Cid.String(), Cid: pin.Cid,
Name: pinsvc.PinName(pin.Name), Name: pinsvc.PinName(pin.Name),
Origins: pin.Origins, Origins: pin.Origins,
Meta: pin.Metadata, Meta: pin.Metadata,

View File

@ -68,7 +68,7 @@ func TestAPIListEndpoint(t *testing.T) {
} }
results := resp.Results results := resp.Results
if results[0].Pin.Cid != clustertest.Cid1.String() || if !results[0].Pin.Cid.Equals(clustertest.Cid1) ||
results[1].Status != pinsvc.StatusPinning { results[1].Status != pinsvc.StatusPinning {
t.Errorf("unexpected statusAll resp: %+v", results) t.Errorf("unexpected statusAll resp: %+v", results)
} }
@ -161,7 +161,7 @@ func TestAPIPinEndpoint(t *testing.T) {
tf := func(t *testing.T, url test.URLFunc) { tf := func(t *testing.T, url test.URLFunc) {
// test normal pin // test normal pin
pin := pinsvc.Pin{ pin := pinsvc.Pin{
Cid: clustertest.Cid3.String(), Cid: clustertest.Cid3,
Name: "testname", Name: "testname",
Origins: []api.Multiaddr{ Origins: []api.Multiaddr{
ma, ma,
@ -192,7 +192,7 @@ func TestAPIPinEndpoint(t *testing.T) {
var errName pinsvc.APIError var errName pinsvc.APIError
pin2 := pinsvc.Pin{ pin2 := pinsvc.Pin{
Cid: clustertest.Cid1.String(), Cid: clustertest.Cid1,
Name: pinsvc.PinName(make([]byte, 256)), Name: pinsvc.PinName(make([]byte, 256)),
} }
pinJSON, err = json.Marshal(pin2) pinJSON, err = json.Marshal(pin2)
@ -218,7 +218,7 @@ func TestAPIGetPinEndpoint(t *testing.T) {
var status pinsvc.PinStatus var status pinsvc.PinStatus
test.MakeGet(t, svcapi, url(svcapi)+"/pins/"+clustertest.Cid1.String(), &status) test.MakeGet(t, svcapi, url(svcapi)+"/pins/"+clustertest.Cid1.String(), &status)
if status.Pin.Cid != clustertest.Cid1.String() { if !status.Pin.Cid.Equals(clustertest.Cid1) {
t.Error("Cid should be set") t.Error("Cid should be set")
} }

View File

@ -12,7 +12,6 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
cid "github.com/ipfs/go-cid"
shell "github.com/ipfs/go-ipfs-api" shell "github.com/ipfs/go-ipfs-api"
files "github.com/ipfs/go-ipfs-files" files "github.com/ipfs/go-ipfs-files"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
@ -64,9 +63,9 @@ type Client interface {
// Pin tracks a Cid with the given replication factor and a name for // Pin tracks a Cid with the given replication factor and a name for
// human-friendliness. // human-friendliness.
Pin(ctx context.Context, ci cid.Cid, opts api.PinOptions) (api.Pin, error) Pin(ctx context.Context, ci api.Cid, opts api.PinOptions) (api.Pin, error)
// Unpin untracks a Cid from cluster. // Unpin untracks a Cid from cluster.
Unpin(ctx context.Context, ci cid.Cid) (api.Pin, error) Unpin(ctx context.Context, ci api.Cid) (api.Pin, error)
// PinPath resolves given path into a cid and performs the pin operation. // PinPath resolves given path into a cid and performs the pin operation.
PinPath(ctx context.Context, path string, opts api.PinOptions) (api.Pin, error) PinPath(ctx context.Context, path string, opts api.PinOptions) (api.Pin, error)
@ -78,21 +77,21 @@ type Client interface {
// and the peers that should be pinning them. // and the peers that should be pinning them.
Allocations(ctx context.Context, filter api.PinType, out chan<- api.Pin) error Allocations(ctx context.Context, filter api.PinType, out chan<- api.Pin) error
// Allocation returns the current allocations for a given Cid. // Allocation returns the current allocations for a given Cid.
Allocation(ctx context.Context, ci cid.Cid) (api.Pin, error) Allocation(ctx context.Context, ci api.Cid) (api.Pin, error)
// Status returns the current ipfs state for a given Cid. If local is true, // Status returns the current ipfs state for a given Cid. If local is true,
// the information affects only the current peer, otherwise the information // the information affects only the current peer, otherwise the information
// is fetched from all cluster peers. // is fetched from all cluster peers.
Status(ctx context.Context, ci cid.Cid, local bool) (api.GlobalPinInfo, error) Status(ctx context.Context, ci api.Cid, local bool) (api.GlobalPinInfo, error)
// StatusCids status information for the requested CIDs. // StatusCids status information for the requested CIDs.
StatusCids(ctx context.Context, cids []cid.Cid, local bool, out chan<- api.GlobalPinInfo) error StatusCids(ctx context.Context, cids []api.Cid, local bool, out chan<- api.GlobalPinInfo) error
// StatusAll gathers Status() for all tracked items. // StatusAll gathers Status() for all tracked items.
StatusAll(ctx context.Context, filter api.TrackerStatus, local bool, out chan<- api.GlobalPinInfo) error StatusAll(ctx context.Context, filter api.TrackerStatus, local bool, out chan<- api.GlobalPinInfo) error
// Recover retriggers pin or unpin ipfs operations for a Cid in error // Recover retriggers pin or unpin ipfs operations for a Cid in error
// state. If local is true, the operation is limited to the current // state. If local is true, the operation is limited to the current
// peer, otherwise it happens on every cluster peer. // peer, otherwise it happens on every cluster peer.
Recover(ctx context.Context, ci cid.Cid, local bool) (api.GlobalPinInfo, error) Recover(ctx context.Context, ci api.Cid, local bool) (api.GlobalPinInfo, error)
// RecoverAll triggers Recover() operations on all tracked items. If // RecoverAll triggers Recover() operations on all tracked items. If
// local is true, the operation is limited to the current peer. // local is true, the operation is limited to the current peer.
// Otherwise, it happens everywhere. // Otherwise, it happens everywhere.

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"sync/atomic" "sync/atomic"
cid "github.com/ipfs/go-cid"
shell "github.com/ipfs/go-ipfs-api" shell "github.com/ipfs/go-ipfs-api"
files "github.com/ipfs/go-ipfs-files" files "github.com/ipfs/go-ipfs-files"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
@ -156,7 +155,7 @@ func (lc *loadBalancingClient) PeerRm(ctx context.Context, id peer.ID) error {
// Pin tracks a Cid with the given replication factor and a name for // Pin tracks a Cid with the given replication factor and a name for
// human-friendliness. // human-friendliness.
func (lc *loadBalancingClient) Pin(ctx context.Context, ci cid.Cid, opts api.PinOptions) (api.Pin, error) { func (lc *loadBalancingClient) Pin(ctx context.Context, ci api.Cid, opts api.PinOptions) (api.Pin, error) {
var pin api.Pin var pin api.Pin
call := func(c Client) error { call := func(c Client) error {
var err error var err error
@ -169,7 +168,7 @@ func (lc *loadBalancingClient) Pin(ctx context.Context, ci cid.Cid, opts api.Pin
} }
// Unpin untracks a Cid from cluster. // Unpin untracks a Cid from cluster.
func (lc *loadBalancingClient) Unpin(ctx context.Context, ci cid.Cid) (api.Pin, error) { func (lc *loadBalancingClient) Unpin(ctx context.Context, ci api.Cid) (api.Pin, error) {
var pin api.Pin var pin api.Pin
call := func(c Client) error { call := func(c Client) error {
var err error var err error
@ -220,7 +219,7 @@ func (lc *loadBalancingClient) Allocations(ctx context.Context, filter api.PinTy
} }
// Allocation returns the current allocations for a given Cid. // Allocation returns the current allocations for a given Cid.
func (lc *loadBalancingClient) Allocation(ctx context.Context, ci cid.Cid) (api.Pin, error) { func (lc *loadBalancingClient) Allocation(ctx context.Context, ci api.Cid) (api.Pin, error) {
var pin api.Pin var pin api.Pin
call := func(c Client) error { call := func(c Client) error {
var err error var err error
@ -235,7 +234,7 @@ func (lc *loadBalancingClient) Allocation(ctx context.Context, ci cid.Cid) (api.
// Status returns the current ipfs state for a given Cid. If local is true, // Status returns the current ipfs state for a given Cid. If local is true,
// the information affects only the current peer, otherwise the information // the information affects only the current peer, otherwise the information
// is fetched from all cluster peers. // is fetched from all cluster peers.
func (lc *loadBalancingClient) Status(ctx context.Context, ci cid.Cid, local bool) (api.GlobalPinInfo, error) { func (lc *loadBalancingClient) Status(ctx context.Context, ci api.Cid, local bool) (api.GlobalPinInfo, error) {
var pinInfo api.GlobalPinInfo var pinInfo api.GlobalPinInfo
call := func(c Client) error { call := func(c Client) error {
var err error var err error
@ -250,7 +249,7 @@ func (lc *loadBalancingClient) Status(ctx context.Context, ci cid.Cid, local boo
// StatusCids returns Status() information for the given Cids. If local is // StatusCids returns Status() information for the given Cids. If local is
// true, the information affects only the current peer, otherwise the // true, the information affects only the current peer, otherwise the
// information is fetched from all cluster peers. // information is fetched from all cluster peers.
func (lc *loadBalancingClient) StatusCids(ctx context.Context, cids []cid.Cid, local bool, out chan<- api.GlobalPinInfo) error { func (lc *loadBalancingClient) StatusCids(ctx context.Context, cids []api.Cid, local bool, out chan<- api.GlobalPinInfo) error {
call := func(c Client) error { call := func(c Client) error {
return c.StatusCids(ctx, cids, local, out) return c.StatusCids(ctx, cids, local, out)
} }
@ -276,7 +275,7 @@ func (lc *loadBalancingClient) StatusAll(ctx context.Context, filter api.Tracker
// Recover retriggers pin or unpin ipfs operations for a Cid in error state. // Recover retriggers pin or unpin ipfs operations for a Cid in error state.
// If local is true, the operation is limited to the current peer, otherwise // If local is true, the operation is limited to the current peer, otherwise
// it happens on every cluster peer. // it happens on every cluster peer.
func (lc *loadBalancingClient) Recover(ctx context.Context, ci cid.Cid, local bool) (api.GlobalPinInfo, error) { func (lc *loadBalancingClient) Recover(ctx context.Context, ci api.Cid, local bool) (api.GlobalPinInfo, error) {
var pinInfo api.GlobalPinInfo var pinInfo api.GlobalPinInfo
call := func(c Client) error { call := func(c Client) error {
var err error var err error

View File

@ -15,7 +15,6 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
cid "github.com/ipfs/go-cid"
files "github.com/ipfs/go-ipfs-files" files "github.com/ipfs/go-ipfs-files"
gopath "github.com/ipfs/go-path" gopath "github.com/ipfs/go-path"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
@ -85,7 +84,7 @@ func (c *defaultClient) PeerRm(ctx context.Context, id peer.ID) error {
// Pin tracks a Cid with the given replication factor and a name for // Pin tracks a Cid with the given replication factor and a name for
// human-friendliness. // human-friendliness.
func (c *defaultClient) Pin(ctx context.Context, ci cid.Cid, opts api.PinOptions) (api.Pin, error) { func (c *defaultClient) Pin(ctx context.Context, ci api.Cid, opts api.PinOptions) (api.Pin, error) {
ctx, span := trace.StartSpan(ctx, "client/Pin") ctx, span := trace.StartSpan(ctx, "client/Pin")
defer span.End() defer span.End()
@ -110,7 +109,7 @@ func (c *defaultClient) Pin(ctx context.Context, ci cid.Cid, opts api.PinOptions
} }
// Unpin untracks a Cid from cluster. // Unpin untracks a Cid from cluster.
func (c *defaultClient) Unpin(ctx context.Context, ci cid.Cid) (api.Pin, error) { func (c *defaultClient) Unpin(ctx context.Context, ci api.Cid) (api.Pin, error) {
ctx, span := trace.StartSpan(ctx, "client/Unpin") ctx, span := trace.StartSpan(ctx, "client/Unpin")
defer span.End() defer span.End()
var pin api.Pin var pin api.Pin
@ -212,7 +211,7 @@ func (c *defaultClient) Allocations(ctx context.Context, filter api.PinType, out
} }
// Allocation returns the current allocations for a given Cid. // Allocation returns the current allocations for a given Cid.
func (c *defaultClient) Allocation(ctx context.Context, ci cid.Cid) (api.Pin, error) { func (c *defaultClient) Allocation(ctx context.Context, ci api.Cid) (api.Pin, error) {
ctx, span := trace.StartSpan(ctx, "client/Allocation") ctx, span := trace.StartSpan(ctx, "client/Allocation")
defer span.End() defer span.End()
@ -224,7 +223,7 @@ func (c *defaultClient) Allocation(ctx context.Context, ci cid.Cid) (api.Pin, er
// Status returns the current ipfs state for a given Cid. If local is true, // Status returns the current ipfs state for a given Cid. If local is true,
// the information affects only the current peer, otherwise the information // the information affects only the current peer, otherwise the information
// is fetched from all cluster peers. // is fetched from all cluster peers.
func (c *defaultClient) Status(ctx context.Context, ci cid.Cid, local bool) (api.GlobalPinInfo, error) { func (c *defaultClient) Status(ctx context.Context, ci api.Cid, local bool) (api.GlobalPinInfo, error) {
ctx, span := trace.StartSpan(ctx, "client/Status") ctx, span := trace.StartSpan(ctx, "client/Status")
defer span.End() defer span.End()
@ -243,7 +242,7 @@ func (c *defaultClient) Status(ctx context.Context, ci cid.Cid, local bool) (api
// StatusCids returns Status() information for the given Cids. If local is // StatusCids returns Status() information for the given Cids. If local is
// true, the information affects only the current peer, otherwise the // true, the information affects only the current peer, otherwise the
// information is fetched from all cluster peers. // information is fetched from all cluster peers.
func (c *defaultClient) StatusCids(ctx context.Context, cids []cid.Cid, local bool, out chan<- api.GlobalPinInfo) error { func (c *defaultClient) StatusCids(ctx context.Context, cids []api.Cid, local bool, out chan<- api.GlobalPinInfo) error {
return c.statusAllWithCids(ctx, api.TrackerStatusUndefined, cids, local, out) return c.statusAllWithCids(ctx, api.TrackerStatusUndefined, cids, local, out)
} }
@ -256,7 +255,7 @@ func (c *defaultClient) StatusAll(ctx context.Context, filter api.TrackerStatus,
return c.statusAllWithCids(ctx, filter, nil, local, out) return c.statusAllWithCids(ctx, filter, nil, local, out)
} }
func (c *defaultClient) statusAllWithCids(ctx context.Context, filter api.TrackerStatus, cids []cid.Cid, local bool, out chan<- api.GlobalPinInfo) error { func (c *defaultClient) statusAllWithCids(ctx context.Context, filter api.TrackerStatus, cids []api.Cid, local bool, out chan<- api.GlobalPinInfo) error {
defer close(out) defer close(out)
ctx, span := trace.StartSpan(ctx, "client/StatusAll") ctx, span := trace.StartSpan(ctx, "client/StatusAll")
defer span.End() defer span.End()
@ -298,7 +297,7 @@ func (c *defaultClient) statusAllWithCids(ctx context.Context, filter api.Tracke
// Recover retriggers pin or unpin ipfs operations for a Cid in error state. // Recover retriggers pin or unpin ipfs operations for a Cid in error state.
// If local is true, the operation is limited to the current peer, otherwise // If local is true, the operation is limited to the current peer, otherwise
// it happens on every cluster peer. // it happens on every cluster peer.
func (c *defaultClient) Recover(ctx context.Context, ci cid.Cid, local bool) (api.GlobalPinInfo, error) { func (c *defaultClient) Recover(ctx context.Context, ci api.Cid, local bool) (api.GlobalPinInfo, error) {
ctx, span := trace.StartSpan(ctx, "client/Recover") ctx, span := trace.StartSpan(ctx, "client/Recover")
defer span.End() defer span.End()
@ -458,7 +457,7 @@ func WaitFor(ctx context.Context, c Client, fp StatusFilterParams) (api.GlobalPi
// StatusFilterParams contains the parameters required // StatusFilterParams contains the parameters required
// to filter a stream of status results. // to filter a stream of status results.
type StatusFilterParams struct { type StatusFilterParams struct {
Cid cid.Cid Cid api.Cid
Local bool // query status from the local peer only Local bool // query status from the local peer only
Target api.TrackerStatus Target api.TrackerStatus
Limit int // wait for N peers reaching status. 0 == all Limit int // wait for N peers reaching status. 0 == all

View File

@ -11,7 +11,6 @@ import (
rest "github.com/ipfs/ipfs-cluster/api/rest" rest "github.com/ipfs/ipfs-cluster/api/rest"
test "github.com/ipfs/ipfs-cluster/test" test "github.com/ipfs/ipfs-cluster/test"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
rpc "github.com/libp2p/go-libp2p-gorpc" rpc "github.com/libp2p/go-libp2p-gorpc"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
@ -227,7 +226,7 @@ func TestPinPath(t *testing.T) {
testF := func(t *testing.T, c Client) { testF := func(t *testing.T, c Client) {
for _, testCase := range pathTestCases { for _, testCase := range pathTestCases {
ec, _ := cid.Decode(testCase.expectedCid) ec, _ := types.DecodeCid(testCase.expectedCid)
resultantPin := types.PinWithOpts(ec, opts) resultantPin := types.PinWithOpts(ec, opts)
p := testCase.path p := testCase.path
pin, err := c.PinPath(ctx, p, opts) pin, err := c.PinPath(ctx, p, opts)
@ -351,7 +350,7 @@ func TestStatusCids(t *testing.T) {
out := make(chan types.GlobalPinInfo) out := make(chan types.GlobalPinInfo)
go func() { go func() {
err := c.StatusCids(ctx, []cid.Cid{test.Cid1}, false, out) err := c.StatusCids(ctx, []types.Cid{test.Cid1}, false, out)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -590,7 +589,7 @@ func (wait *waitService) Pin(ctx context.Context, in types.Pin, out *types.Pin)
return nil return nil
} }
func (wait *waitService) Status(ctx context.Context, in cid.Cid, out *types.GlobalPinInfo) error { func (wait *waitService) Status(ctx context.Context, in types.Cid, out *types.GlobalPinInfo) error {
wait.l.Lock() wait.l.Lock()
defer wait.l.Unlock() defer wait.l.Unlock()
if time.Now().After(wait.pinStart.Add(5 * time.Second)) { //pinned if time.Now().After(wait.pinStart.Add(5 * time.Second)) { //pinned
@ -642,7 +641,7 @@ func (wait *waitService) Status(ctx context.Context, in cid.Cid, out *types.Glob
return nil return nil
} }
func (wait *waitService) PinGet(ctx context.Context, in cid.Cid, out *types.Pin) error { func (wait *waitService) PinGet(ctx context.Context, in types.Cid, out *types.Pin) error {
p := types.PinCid(in) p := types.PinCid(in)
p.ReplicationFactorMin = 2 p.ReplicationFactorMin = 2
p.ReplicationFactorMax = 3 p.ReplicationFactorMax = 3
@ -662,7 +661,7 @@ func (wait *waitServiceUnpin) Unpin(ctx context.Context, in types.Pin, out *type
return nil return nil
} }
func (wait *waitServiceUnpin) Status(ctx context.Context, in cid.Cid, out *types.GlobalPinInfo) error { func (wait *waitServiceUnpin) Status(ctx context.Context, in types.Cid, out *types.GlobalPinInfo) error {
wait.l.Lock() wait.l.Lock()
defer wait.l.Unlock() defer wait.l.Unlock()
if time.Now().After(wait.unpinStart.Add(5 * time.Second)) { //unpinned if time.Now().After(wait.unpinStart.Add(5 * time.Second)) { //unpinned
@ -698,7 +697,7 @@ func (wait *waitServiceUnpin) Status(ctx context.Context, in cid.Cid, out *types
return nil return nil
} }
func (wait *waitServiceUnpin) PinGet(ctx context.Context, in cid.Cid, out *types.Pin) error { func (wait *waitServiceUnpin) PinGet(ctx context.Context, in types.Cid, out *types.Pin) error {
return errors.New("not found") return errors.New("not found")
} }

View File

@ -17,7 +17,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/ipfs/go-cid"
"github.com/ipfs/ipfs-cluster/adder/adderutils" "github.com/ipfs/ipfs-cluster/adder/adderutils"
types "github.com/ipfs/ipfs-cluster/api" types "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/api/common" "github.com/ipfs/ipfs-cluster/api/common"
@ -611,10 +610,10 @@ func (api *API) statusCidsHandler(w http.ResponseWriter, r *http.Request) {
queryValues := r.URL.Query() queryValues := r.URL.Query()
filterCidsStr := strings.Split(queryValues.Get("cids"), ",") filterCidsStr := strings.Split(queryValues.Get("cids"), ",")
var cids []cid.Cid var cids []types.Cid
for _, cidStr := range filterCidsStr { for _, cidStr := range filterCidsStr {
c, err := cid.Decode(cidStr) c, err := types.DecodeCid(cidStr)
if err != nil { if err != nil {
api.SendResponse(w, http.StatusBadRequest, fmt.Errorf("error decoding Cid: %w", err), nil) api.SendResponse(w, http.StatusBadRequest, fmt.Errorf("error decoding Cid: %w", err), nil)
return return
@ -638,7 +637,7 @@ func (api *API) statusCidsHandler(w http.ResponseWriter, r *http.Request) {
if local == "true" { if local == "true" {
for _, ci := range cids { for _, ci := range cids {
go func(c cid.Cid) { go func(c types.Cid) {
defer wg.Done() defer wg.Done()
var pinInfo types.PinInfo var pinInfo types.PinInfo
err := api.rpcClient.CallContext( err := api.rpcClient.CallContext(
@ -658,7 +657,7 @@ func (api *API) statusCidsHandler(w http.ResponseWriter, r *http.Request) {
} }
} else { } else {
for _, ci := range cids { for _, ci := range cids {
go func(c cid.Cid) { go func(c types.Cid) {
defer wg.Done() defer wg.Done()
var pinInfo types.GlobalPinInfo var pinInfo types.GlobalPinInfo
err := api.rpcClient.CallContext( err := api.rpcClient.CallContext(

View File

@ -13,7 +13,6 @@ import (
test "github.com/ipfs/ipfs-cluster/api/common/test" test "github.com/ipfs/ipfs-cluster/api/common/test"
clustertest "github.com/ipfs/ipfs-cluster/test" clustertest "github.com/ipfs/ipfs-cluster/test"
cid "github.com/ipfs/go-cid"
libp2p "github.com/libp2p/go-libp2p" libp2p "github.com/libp2p/go-libp2p"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
@ -401,7 +400,7 @@ func TestAPIPinEndpointWithPath(t *testing.T) {
tf := func(t *testing.T, url test.URLFunc) { tf := func(t *testing.T, url test.URLFunc) {
for _, testCase := range pathTestCases[:3] { for _, testCase := range pathTestCases[:3] {
c, _ := cid.Decode(testCase.expectedCid) c, _ := api.DecodeCid(testCase.expectedCid)
resultantPin := api.PinWithOpts( resultantPin := api.PinWithOpts(
c, c,
testPinOpts, testPinOpts,

View File

@ -277,33 +277,66 @@ var ipfsPinStatus2TrackerStatusMap = map[IPFSPinStatus]TrackerStatus{
IPFSPinStatusError: TrackerStatusClusterError, //TODO(ajl): check suitability IPFSPinStatusError: TrackerStatusClusterError, //TODO(ajl): check suitability
} }
// Cid is a CID with the MarshalJSON/UnmarshalJSON methods overwritten. // Cid embeds a cid.Cid with the MarshalJSON/UnmarshalJSON methods overwritten.
type Cid cid.Cid type Cid struct {
cid.Cid
}
func (c Cid) String() string { // CidUndef is an Undefined CID.
return cid.Cid(c).String() var CidUndef = Cid{cid.Undef}
// NewCid wraps a cid.Cid in a Cid.
func NewCid(c cid.Cid) Cid {
return Cid{
Cid: c,
}
}
// DecodeCid parses a CID from its string form.
func DecodeCid(str string) (Cid, error) {
c, err := cid.Decode(str)
return Cid{c}, err
}
// CastCid returns a CID from its bytes.
func CastCid(bs []byte) (Cid, error) {
c, err := cid.Cast(bs)
return Cid{c}, err
} }
// MarshalJSON marshals a CID as JSON as a normal CID string. // MarshalJSON marshals a CID as JSON as a normal CID string.
func (c Cid) MarshalJSON() ([]byte, error) { func (c Cid) MarshalJSON() ([]byte, error) {
return json.Marshal(c.String()) if !c.Defined() {
return []byte("null"), nil
}
return []byte(`"` + c.String() + `"`), nil
} }
// UnmarshalJSON reads a CID from its representation as JSON string. // UnmarshalJSON reads a CID from its representation as JSON string.
func (c *Cid) UnmarshalJSON(b []byte) error { func (c *Cid) UnmarshalJSON(b []byte) error {
if string(b) == "null" {
*c = CidUndef
return nil
}
var cidStr string var cidStr string
err := json.Unmarshal(b, &cidStr) err := json.Unmarshal(b, &cidStr)
if err != nil { if err != nil {
return err return err
} }
cc, err := cid.Decode(cidStr) cc, err := DecodeCid(cidStr)
if err != nil { if err != nil {
return err return err
} }
*c = Cid(cc) *c = cc
return nil return nil
} }
// Equals returns true if two Cids are equal.
func (c Cid) Equals(c2 Cid) bool {
return c.Cid.Equals(c2.Cid)
}
// IPFSPinInfo represents an IPFS Pin, which only has a CID and type. // IPFSPinInfo represents an IPFS Pin, which only has a CID and type.
// Its JSON form is what IPFS returns when querying a pinset. // Its JSON form is what IPFS returns when querying a pinset.
type IPFSPinInfo struct { type IPFSPinInfo struct {
@ -314,7 +347,7 @@ type IPFSPinInfo struct {
// GlobalPinInfo contains cluster-wide status information about a tracked Cid, // GlobalPinInfo contains cluster-wide status information about a tracked Cid,
// indexed by cluster peer. // indexed by cluster peer.
type GlobalPinInfo struct { type GlobalPinInfo struct {
Cid cid.Cid `json:"cid" codec:"c"` Cid Cid `json:"cid" codec:"c"`
Name string `json:"name" codec:"n"` Name string `json:"name" codec:"n"`
Allocations []peer.ID `json:"allocations" codec:"a,omitempty"` Allocations []peer.ID `json:"allocations" codec:"a,omitempty"`
Origins []Multiaddr `json:"origins" codec:"g,omitempty"` Origins []Multiaddr `json:"origins" codec:"g,omitempty"`
@ -360,7 +393,7 @@ func (gpi *GlobalPinInfo) Defined() bool {
return gpi.Cid.Defined() return gpi.Cid.Defined()
} }
// Matches returns true if one of the statuses in GlobalPinInfo matches // Match returns true if one of the statuses in GlobalPinInfo matches
// the given filter. // the given filter.
func (gpi GlobalPinInfo) Match(filter TrackerStatus) bool { func (gpi GlobalPinInfo) Match(filter TrackerStatus) bool {
for _, pi := range gpi.PeerMap { for _, pi := range gpi.PeerMap {
@ -400,7 +433,7 @@ func (pis PinInfoShort) String() string {
// PinInfo holds information about local pins. This is used by the Pin // PinInfo holds information about local pins. This is used by the Pin
// Trackers. // Trackers.
type PinInfo struct { type PinInfo struct {
Cid cid.Cid `json:"cid" codec:"c"` Cid Cid `json:"cid" codec:"c"`
Name string `json:"name" codec:"m,omitempty"` Name string `json:"name" codec:"m,omitempty"`
Peer peer.ID `json:"peer" codec:"p,omitempty"` Peer peer.ID `json:"peer" codec:"p,omitempty"`
Allocations []peer.ID `json:"allocations" codec:"o,omitempty"` Allocations []peer.ID `json:"allocations" codec:"o,omitempty"`
@ -709,7 +742,7 @@ type PinOptions struct {
UserAllocations []peer.ID `json:"user_allocations" codec:"ua,omitempty"` UserAllocations []peer.ID `json:"user_allocations" codec:"ua,omitempty"`
ExpireAt time.Time `json:"expire_at" codec:"e,omitempty"` ExpireAt time.Time `json:"expire_at" codec:"e,omitempty"`
Metadata map[string]string `json:"metadata" codec:"m,omitempty"` Metadata map[string]string `json:"metadata" codec:"m,omitempty"`
PinUpdate cid.Cid `json:"pin_update,omitempty" codec:"pu,omitempty"` PinUpdate Cid `json:"pin_update,omitempty" codec:"pu,omitempty"`
Origins []Multiaddr `json:"origins" codec:"g,omitempty"` Origins []Multiaddr `json:"origins" codec:"g,omitempty"`
} }
@ -807,7 +840,7 @@ func (po PinOptions) ToQuery() (string, error) {
} }
q.Set(fmt.Sprintf("%s%s", pinOptionsMetaPrefix, k), v) q.Set(fmt.Sprintf("%s%s", pinOptionsMetaPrefix, k), v)
} }
if po.PinUpdate != cid.Undef { if po.PinUpdate.Defined() {
q.Set("pin-update", po.PinUpdate.String()) q.Set("pin-update", po.PinUpdate.String())
} }
@ -888,7 +921,7 @@ func (po *PinOptions) FromQuery(q url.Values) error {
updateStr := q.Get("pin-update") updateStr := q.Get("pin-update")
if updateStr != "" { if updateStr != "" {
updateCid, err := cid.Decode(updateStr) updateCid, err := DecodeCid(updateStr)
if err != nil { if err != nil {
return fmt.Errorf("error decoding update option parameter: %s", err) return fmt.Errorf("error decoding update option parameter: %s", err)
} }
@ -940,7 +973,7 @@ func (pd PinDepth) ToPinMode() PinMode {
type Pin struct { type Pin struct {
PinOptions PinOptions
Cid cid.Cid `json:"cid" codec:"c"` Cid Cid `json:"cid" codec:"c"`
// See PinType comments // See PinType comments
Type PinType `json:"type" codec:"t,omitempty"` Type PinType `json:"type" codec:"t,omitempty"`
@ -957,7 +990,7 @@ type Pin struct {
// MetaPin it is the ClusterDAG CID. For Shards, // MetaPin it is the ClusterDAG CID. For Shards,
// it is the previous shard CID. // it is the previous shard CID.
// When not needed the pointer is nil // When not needed the pointer is nil
Reference *cid.Cid `json:"reference" codec:"r,omitempty"` Reference *Cid `json:"reference" codec:"r,omitempty"`
// The time that the pin was submitted to the consensus layer. // The time that the pin was submitted to the consensus layer.
Timestamp time.Time `json:"timestamp" codec:"i,omitempty"` Timestamp time.Time `json:"timestamp" codec:"i,omitempty"`
@ -994,7 +1027,7 @@ func (pp PinPath) Defined() bool {
// PinCid is a shortcut to create a Pin only with a Cid. Default is for pin to // PinCid is a shortcut to create a Pin only with a Cid. Default is for pin to
// be recursive and the pin to be of DataType. // be recursive and the pin to be of DataType.
func PinCid(c cid.Cid) Pin { func PinCid(c Cid) Pin {
return Pin{ return Pin{
Cid: c, Cid: c,
Type: DataType, Type: DataType,
@ -1007,7 +1040,7 @@ func PinCid(c cid.Cid) Pin {
// PinWithOpts creates a new Pin calling PinCid(c) and then sets its // PinWithOpts creates a new Pin calling PinCid(c) and then sets its
// PinOptions fields with the given options. Pin fields that are linked to // PinOptions fields with the given options. Pin fields that are linked to
// options are set accordingly (MaxDepth from Mode). // options are set accordingly (MaxDepth from Mode).
func PinWithOpts(c cid.Cid, opts PinOptions) Pin { func PinWithOpts(c Cid, opts PinOptions) Pin {
p := PinCid(c) p := PinCid(c)
p.PinOptions = opts p.PinOptions = opts
p.MaxDepth = p.Mode.ToPinDepth() p.MaxDepth = p.Mode.ToPinDepth()
@ -1090,9 +1123,9 @@ func (pin *Pin) ProtoUnmarshal(data []byte) error {
if err != nil { if err != nil {
return err return err
} }
ci, err := cid.Cast(pbPin.GetCid()) ci, err := CastCid(pbPin.GetCid())
if err != nil { if err != nil {
pin.Cid = cid.Undef pin.Cid = CidUndef
} else { } else {
pin.Cid = ci pin.Cid = ci
} }
@ -1112,7 +1145,7 @@ func (pin *Pin) ProtoUnmarshal(data []byte) error {
pin.Allocations = allocs pin.Allocations = allocs
pin.MaxDepth = PinDepth(pbPin.GetMaxDepth()) pin.MaxDepth = PinDepth(pbPin.GetMaxDepth())
ref, err := cid.Cast(pbPin.GetReference()) ref, err := CastCid(pbPin.GetReference())
if err != nil { if err != nil {
pin.Reference = nil pin.Reference = nil
@ -1137,7 +1170,7 @@ func (pin *Pin) ProtoUnmarshal(data []byte) error {
pin.ExpireAt = time.Unix(int64(exp), 0) pin.ExpireAt = time.Unix(int64(exp), 0)
} }
pin.Metadata = opts.GetMetadata() pin.Metadata = opts.GetMetadata()
pinUpdate, err := cid.Cast(opts.GetPinUpdate()) pinUpdate, err := CastCid(opts.GetPinUpdate())
if err == nil { if err == nil {
pin.PinUpdate = pinUpdate pin.PinUpdate = pinUpdate
} }
@ -1230,9 +1263,9 @@ func (pin Pin) Defined() bool {
// NodeWithMeta specifies a block of data and a set of optional metadata fields // NodeWithMeta specifies a block of data and a set of optional metadata fields
// carrying information about the encoded ipld node // carrying information about the encoded ipld node
type NodeWithMeta struct { type NodeWithMeta struct {
Data []byte `codec:"d,omitempty"` Data []byte `codec:"d,omitempty"`
Cid cid.Cid `codec:"c,omitempty"` Cid Cid `codec:"c,omitempty"`
CumSize uint64 `codec:"s,omitempty"` // Cumulative size CumSize uint64 `codec:"s,omitempty"` // Cumulative size
} }
// Size returns how big is the block. It is different from CumSize, which // Size returns how big is the block. It is different from CumSize, which
@ -1357,8 +1390,8 @@ type IPFSRepoStat struct {
// IPFSRepoGC represents the streaming response sent from repo gc API of IPFS. // IPFSRepoGC represents the streaming response sent from repo gc API of IPFS.
type IPFSRepoGC struct { type IPFSRepoGC struct {
Key cid.Cid `json:"key,omitempty" codec:"k,omitempty"` Key Cid `json:"key,omitempty" codec:"k,omitempty"`
Error string `json:"error,omitempty" codec:"e,omitempty"` Error string `json:"error,omitempty" codec:"e,omitempty"`
} }
// RepoGC contains garbage collected CIDs from a cluster peer's IPFS daemon. // RepoGC contains garbage collected CIDs from a cluster peer's IPFS daemon.

View File

@ -8,7 +8,6 @@ import (
"testing" "testing"
"time" "time"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
multiaddr "github.com/multiformats/go-multiaddr" multiaddr "github.com/multiformats/go-multiaddr"
@ -263,7 +262,7 @@ func TestIDCodec(t *testing.T) {
} }
func TestPinCodec(t *testing.T) { func TestPinCodec(t *testing.T) {
ci, _ := cid.Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc") ci, _ := DecodeCid("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc")
pin := PinCid(ci) pin := PinCid(ci)
var buf bytes.Buffer var buf bytes.Buffer
enc := codec.NewEncoder(&buf, &codec.MsgpackHandle{}) enc := codec.NewEncoder(&buf, &codec.MsgpackHandle{})

View File

@ -19,7 +19,6 @@ import (
"github.com/ipfs/ipfs-cluster/version" "github.com/ipfs/ipfs-cluster/version"
"go.uber.org/multierr" "go.uber.org/multierr"
cid "github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
host "github.com/libp2p/go-libp2p-core/host" host "github.com/libp2p/go-libp2p-core/host"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
@ -1205,7 +1204,7 @@ func (c *Cluster) StatusAllLocal(ctx context.Context, filter api.TrackerStatus,
// Status returns the GlobalPinInfo for a given Cid as fetched from all // Status returns the GlobalPinInfo for a given Cid as fetched from all
// current peers. If an error happens, the GlobalPinInfo should contain // current peers. If an error happens, the GlobalPinInfo should contain
// as much information as could be fetched from the other peers. // as much information as could be fetched from the other peers.
func (c *Cluster) Status(ctx context.Context, h cid.Cid) (api.GlobalPinInfo, error) { func (c *Cluster) Status(ctx context.Context, h api.Cid) (api.GlobalPinInfo, error) {
_, span := trace.StartSpan(ctx, "cluster/Status") _, span := trace.StartSpan(ctx, "cluster/Status")
defer span.End() defer span.End()
ctx = trace.NewContext(c.ctx, span) ctx = trace.NewContext(c.ctx, span)
@ -1214,7 +1213,7 @@ func (c *Cluster) Status(ctx context.Context, h cid.Cid) (api.GlobalPinInfo, err
} }
// StatusLocal returns this peer's PinInfo for a given Cid. // StatusLocal returns this peer's PinInfo for a given Cid.
func (c *Cluster) StatusLocal(ctx context.Context, h cid.Cid) api.PinInfo { func (c *Cluster) StatusLocal(ctx context.Context, h api.Cid) api.PinInfo {
_, span := trace.StartSpan(ctx, "cluster/StatusLocal") _, span := trace.StartSpan(ctx, "cluster/StatusLocal")
defer span.End() defer span.End()
ctx = trace.NewContext(c.ctx, span) ctx = trace.NewContext(c.ctx, span)
@ -1225,8 +1224,8 @@ func (c *Cluster) StatusLocal(ctx context.Context, h cid.Cid) api.PinInfo {
// used for RecoverLocal and SyncLocal. // used for RecoverLocal and SyncLocal.
func (c *Cluster) localPinInfoOp( func (c *Cluster) localPinInfoOp(
ctx context.Context, ctx context.Context,
h cid.Cid, h api.Cid,
f func(context.Context, cid.Cid) (api.PinInfo, error), f func(context.Context, api.Cid) (api.PinInfo, error),
) (pInfo api.PinInfo, err error) { ) (pInfo api.PinInfo, err error) {
ctx, span := trace.StartSpan(ctx, "cluster/localPinInfoOp") ctx, span := trace.StartSpan(ctx, "cluster/localPinInfoOp")
defer span.End() defer span.End()
@ -1284,7 +1283,7 @@ func (c *Cluster) RecoverAllLocal(ctx context.Context, out chan<- api.PinInfo) e
// Recover operations ask IPFS to pin or unpin items in error state. Recover // Recover operations ask IPFS to pin or unpin items in error state. Recover
// is faster than calling Pin on the same CID as it avoids committing an // is faster than calling Pin on the same CID as it avoids committing an
// identical pin to the consensus layer. // identical pin to the consensus layer.
func (c *Cluster) Recover(ctx context.Context, h cid.Cid) (api.GlobalPinInfo, error) { func (c *Cluster) Recover(ctx context.Context, h api.Cid) (api.GlobalPinInfo, error) {
_, span := trace.StartSpan(ctx, "cluster/Recover") _, span := trace.StartSpan(ctx, "cluster/Recover")
defer span.End() defer span.End()
ctx = trace.NewContext(c.ctx, span) ctx = trace.NewContext(c.ctx, span)
@ -1298,7 +1297,7 @@ func (c *Cluster) Recover(ctx context.Context, h cid.Cid) (api.GlobalPinInfo, er
// Recover operations ask IPFS to pin or unpin items in error state. Recover // Recover operations ask IPFS to pin or unpin items in error state. Recover
// is faster than calling Pin on the same CID as it avoids committing an // is faster than calling Pin on the same CID as it avoids committing an
// identical pin to the consensus layer. // identical pin to the consensus layer.
func (c *Cluster) RecoverLocal(ctx context.Context, h cid.Cid) (api.PinInfo, error) { func (c *Cluster) RecoverLocal(ctx context.Context, h api.Cid) (api.PinInfo, error) {
_, span := trace.StartSpan(ctx, "cluster/RecoverLocal") _, span := trace.StartSpan(ctx, "cluster/RecoverLocal")
defer span.End() defer span.End()
ctx = trace.NewContext(c.ctx, span) ctx = trace.NewContext(c.ctx, span)
@ -1353,7 +1352,7 @@ func (c *Cluster) pinsSlice(ctx context.Context) ([]api.Pin, error) {
// assigned for the requested Cid, but does not indicate if // assigned for the requested Cid, but does not indicate if
// the item is successfully pinned. For that, use Status(). PinGet // the item is successfully pinned. For that, use Status(). PinGet
// returns an error if the given Cid is not part of the global state. // returns an error if the given Cid is not part of the global state.
func (c *Cluster) PinGet(ctx context.Context, h cid.Cid) (api.Pin, error) { func (c *Cluster) PinGet(ctx context.Context, h api.Cid) (api.Pin, error) {
_, span := trace.StartSpan(ctx, "cluster/PinGet") _, span := trace.StartSpan(ctx, "cluster/PinGet")
defer span.End() defer span.End()
ctx = trace.NewContext(c.ctx, span) ctx = trace.NewContext(c.ctx, span)
@ -1390,7 +1389,7 @@ func (c *Cluster) PinGet(ctx context.Context, h cid.Cid) (api.Pin, error) {
// //
// If the Update option is set, the pin options (including allocations) will // If the Update option is set, the pin options (including allocations) will
// be copied from an existing one. This is equivalent to running PinUpdate. // be copied from an existing one. This is equivalent to running PinUpdate.
func (c *Cluster) Pin(ctx context.Context, h cid.Cid, opts api.PinOptions) (api.Pin, error) { func (c *Cluster) Pin(ctx context.Context, h api.Cid, opts api.PinOptions) (api.Pin, error) {
_, span := trace.StartSpan(ctx, "cluster/Pin") _, span := trace.StartSpan(ctx, "cluster/Pin")
defer span.End() defer span.End()
@ -1521,12 +1520,12 @@ func (c *Cluster) pin(
return api.Pin{}, false, errFollowerMode return api.Pin{}, false, errFollowerMode
} }
if pin.Cid == cid.Undef { if !pin.Cid.Defined() {
return pin, false, errors.New("bad pin object") return pin, false, errors.New("bad pin object")
} }
// Handle pin updates when the option is set // Handle pin updates when the option is set
if update := pin.PinUpdate; update != cid.Undef && !update.Equals(pin.Cid) { if update := pin.PinUpdate; update.Defined() && !update.Equals(pin.Cid) {
pin, err := c.PinUpdate(ctx, update, pin.Cid, pin.PinOptions) pin, err := c.PinUpdate(ctx, update, pin.Cid, pin.PinOptions)
return pin, true, err return pin, true, err
} }
@ -1600,7 +1599,7 @@ func (c *Cluster) pin(
// //
// Unpin does not reflect the success or failure of underlying IPFS daemon // Unpin does not reflect the success or failure of underlying IPFS daemon
// unpinning operations, which happen in async fashion. // unpinning operations, which happen in async fashion.
func (c *Cluster) Unpin(ctx context.Context, h cid.Cid) (api.Pin, error) { func (c *Cluster) Unpin(ctx context.Context, h api.Cid) (api.Pin, error) {
_, span := trace.StartSpan(ctx, "cluster/Unpin") _, span := trace.StartSpan(ctx, "cluster/Unpin")
defer span.End() defer span.End()
ctx = trace.NewContext(c.ctx, span) ctx = trace.NewContext(c.ctx, span)
@ -1670,7 +1669,7 @@ func (c *Cluster) unpinClusterDag(metaPin api.Pin) error {
// IPFSConnector supports it - the default one does). This may offer // IPFSConnector supports it - the default one does). This may offer
// significant speed when pinning items which are similar to previously pinned // significant speed when pinning items which are similar to previously pinned
// content. // content.
func (c *Cluster) PinUpdate(ctx context.Context, from cid.Cid, to cid.Cid, opts api.PinOptions) (api.Pin, error) { func (c *Cluster) PinUpdate(ctx context.Context, from api.Cid, to api.Cid, opts api.PinOptions) (api.Pin, error) {
existing, err := c.PinGet(ctx, from) existing, err := c.PinGet(ctx, from)
if err != nil { // including when the existing pin is not found if err != nil { // including when the existing pin is not found
return api.Pin{}, err return api.Pin{}, err
@ -1728,7 +1727,7 @@ func (c *Cluster) UnpinPath(ctx context.Context, path string) (api.Pin, error) {
// pipeline is used to DAGify the file. Depending on input parameters this // pipeline is used to DAGify the file. Depending on input parameters this
// DAG can be added locally to the calling cluster peer's ipfs repo, or // DAG can be added locally to the calling cluster peer's ipfs repo, or
// sharded across the entire cluster. // sharded across the entire cluster.
func (c *Cluster) AddFile(ctx context.Context, reader *multipart.Reader, params api.AddParams) (cid.Cid, error) { func (c *Cluster) AddFile(ctx context.Context, reader *multipart.Reader, params api.AddParams) (api.Cid, error) {
// TODO: add context param and tracing // TODO: add context param and tracing
var dags adder.ClusterDAGService var dags adder.ClusterDAGService
@ -1842,7 +1841,7 @@ func (c *Cluster) getTrustedPeers(ctx context.Context, exclude peer.ID) ([]peer.
return trustedPeers, nil return trustedPeers, nil
} }
func (c *Cluster) setTrackerStatus(gpin *api.GlobalPinInfo, h cid.Cid, peers []peer.ID, status api.TrackerStatus, pin api.Pin, t time.Time) { func (c *Cluster) setTrackerStatus(gpin *api.GlobalPinInfo, h api.Cid, peers []peer.ID, status api.TrackerStatus, pin api.Pin, t time.Time) {
for _, p := range peers { for _, p := range peers {
pv := pingValueFromMetric(c.monitor.LatestForPeer(c.ctx, pingMetricName, p)) pv := pingValueFromMetric(c.monitor.LatestForPeer(c.ctx, pingMetricName, p))
gpin.Add(api.PinInfo{ gpin.Add(api.PinInfo{
@ -1864,7 +1863,7 @@ func (c *Cluster) setTrackerStatus(gpin *api.GlobalPinInfo, h cid.Cid, peers []p
} }
} }
func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h cid.Cid) (api.GlobalPinInfo, error) { func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h api.Cid) (api.GlobalPinInfo, error) {
ctx, span := trace.StartSpan(ctx, "cluster/globalPinInfoCid") ctx, span := trace.StartSpan(ctx, "cluster/globalPinInfoCid")
defer span.End() defer span.End()
@ -2008,7 +2007,7 @@ func (c *Cluster) globalPinInfoStream(ctx context.Context, comp, method string,
inChan = emptyChan inChan = emptyChan
} }
fullMap := make(map[cid.Cid]api.GlobalPinInfo) fullMap := make(map[api.Cid]api.GlobalPinInfo)
var members []peer.ID var members []peer.ID
var err error var err error
@ -2141,7 +2140,7 @@ func (c *Cluster) getIDForPeer(ctx context.Context, pid peer.ID) (*api.ID, error
// that order (the MetaPin is the last element). // that order (the MetaPin is the last element).
// It returns a slice with only the given Cid if it's not a known Cid or not a // It returns a slice with only the given Cid if it's not a known Cid or not a
// MetaPin. // MetaPin.
func (c *Cluster) cidsFromMetaPin(ctx context.Context, h cid.Cid) ([]cid.Cid, error) { func (c *Cluster) cidsFromMetaPin(ctx context.Context, h api.Cid) ([]api.Cid, error) {
ctx, span := trace.StartSpan(ctx, "cluster/cidsFromMetaPin") ctx, span := trace.StartSpan(ctx, "cluster/cidsFromMetaPin")
defer span.End() defer span.End()
@ -2150,7 +2149,7 @@ func (c *Cluster) cidsFromMetaPin(ctx context.Context, h cid.Cid) ([]cid.Cid, er
return nil, err return nil, err
} }
list := []cid.Cid{h} list := []api.Cid{h}
pin, err := cState.Get(ctx, h) pin, err := cState.Get(ctx, h)
if err != nil { if err != nil {
@ -2164,7 +2163,7 @@ func (c *Cluster) cidsFromMetaPin(ctx context.Context, h cid.Cid) ([]cid.Cid, er
if pin.Reference == nil { if pin.Reference == nil {
return nil, errors.New("metaPin.Reference is unset") return nil, errors.New("metaPin.Reference is unset")
} }
list = append([]cid.Cid{*pin.Reference}, list...) list = append([]api.Cid{*pin.Reference}, list...)
clusterDagPin, err := c.PinGet(ctx, *pin.Reference) clusterDagPin, err := c.PinGet(ctx, *pin.Reference)
if err != nil { if err != nil {
return list, fmt.Errorf("could not get clusterDAG pin from state. Malformed pin?: %s", err) return list, fmt.Errorf("could not get clusterDAG pin from state. Malformed pin?: %s", err)
@ -2180,7 +2179,7 @@ func (c *Cluster) cidsFromMetaPin(ctx context.Context, h cid.Cid) ([]cid.Cid, er
return list, fmt.Errorf("error parsing clusterDAG block: %s", err) return list, fmt.Errorf("error parsing clusterDAG block: %s", err)
} }
for _, l := range clusterDagNode.Links() { for _, l := range clusterDagNode.Links() {
list = append([]cid.Cid{l.Cid}, list...) list = append([]api.Cid{api.NewCid(l.Cid)}, list...)
} }
return list, nil return list, nil

View File

@ -21,7 +21,6 @@ import (
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
"github.com/ipfs/ipfs-cluster/version" "github.com/ipfs/ipfs-cluster/version"
cid "github.com/ipfs/go-cid"
gopath "github.com/ipfs/go-path" gopath "github.com/ipfs/go-path"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
rpc "github.com/libp2p/go-libp2p-gorpc" rpc "github.com/libp2p/go-libp2p-gorpc"
@ -68,7 +67,7 @@ func (ipfs *mockConnector) Pin(ctx context.Context, pin api.Pin) error {
return nil return nil
} }
func (ipfs *mockConnector) Unpin(ctx context.Context, c cid.Cid) error { func (ipfs *mockConnector) Unpin(ctx context.Context, c api.Cid) error {
ipfs.pins.Delete(c) ipfs.pins.Delete(c)
return nil return nil
} }
@ -96,7 +95,7 @@ func (ipfs *mockConnector) PinLs(ctx context.Context, in []string, out chan<- ap
default: default:
st = api.IPFSPinStatusRecursive st = api.IPFSPinStatusRecursive
} }
c := k.(cid.Cid) c := k.(api.Cid)
out <- api.IPFSPinInfo{Cid: api.Cid(c), Type: st} out <- api.IPFSPinInfo{Cid: api.Cid(c), Type: st}
return true return true
@ -123,10 +122,10 @@ func (ipfs *mockConnector) RepoGC(ctx context.Context) (api.RepoGC, error) {
}, nil }, nil
} }
func (ipfs *mockConnector) Resolve(ctx context.Context, path string) (cid.Cid, error) { func (ipfs *mockConnector) Resolve(ctx context.Context, path string) (api.Cid, error) {
_, err := gopath.ParsePath(path) _, err := gopath.ParsePath(path)
if err != nil { if err != nil {
return cid.Undef, err return api.CidUndef, err
} }
return test.CidResolved, nil return test.CidResolved, nil
@ -141,7 +140,7 @@ func (ipfs *mockConnector) BlockStream(ctx context.Context, in <-chan api.NodeWi
return nil return nil
} }
func (ipfs *mockConnector) BlockGet(ctx context.Context, c cid.Cid) ([]byte, error) { func (ipfs *mockConnector) BlockGet(ctx context.Context, c api.Cid) ([]byte, error) {
d, ok := ipfs.blocks.Load(c.String()) d, ok := ipfs.blocks.Load(c.String())
if !ok { if !ok {
return nil, errors.New("block not found") return nil, errors.New("block not found")
@ -444,7 +443,7 @@ func TestUnpinShard(t *testing.T) {
sharding.VerifyShards(t, root, cl, cl.ipfs, 14) sharding.VerifyShards(t, root, cl, cl.ipfs, 14)
// skipping errors, VerifyShards has checked // skipping errors, VerifyShards has checked
pinnedCids := []cid.Cid{} pinnedCids := []api.Cid{}
pinnedCids = append(pinnedCids, root) pinnedCids = append(pinnedCids, root)
metaPin, _ := cl.PinGet(ctx, root) metaPin, _ := cl.PinGet(ctx, root)
cDag, _ := cl.PinGet(ctx, *metaPin.Reference) cDag, _ := cl.PinGet(ctx, *metaPin.Reference)
@ -452,7 +451,7 @@ func TestUnpinShard(t *testing.T) {
cDagBlock, _ := cl.ipfs.BlockGet(ctx, cDag.Cid) cDagBlock, _ := cl.ipfs.BlockGet(ctx, cDag.Cid)
cDagNode, _ := sharding.CborDataToNode(cDagBlock, "cbor") cDagNode, _ := sharding.CborDataToNode(cDagBlock, "cbor")
for _, l := range cDagNode.Links() { for _, l := range cDagNode.Links() {
pinnedCids = append(pinnedCids, l.Cid) pinnedCids = append(pinnedCids, api.NewCid(l.Cid))
} }
t.Run("unpin clusterdag should fail", func(t *testing.T) { t.Run("unpin clusterdag should fail", func(t *testing.T) {
@ -464,7 +463,7 @@ func TestUnpinShard(t *testing.T) {
}) })
t.Run("unpin shard should fail", func(t *testing.T) { t.Run("unpin shard should fail", func(t *testing.T) {
_, err := cl.Unpin(ctx, cDagNode.Links()[0].Cid) _, err := cl.Unpin(ctx, api.NewCid(cDagNode.Links()[0].Cid))
if err == nil { if err == nil {
t.Fatal("should not allow unpinning shards directly") t.Fatal("should not allow unpinning shards directly")
} }
@ -504,10 +503,10 @@ func TestUnpinShard(t *testing.T) {
// cShard, _ := cid.Decode(test.ShardCid) // cShard, _ := cid.Decode(test.ShardCid)
// cCdag, _ := cid.Decode(test.CdagCid) // cCdag, _ := cid.Decode(test.CdagCid)
// cMeta, _ := cid.Decode(test.MetaRootCid) // cMeta, _ := cid.Decode(test.MetaRootCid)
// pinMeta(t, cl, []cid.Cid{cShard}, cCdag, cMeta) // pinMeta(t, cl, []api.NewCid(cShard), cCdag, cMeta)
// } // }
// func pinMeta(t *testing.T, cl *Cluster, shardCids []cid.Cid, cCdag, cMeta cid.Cid) { // func pinMeta(t *testing.T, cl *Cluster, shardCids []api.Cid, cCdag, cMeta api.Cid) {
// for _, cShard := range shardCids { // for _, cShard := range shardCids {
// shardPin := api.Pin{ // shardPin := api.Pin{
// Cid: cShard, // Cid: cShard,
@ -609,7 +608,7 @@ func TestUnpinShard(t *testing.T) {
// cShard2, _ := cid.Decode(test.ShardCid2) // cShard2, _ := cid.Decode(test.ShardCid2)
// cCdag2, _ := cid.Decode(test.CdagCid2) // cCdag2, _ := cid.Decode(test.CdagCid2)
// cMeta2, _ := cid.Decode(test.MetaRootCid2) // cMeta2, _ := cid.Decode(test.MetaRootCid2)
// pinMeta(t, cl, []cid.Cid{cShard, cShard2}, cCdag2, cMeta2) // pinMeta(t, cl, []api.Cid{cShard, cShard2}, cCdag2, cMeta2)
// shardPin, err := cl.PinGet(cShard) // shardPin, err := cl.PinGet(cShard)
// if err != nil { // if err != nil {

View File

@ -15,7 +15,6 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/api/rest/client" "github.com/ipfs/ipfs-cluster/api/rest/client"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
@ -784,7 +783,7 @@ existing item from the cluster. Please run "pin rm" for that.
from := c.Args().Get(0) from := c.Args().Get(0)
to := c.Args().Get(1) to := c.Args().Get(1)
fromCid, err := cid.Decode(from) fromCid, err := api.DecodeCid(from)
checkErr("parsing from Cid", err) checkErr("parsing from Cid", err)
var expireAt time.Time var expireAt time.Time
@ -842,7 +841,7 @@ The filter only takes effect when listing all pins. The possible values are:
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
cidStr := c.Args().First() cidStr := c.Args().First()
if cidStr != "" { if cidStr != "" {
ci, err := cid.Decode(cidStr) ci, err := api.DecodeCid(cidStr)
checkErr("parsing cid", err) checkErr("parsing cid", err)
resp, cerr := globalClient.Allocation(ctx, ci) resp, cerr := globalClient.Allocation(ctx, ci)
formatResponse(c, resp, cerr) formatResponse(c, resp, cerr)
@ -889,9 +888,9 @@ separated list). The following are valid status values:
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
cidsStr := c.Args() cidsStr := c.Args()
cids := make([]cid.Cid, len(cidsStr)) cids := make([]api.Cid, len(cidsStr))
for i, cStr := range cidsStr { for i, cStr := range cidsStr {
ci, err := cid.Decode(cStr) ci, err := api.DecodeCid(cStr)
checkErr("parsing cid", err) checkErr("parsing cid", err)
cids[i] = ci cids[i] = ci
} }
@ -944,7 +943,7 @@ operations on the contacted peer (as opposed to on every peer).
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
cidStr := c.Args().First() cidStr := c.Args().First()
if cidStr != "" { if cidStr != "" {
ci, err := cid.Decode(cidStr) ci, err := api.DecodeCid(cidStr)
checkErr("parsing cid", err) checkErr("parsing cid", err)
resp, cerr := globalClient.Recover(ctx, ci, c.Bool("local")) resp, cerr := globalClient.Recover(ctx, ci, c.Bool("local"))
formatResponse(c, resp, cerr) formatResponse(c, resp, cerr)
@ -1215,7 +1214,7 @@ func handlePinResponseFormatFlags(
} }
func waitFor( func waitFor(
ci cid.Cid, ci api.Cid,
target api.TrackerStatus, target api.TrackerStatus,
timeout time.Duration, timeout time.Duration,
limit int, limit int,

View File

@ -9,7 +9,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/ipfs/go-cid"
ipfscluster "github.com/ipfs/ipfs-cluster" ipfscluster "github.com/ipfs/ipfs-cluster"
"github.com/ipfs/ipfs-cluster/allocator/balanced" "github.com/ipfs/ipfs-cluster/allocator/balanced"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
@ -548,7 +547,7 @@ func printStatusOffline(cfgHelper *cmdutils.ConfigHelper) error {
return err return err
} }
func printPin(c cid.Cid, status, name, err string) { func printPin(c api.Cid, status, name, err string) {
if err != "" { if err != "" {
name = name + " (" + err + ")" name = name + " (" + err + ")"
} }

View File

@ -1,3 +1,5 @@
// Package crdt implements the IPFS Cluster consensus interface using
// CRDT-datastore to replicate the cluster global state to every peer.
package crdt package crdt
import ( import (
@ -8,7 +10,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/ipfs/go-cid"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/pstoremgr" "github.com/ipfs/ipfs-cluster/pstoremgr"
"github.com/ipfs/ipfs-cluster/state" "github.com/ipfs/ipfs-cluster/state"
@ -238,7 +239,7 @@ func (css *Consensus) setup() {
logger.Error(err, k) logger.Error(err, k)
return return
} }
c, err := cid.Cast(kb) c, err := api.CastCid(kb)
if err != nil { if err != nil {
logger.Error(err, k) logger.Error(err, k)
return return

View File

@ -10,7 +10,6 @@ import (
"github.com/ipfs/ipfs-cluster/datastore/inmem" "github.com/ipfs/ipfs-cluster/datastore/inmem"
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
cid "github.com/ipfs/go-cid"
ipns "github.com/ipfs/go-ipns" ipns "github.com/ipfs/go-ipns"
libp2p "github.com/libp2p/go-libp2p" libp2p "github.com/libp2p/go-libp2p"
host "github.com/libp2p/go-libp2p-core/host" host "github.com/libp2p/go-libp2p-core/host"
@ -87,7 +86,7 @@ func clean(t *testing.T, cc *Consensus) {
} }
} }
func testPin(c cid.Cid) api.Pin { func testPin(c api.Cid) api.Pin {
p := api.PinCid(c) p := api.PinCid(c)
p.ReplicationFactorMin = -1 p.ReplicationFactorMin = -1
p.ReplicationFactorMax = -1 p.ReplicationFactorMax = -1
@ -453,7 +452,7 @@ func TestBatching(t *testing.T) {
} }
// Pin 4 things, and check that 3 are commited // Pin 4 things, and check that 3 are commited
for _, c := range []cid.Cid{test.Cid2, test.Cid3, test.Cid4, test.Cid5} { for _, c := range []api.Cid{test.Cid2, test.Cid3, test.Cid4, test.Cid5} {
err = cc.LogPin(ctx, testPin(c)) err = cc.LogPin(ctx, testPin(c))
if err != nil { if err != nil {
t.Error(err) t.Error(err)

View File

@ -12,7 +12,6 @@ import (
"github.com/ipfs/ipfs-cluster/state/dsstate" "github.com/ipfs/ipfs-cluster/state/dsstate"
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
cid "github.com/ipfs/go-cid"
libp2p "github.com/libp2p/go-libp2p" libp2p "github.com/libp2p/go-libp2p"
host "github.com/libp2p/go-libp2p-core/host" host "github.com/libp2p/go-libp2p-core/host"
peerstore "github.com/libp2p/go-libp2p-core/peerstore" peerstore "github.com/libp2p/go-libp2p-core/peerstore"
@ -22,7 +21,7 @@ func cleanRaft(idn int) {
os.RemoveAll(fmt.Sprintf("raftFolderFromTests-%d", idn)) os.RemoveAll(fmt.Sprintf("raftFolderFromTests-%d", idn))
} }
func testPin(c cid.Cid) api.Pin { func testPin(c api.Cid) api.Pin {
p := api.PinCid(c) p := api.PinCid(c)
p.ReplicationFactorMin = -1 p.ReplicationFactorMin = -1
p.ReplicationFactorMax = -1 p.ReplicationFactorMax = -1

View File

@ -12,7 +12,6 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/state" "github.com/ipfs/ipfs-cluster/state"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
rpc "github.com/libp2p/go-libp2p-gorpc" rpc "github.com/libp2p/go-libp2p-gorpc"
) )
@ -76,7 +75,7 @@ type IPFSConnector interface {
Component Component
ID(context.Context) (api.IPFSID, error) ID(context.Context) (api.IPFSID, error)
Pin(context.Context, api.Pin) error Pin(context.Context, api.Pin) error
Unpin(context.Context, cid.Cid) error Unpin(context.Context, api.Cid) error
PinLsCid(context.Context, api.Pin) (api.IPFSPinStatus, error) PinLsCid(context.Context, api.Pin) (api.IPFSPinStatus, error)
// PinLs returns pins in the pinset of the given types (recursive, direct...) // PinLs returns pins in the pinset of the given types (recursive, direct...)
PinLs(ctx context.Context, typeFilters []string, out chan<- api.IPFSPinInfo) error PinLs(ctx context.Context, typeFilters []string, out chan<- api.IPFSPinInfo) error
@ -94,11 +93,11 @@ type IPFSConnector interface {
// RepoGC performs garbage collection sweep on the IPFS repo. // RepoGC performs garbage collection sweep on the IPFS repo.
RepoGC(context.Context) (api.RepoGC, error) RepoGC(context.Context) (api.RepoGC, error)
// Resolve returns a cid given a path. // Resolve returns a cid given a path.
Resolve(context.Context, string) (cid.Cid, error) Resolve(context.Context, string) (api.Cid, error)
// BlockStream adds a stream of blocks to IPFS. // BlockStream adds a stream of blocks to IPFS.
BlockStream(context.Context, <-chan api.NodeWithMeta) error BlockStream(context.Context, <-chan api.NodeWithMeta) error
// BlockGet retrieves the raw data of an IPFS block. // BlockGet retrieves the raw data of an IPFS block.
BlockGet(context.Context, cid.Cid) ([]byte, error) BlockGet(context.Context, api.Cid) ([]byte, error)
} }
// Peered represents a component which needs to be aware of the peers // Peered represents a component which needs to be aware of the peers
@ -119,16 +118,16 @@ type PinTracker interface {
Track(context.Context, api.Pin) error Track(context.Context, api.Pin) error
// Untrack tells the tracker that a Cid is to be forgotten. The tracker // Untrack tells the tracker that a Cid is to be forgotten. The tracker
// may perform an IPFS unpin operation. // may perform an IPFS unpin operation.
Untrack(context.Context, cid.Cid) error Untrack(context.Context, api.Cid) error
// StatusAll returns the list of pins with their local status. Takes a // StatusAll returns the list of pins with their local status. Takes a
// filter to specify which statuses to report. // filter to specify which statuses to report.
StatusAll(context.Context, api.TrackerStatus, chan<- api.PinInfo) error StatusAll(context.Context, api.TrackerStatus, chan<- api.PinInfo) error
// Status returns the local status of a given Cid. // Status returns the local status of a given Cid.
Status(context.Context, cid.Cid) api.PinInfo Status(context.Context, api.Cid) api.PinInfo
// RecoverAll calls Recover() for all pins tracked. // RecoverAll calls Recover() for all pins tracked.
RecoverAll(context.Context, chan<- api.PinInfo) error RecoverAll(context.Context, chan<- api.PinInfo) error
// Recover retriggers a Pin/Unpin operation in a Cids with error status. // Recover retriggers a Pin/Unpin operation in a Cids with error status.
Recover(context.Context, cid.Cid) (api.PinInfo, error) Recover(context.Context, api.Cid) (api.PinInfo, error)
} }
// Informer provides Metric information from a peer. The metrics produced by // Informer provides Metric information from a peer. The metrics produced by
@ -155,7 +154,7 @@ type PinAllocator interface {
// which are currently pinning the content. The candidates map // which are currently pinning the content. The candidates map
// contains the metrics for all peers which are eligible for pinning // contains the metrics for all peers which are eligible for pinning
// the content. // the content.
Allocate(ctx context.Context, c cid.Cid, current, candidates, priority api.MetricsSet) ([]peer.ID, error) Allocate(ctx context.Context, c api.Cid, current, candidates, priority api.MetricsSet) ([]peer.ID, error)
// Metrics returns the list of metrics that the allocator needs. // Metrics returns the list of metrics that the allocator needs.
Metrics() []string Metrics() []string
} }

View File

@ -656,7 +656,7 @@ func TestClustersPin(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = clusters[j].Pin(ctx, h, api.PinOptions{}) _, err = clusters[j].Pin(ctx, api.NewCid(h), api.PinOptions{})
if err != nil { if err != nil {
t.Errorf("error pinning %s: %s", h, err) t.Errorf("error pinning %s: %s", h, err)
} }
@ -759,12 +759,12 @@ func TestClustersPinUpdate(t *testing.T) {
h, _ := prefix.Sum(randomBytes()) // create random cid h, _ := prefix.Sum(randomBytes()) // create random cid
h2, _ := prefix.Sum(randomBytes()) // create random cid h2, _ := prefix.Sum(randomBytes()) // create random cid
_, err := clusters[0].PinUpdate(ctx, h, h2, api.PinOptions{}) _, err := clusters[0].PinUpdate(ctx, api.NewCid(h), api.NewCid(h2), api.PinOptions{})
if err == nil || err != state.ErrNotFound { if err == nil || err != state.ErrNotFound {
t.Fatal("pin update should fail when from is not pinned") t.Fatal("pin update should fail when from is not pinned")
} }
_, err = clusters[0].Pin(ctx, h, api.PinOptions{}) _, err = clusters[0].Pin(ctx, api.NewCid(h), api.PinOptions{})
if err != nil { if err != nil {
t.Errorf("error pinning %s: %s", h, err) t.Errorf("error pinning %s: %s", h, err)
} }
@ -773,12 +773,12 @@ func TestClustersPinUpdate(t *testing.T) {
expiry := time.Now().AddDate(1, 0, 0) expiry := time.Now().AddDate(1, 0, 0)
opts2 := api.PinOptions{ opts2 := api.PinOptions{
UserAllocations: []peer.ID{clusters[0].host.ID()}, // should not be used UserAllocations: []peer.ID{clusters[0].host.ID()}, // should not be used
PinUpdate: h, PinUpdate: api.NewCid(h),
Name: "new name", Name: "new name",
ExpireAt: expiry, ExpireAt: expiry,
} }
_, err = clusters[0].Pin(ctx, h2, opts2) // should call PinUpdate _, err = clusters[0].Pin(ctx, api.NewCid(h2), opts2) // should call PinUpdate
if err != nil { if err != nil {
t.Errorf("error pin-updating %s: %s", h2, err) t.Errorf("error pin-updating %s: %s", h2, err)
} }
@ -786,7 +786,7 @@ func TestClustersPinUpdate(t *testing.T) {
pinDelay() pinDelay()
f := func(t *testing.T, c *Cluster) { f := func(t *testing.T, c *Cluster) {
pinget, err := c.PinGet(ctx, h2) pinget, err := c.PinGet(ctx, api.NewCid(h2))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -821,7 +821,7 @@ func TestClustersPinDirect(t *testing.T) {
h, _ := prefix.Sum(randomBytes()) // create random cid h, _ := prefix.Sum(randomBytes()) // create random cid
_, err := clusters[0].Pin(ctx, h, api.PinOptions{Mode: api.PinModeDirect}) _, err := clusters[0].Pin(ctx, api.NewCid(h), api.PinOptions{Mode: api.PinModeDirect})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -829,7 +829,7 @@ func TestClustersPinDirect(t *testing.T) {
pinDelay() pinDelay()
f := func(t *testing.T, c *Cluster, mode api.PinMode) { f := func(t *testing.T, c *Cluster, mode api.PinMode) {
pinget, err := c.PinGet(ctx, h) pinget, err := c.PinGet(ctx, api.NewCid(h))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -842,7 +842,7 @@ func TestClustersPinDirect(t *testing.T) {
t.Errorf("pin should have max-depth %d but has %d", mode.ToPinDepth(), pinget.MaxDepth) t.Errorf("pin should have max-depth %d but has %d", mode.ToPinDepth(), pinget.MaxDepth)
} }
pInfo := c.StatusLocal(ctx, h) pInfo := c.StatusLocal(ctx, api.NewCid(h))
if pInfo.Error != "" { if pInfo.Error != "" {
t.Error(pInfo.Error) t.Error(pInfo.Error)
} }
@ -857,7 +857,7 @@ func TestClustersPinDirect(t *testing.T) {
}) })
// Convert into a recursive mode // Convert into a recursive mode
_, err = clusters[0].Pin(ctx, h, api.PinOptions{Mode: api.PinModeRecursive}) _, err = clusters[0].Pin(ctx, api.NewCid(h), api.PinOptions{Mode: api.PinModeRecursive})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -869,7 +869,7 @@ func TestClustersPinDirect(t *testing.T) {
}) })
// This should fail as we cannot convert back to direct // This should fail as we cannot convert back to direct
_, err = clusters[0].Pin(ctx, h, api.PinOptions{Mode: api.PinModeDirect}) _, err = clusters[0].Pin(ctx, api.NewCid(h), api.PinOptions{Mode: api.PinModeDirect})
if err == nil { if err == nil {
t.Error("a recursive pin cannot be converted back to direct pin") t.Error("a recursive pin cannot be converted back to direct pin")
} }
@ -1229,14 +1229,14 @@ func TestClustersReplicationOverall(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = clusters[j].Pin(ctx, h, api.PinOptions{}) _, err = clusters[j].Pin(ctx, api.NewCid(h), api.PinOptions{})
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
pinDelay() pinDelay()
// check that it is held by exactly nClusters - 1 peers // check that it is held by exactly nClusters - 1 peers
gpi, err := clusters[j].Status(ctx, h) gpi, err := clusters[j].Status(ctx, api.NewCid(h))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -353,7 +353,7 @@ func (ipfs *Connector) Pin(ctx context.Context, pin api.Pin) error {
// If we have a pin-update, and the old object // If we have a pin-update, and the old object
// is pinned recursively, then do pin/update. // is pinned recursively, then do pin/update.
// Otherwise do a normal pin. // Otherwise do a normal pin.
if from := pin.PinUpdate; from != cid.Undef { if from := pin.PinUpdate; from.Defined() {
fromPin := api.PinWithOpts(from, pin.PinOptions) fromPin := api.PinWithOpts(from, pin.PinOptions)
pinStatus, _ := ipfs.PinLsCid(ctx, fromPin) pinStatus, _ := ipfs.PinLsCid(ctx, fromPin)
if pinStatus.IsPinned(-1) { // pinned recursively. if pinStatus.IsPinned(-1) { // pinned recursively.
@ -408,7 +408,7 @@ func (ipfs *Connector) Pin(ctx context.Context, pin api.Pin) error {
// pinProgress pins an item and sends fetched node's progress on a // pinProgress pins an item and sends fetched node's progress on a
// channel. Blocks until done or error. pinProgress will always close the out // channel. Blocks until done or error. pinProgress will always close the out
// channel. pinProgress will not block on sending to the channel if it is full. // channel. pinProgress will not block on sending to the channel if it is full.
func (ipfs *Connector) pinProgress(ctx context.Context, hash cid.Cid, maxDepth api.PinDepth, out chan<- int) error { func (ipfs *Connector) pinProgress(ctx context.Context, hash api.Cid, maxDepth api.PinDepth, out chan<- int) error {
defer close(out) defer close(out)
ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/pinsProgress") ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/pinsProgress")
@ -451,7 +451,7 @@ func (ipfs *Connector) pinProgress(ctx context.Context, hash cid.Cid, maxDepth a
} }
} }
func (ipfs *Connector) pinUpdate(ctx context.Context, from, to cid.Cid) error { func (ipfs *Connector) pinUpdate(ctx context.Context, from, to api.Cid) error {
ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/pinUpdate") ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/pinUpdate")
defer span.End() defer span.End()
@ -467,7 +467,7 @@ func (ipfs *Connector) pinUpdate(ctx context.Context, from, to cid.Cid) error {
// Unpin performs an unpin request against the configured IPFS // Unpin performs an unpin request against the configured IPFS
// daemon. // daemon.
func (ipfs *Connector) Unpin(ctx context.Context, hash cid.Cid) error { func (ipfs *Connector) Unpin(ctx context.Context, hash api.Cid) error {
ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/Unpin") ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/Unpin")
defer span.End() defer span.End()
@ -834,23 +834,23 @@ func (ipfs *Connector) RepoGC(ctx context.Context) (api.RepoGC, error) {
} }
} }
repoGC.Keys = append(repoGC.Keys, api.IPFSRepoGC{Key: resp.Key, Error: resp.Error}) repoGC.Keys = append(repoGC.Keys, api.IPFSRepoGC{Key: api.NewCid(resp.Key), Error: resp.Error})
} }
} }
// Resolve accepts ipfs or ipns path and resolves it into a cid // Resolve accepts ipfs or ipns path and resolves it into a cid
func (ipfs *Connector) Resolve(ctx context.Context, path string) (cid.Cid, error) { func (ipfs *Connector) Resolve(ctx context.Context, path string) (api.Cid, error) {
ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/Resolve") ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/Resolve")
defer span.End() defer span.End()
validPath, err := gopath.ParsePath(path) validPath, err := gopath.ParsePath(path)
if err != nil { if err != nil {
logger.Error("could not parse path: " + err.Error()) logger.Error("could not parse path: " + err.Error())
return cid.Undef, err return api.CidUndef, err
} }
if !strings.HasPrefix(path, "/ipns") && validPath.IsJustAKey() { if !strings.HasPrefix(path, "/ipns") && validPath.IsJustAKey() {
ci, _, err := gopath.SplitAbsPath(validPath) ci, _, err := gopath.SplitAbsPath(validPath)
return ci, err return api.NewCid(ci), err
} }
ctx, cancel := context.WithTimeout(ctx, ipfs.config.IPFSRequestTimeout) ctx, cancel := context.WithTimeout(ctx, ipfs.config.IPFSRequestTimeout)
@ -858,18 +858,18 @@ func (ipfs *Connector) Resolve(ctx context.Context, path string) (cid.Cid, error
res, err := ipfs.postCtx(ctx, "resolve?arg="+url.QueryEscape(path), "", nil) res, err := ipfs.postCtx(ctx, "resolve?arg="+url.QueryEscape(path), "", nil)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
return cid.Undef, err return api.CidUndef, err
} }
var resp ipfsResolveResp var resp ipfsResolveResp
err = json.Unmarshal(res, &resp) err = json.Unmarshal(res, &resp)
if err != nil { if err != nil {
logger.Error("could not unmarshal response: " + err.Error()) logger.Error("could not unmarshal response: " + err.Error())
return cid.Undef, err return api.CidUndef, err
} }
ci, _, err := gopath.SplitAbsPath(gopath.FromString(resp.Path)) ci, _, err := gopath.SplitAbsPath(gopath.FromString(resp.Path))
return ci, err return api.NewCid(ci), err
} }
// SwarmPeers returns the peers currently connected to this ipfs daemon. // SwarmPeers returns the peers currently connected to this ipfs daemon.
@ -950,15 +950,15 @@ func (ci *chanIterator) Node() files.Node {
return nil return nil
} }
ci.seenMu.Lock() ci.seenMu.Lock()
ci.seen.Add(ci.current.Cid) ci.seen.Add(ci.current.Cid.Cid)
ci.seenMu.Unlock() ci.seenMu.Unlock()
return files.NewBytesFile(ci.current.Data) return files.NewBytesFile(ci.current.Data)
} }
func (ci *chanIterator) Seen(c api.Cid) bool { func (ci *chanIterator) Seen(c api.Cid) bool {
ci.seenMu.Lock() ci.seenMu.Lock()
has := ci.seen.Has(cid.Cid(c)) has := ci.seen.Has(c.Cid)
ci.seen.Remove(cid.Cid(c)) ci.seen.Remove(c.Cid)
ci.seenMu.Unlock() ci.seenMu.Unlock()
return has return has
} }
@ -1117,7 +1117,7 @@ func (ipfs *Connector) BlockStream(ctx context.Context, blocks <-chan api.NodeWi
} }
// BlockGet retrieves an ipfs block with the given cid // BlockGet retrieves an ipfs block with the given cid
func (ipfs *Connector) BlockGet(ctx context.Context, c cid.Cid) ([]byte, error) { func (ipfs *Connector) BlockGet(ctx context.Context, c api.Cid) ([]byte, error) {
ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/BlockGet") ctx, span := trace.StartSpan(ctx, "ipfsconn/ipfshttp/BlockGet")
defer span.End() defer span.End()
@ -1129,7 +1129,7 @@ func (ipfs *Connector) BlockGet(ctx context.Context, c cid.Cid) ([]byte, error)
// // FetchRefs asks IPFS to download blocks recursively to the given depth. // // FetchRefs asks IPFS to download blocks recursively to the given depth.
// // It discards the response, but waits until it completes. // // It discards the response, but waits until it completes.
// func (ipfs *Connector) FetchRefs(ctx context.Context, c cid.Cid, maxDepth int) error { // func (ipfs *Connector) FetchRefs(ctx context.Context, c api.Cid, maxDepth int) error {
// ctx, cancel := context.WithTimeout(ipfs.ctx, ipfs.config.PinTimeout) // ctx, cancel := context.WithTimeout(ipfs.ctx, ipfs.config.PinTimeout)
// defer cancel() // defer cancel()

View File

@ -1,3 +1,4 @@
// Package observations sets up metric and trace exporting for IPFS cluster.
package observations package observations
import ( import (

View File

@ -12,7 +12,6 @@ import (
"github.com/ipfs/ipfs-cluster/config" "github.com/ipfs/ipfs-cluster/config"
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
cid "github.com/ipfs/go-cid"
host "github.com/libp2p/go-libp2p-core/host" host "github.com/libp2p/go-libp2p-core/host"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
@ -462,7 +461,7 @@ func TestClustersPeerRemoveReallocsPins(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = chosen.Pin(ctx, h, api.PinOptions{}) _, err = chosen.Pin(ctx, api.NewCid(h), api.PinOptions{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -474,7 +473,7 @@ func TestClustersPeerRemoveReallocsPins(t *testing.T) {
// At this point, all peers must have nClusters -1 pins // At this point, all peers must have nClusters -1 pins
// associated to them. // associated to them.
// Find out which pins are associated to the chosen peer. // Find out which pins are associated to the chosen peer.
interestingCids := []cid.Cid{} interestingCids := []api.Cid{}
pins, err := chosen.pinsSlice(ctx) pins, err := chosen.pinsSlice(ctx)
if err != nil { if err != nil {

View File

@ -7,8 +7,6 @@ import (
"sync" "sync"
"time" "time"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"go.opencensus.io/trace" "go.opencensus.io/trace"
) )
@ -109,7 +107,7 @@ func (op *Operation) String() string {
} }
// Cid returns the Cid associated to this operation. // Cid returns the Cid associated to this operation.
func (op *Operation) Cid() cid.Cid { func (op *Operation) Cid() api.Cid {
return op.pin.Cid return op.pin.Cid
} }

View File

@ -14,7 +14,6 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
@ -30,7 +29,7 @@ type OperationTracker struct {
peerName string peerName string
mu sync.RWMutex mu sync.RWMutex
operations map[cid.Cid]*Operation operations map[api.Cid]*Operation
} }
func (opt *OperationTracker) String() string { func (opt *OperationTracker) String() string {
@ -57,7 +56,7 @@ func NewOperationTracker(ctx context.Context, pid peer.ID, peerName string) *Ope
ctx: ctx, ctx: ctx,
pid: pid, pid: pid,
peerName: peerName, peerName: peerName,
operations: make(map[cid.Cid]*Operation), operations: make(map[api.Cid]*Operation),
} }
} }
@ -107,7 +106,7 @@ func (opt *OperationTracker) Clean(ctx context.Context, op *Operation) {
// Status returns the TrackerStatus associated to the last operation known // Status returns the TrackerStatus associated to the last operation known
// with the given Cid. It returns false if we are not tracking any operation // with the given Cid. It returns false if we are not tracking any operation
// for the given Cid. // for the given Cid.
func (opt *OperationTracker) Status(ctx context.Context, c cid.Cid) (api.TrackerStatus, bool) { func (opt *OperationTracker) Status(ctx context.Context, c api.Cid) (api.TrackerStatus, bool) {
opt.mu.RLock() opt.mu.RLock()
defer opt.mu.RUnlock() defer opt.mu.RUnlock()
op, ok := opt.operations[c] op, ok := opt.operations[c]
@ -122,7 +121,7 @@ func (opt *OperationTracker) Status(ctx context.Context, c cid.Cid) (api.Tracker
// is PhaseDone. Any other phases are considered in-flight and not touched. // is PhaseDone. Any other phases are considered in-flight and not touched.
// For things already in error, the error message is updated. // For things already in error, the error message is updated.
// Remote pins are ignored too. // Remote pins are ignored too.
func (opt *OperationTracker) SetError(ctx context.Context, c cid.Cid, err error) { func (opt *OperationTracker) SetError(ctx context.Context, c api.Cid, err error) {
opt.mu.Lock() opt.mu.Lock()
defer opt.mu.Unlock() defer opt.mu.Unlock()
op, ok := opt.operations[c] op, ok := opt.operations[c]
@ -143,7 +142,7 @@ func (opt *OperationTracker) SetError(ctx context.Context, c cid.Cid, err error)
func (opt *OperationTracker) unsafePinInfo(ctx context.Context, op *Operation, ipfs api.IPFSID) api.PinInfo { func (opt *OperationTracker) unsafePinInfo(ctx context.Context, op *Operation, ipfs api.IPFSID) api.PinInfo {
if op == nil { if op == nil {
return api.PinInfo{ return api.PinInfo{
Cid: cid.Undef, Cid: api.CidUndef,
Peer: opt.pid, Peer: opt.pid,
Name: "", Name: "",
PinInfoShort: api.PinInfoShort{ PinInfoShort: api.PinInfoShort{
@ -175,7 +174,7 @@ func (opt *OperationTracker) unsafePinInfo(ctx context.Context, op *Operation, i
} }
// Get returns a PinInfo object for Cid. // Get returns a PinInfo object for Cid.
func (opt *OperationTracker) Get(ctx context.Context, c cid.Cid, ipfs api.IPFSID) api.PinInfo { func (opt *OperationTracker) Get(ctx context.Context, c api.Cid, ipfs api.IPFSID) api.PinInfo {
ctx, span := trace.StartSpan(ctx, "optracker/GetAll") ctx, span := trace.StartSpan(ctx, "optracker/GetAll")
defer span.End() defer span.End()
@ -183,7 +182,7 @@ func (opt *OperationTracker) Get(ctx context.Context, c cid.Cid, ipfs api.IPFSID
defer opt.mu.RUnlock() defer opt.mu.RUnlock()
op := opt.operations[c] op := opt.operations[c]
pInfo := opt.unsafePinInfo(ctx, op, ipfs) pInfo := opt.unsafePinInfo(ctx, op, ipfs)
if pInfo.Cid == cid.Undef { if !pInfo.Cid.Defined() {
pInfo.Cid = c pInfo.Cid = c
} }
return pInfo return pInfo
@ -191,7 +190,7 @@ func (opt *OperationTracker) Get(ctx context.Context, c cid.Cid, ipfs api.IPFSID
// GetExists returns a PinInfo object for a Cid only if there exists // GetExists returns a PinInfo object for a Cid only if there exists
// an associated Operation. // an associated Operation.
func (opt *OperationTracker) GetExists(ctx context.Context, c cid.Cid, ipfs api.IPFSID) (api.PinInfo, bool) { func (opt *OperationTracker) GetExists(ctx context.Context, c api.Cid, ipfs api.IPFSID) (api.PinInfo, bool) {
ctx, span := trace.StartSpan(ctx, "optracker/GetExists") ctx, span := trace.StartSpan(ctx, "optracker/GetExists")
defer span.End() defer span.End()
@ -258,7 +257,7 @@ func (opt *OperationTracker) CleanAllDone(ctx context.Context) {
} }
// OpContext gets the context of an operation, if any. // OpContext gets the context of an operation, if any.
func (opt *OperationTracker) OpContext(ctx context.Context, c cid.Cid) context.Context { func (opt *OperationTracker) OpContext(ctx context.Context, c api.Cid) context.Context {
opt.mu.RLock() opt.mu.RLock()
defer opt.mu.RUnlock() defer opt.mu.RUnlock()
op, ok := opt.operations[c] op, ok := opt.operations[c]
@ -298,8 +297,8 @@ func (opt *OperationTracker) filterOps(ctx context.Context, filters ...interface
return fltops return fltops
} }
func filterOpsMap(ctx context.Context, ops map[cid.Cid]*Operation, filters []interface{}) map[cid.Cid]*Operation { func filterOpsMap(ctx context.Context, ops map[api.Cid]*Operation, filters []interface{}) map[api.Cid]*Operation {
fltops := make(map[cid.Cid]*Operation) fltops := make(map[api.Cid]*Operation)
if len(filters) < 1 { if len(filters) < 1 {
return nil return nil
} }
@ -315,7 +314,7 @@ func filterOpsMap(ctx context.Context, ops map[cid.Cid]*Operation, filters []int
return filterOpsMap(ctx, fltops, filters) return filterOpsMap(ctx, fltops, filters)
} }
func filter(ctx context.Context, in, out map[cid.Cid]*Operation, filter interface{}) { func filter(ctx context.Context, in, out map[api.Cid]*Operation, filter interface{}) {
for _, op := range in { for _, op := range in {
switch filter.(type) { switch filter.(type) {
case OperationType: case OperationType:

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"testing" "testing"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
) )
@ -203,7 +202,7 @@ func TestOperationTracker_OpContext(t *testing.T) {
func TestOperationTracker_filterOps(t *testing.T) { func TestOperationTracker_filterOps(t *testing.T) {
ctx := context.Background() ctx := context.Background()
testOpsMap := map[cid.Cid]*Operation{ testOpsMap := map[api.Cid]*Operation{
test.Cid1: {pin: api.PinCid(test.Cid1), opType: OperationPin, phase: PhaseQueued}, test.Cid1: {pin: api.PinCid(test.Cid1), opType: OperationPin, phase: PhaseQueued},
test.Cid2: {pin: api.PinCid(test.Cid2), opType: OperationPin, phase: PhaseInProgress}, test.Cid2: {pin: api.PinCid(test.Cid2), opType: OperationPin, phase: PhaseInProgress},
test.Cid3: {pin: api.PinCid(test.Cid3), opType: OperationUnpin, phase: PhaseInProgress}, test.Cid3: {pin: api.PinCid(test.Cid3), opType: OperationUnpin, phase: PhaseInProgress},

View File

@ -19,7 +19,6 @@ import (
"github.com/ipfs/ipfs-cluster/state/dsstate" "github.com/ipfs/ipfs-cluster/state/dsstate"
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
) )
@ -139,7 +138,7 @@ func BenchmarkPinTracker_Track(b *testing.B) {
func TestPinTracker_Untrack(t *testing.T) { func TestPinTracker_Untrack(t *testing.T) {
type args struct { type args struct {
c cid.Cid c api.Cid
tracker ipfscluster.PinTracker tracker ipfscluster.PinTracker
} }
tests := []struct { tests := []struct {
@ -273,7 +272,7 @@ func TestPinTracker_StatusAll(t *testing.T) {
func TestPinTracker_Status(t *testing.T) { func TestPinTracker_Status(t *testing.T) {
type args struct { type args struct {
c cid.Cid c api.Cid
tracker ipfscluster.PinTracker tracker ipfscluster.PinTracker
} }
tests := []struct { tests := []struct {
@ -397,7 +396,7 @@ func TestPinTracker_RecoverAll(t *testing.T) {
func TestPinTracker_Recover(t *testing.T) { func TestPinTracker_Recover(t *testing.T) {
type args struct { type args struct {
c cid.Cid c api.Cid
tracker ipfscluster.PinTracker tracker ipfscluster.PinTracker
} }
tests := []struct { tests := []struct {
@ -438,7 +437,7 @@ func TestPinTracker_Recover(t *testing.T) {
func TestUntrackTrack(t *testing.T) { func TestUntrackTrack(t *testing.T) {
type args struct { type args struct {
c cid.Cid c api.Cid
tracker ipfscluster.PinTracker tracker ipfscluster.PinTracker
} }
tests := []struct { tests := []struct {
@ -481,7 +480,7 @@ func TestUntrackTrack(t *testing.T) {
func TestTrackUntrackWithCancel(t *testing.T) { func TestTrackUntrackWithCancel(t *testing.T) {
type args struct { type args struct {
c cid.Cid c api.Cid
tracker ipfscluster.PinTracker tracker ipfscluster.PinTracker
} }
tests := []struct { tests := []struct {

View File

@ -14,7 +14,6 @@ import (
"github.com/ipfs/ipfs-cluster/pintracker/optracker" "github.com/ipfs/ipfs-cluster/pintracker/optracker"
"github.com/ipfs/ipfs-cluster/state" "github.com/ipfs/ipfs-cluster/state"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
rpc "github.com/libp2p/go-libp2p-gorpc" rpc "github.com/libp2p/go-libp2p-gorpc"
@ -315,7 +314,7 @@ func (spt *Tracker) Track(ctx context.Context, c api.Pin) error {
// Untrack tells the StatelessPinTracker to stop managing a Cid. // Untrack tells the StatelessPinTracker to stop managing a Cid.
// If the Cid is pinned locally, it will be unpinned. // If the Cid is pinned locally, it will be unpinned.
func (spt *Tracker) Untrack(ctx context.Context, c cid.Cid) error { func (spt *Tracker) Untrack(ctx context.Context, c api.Cid) error {
ctx, span := trace.StartSpan(ctx, "tracker/stateless/Untrack") ctx, span := trace.StartSpan(ctx, "tracker/stateless/Untrack")
defer span.End() defer span.End()
@ -455,7 +454,7 @@ func (spt *Tracker) StatusAll(ctx context.Context, filter api.TrackerStatus, out
} }
// Status returns information for a Cid pinned to the local IPFS node. // Status returns information for a Cid pinned to the local IPFS node.
func (spt *Tracker) Status(ctx context.Context, c cid.Cid) api.PinInfo { func (spt *Tracker) Status(ctx context.Context, c api.Cid) api.PinInfo {
ctx, span := trace.StartSpan(ctx, "tracker/stateless/Status") ctx, span := trace.StartSpan(ctx, "tracker/stateless/Status")
defer span.End() defer span.End()
@ -594,7 +593,7 @@ func (spt *Tracker) RecoverAll(ctx context.Context, out chan<- api.PinInfo) erro
// Recover will trigger pinning or unpinning for items in // Recover will trigger pinning or unpinning for items in
// PinError or UnpinError states. // PinError or UnpinError states.
func (spt *Tracker) Recover(ctx context.Context, c cid.Cid) (api.PinInfo, error) { func (spt *Tracker) Recover(ctx context.Context, c api.Cid) (api.PinInfo, error) {
ctx, span := trace.StartSpan(ctx, "tracker/stateless/Recover") ctx, span := trace.StartSpan(ctx, "tracker/stateless/Recover")
defer span.End() defer span.End()
@ -662,7 +661,7 @@ func (spt *Tracker) ipfsPins(ctx context.Context) (<-chan api.IPFSPinInfo, error
// OpContext exports the internal optracker's OpContext method. // OpContext exports the internal optracker's OpContext method.
// For testing purposes only. // For testing purposes only.
func (spt *Tracker) OpContext(ctx context.Context, c cid.Cid) context.Context { func (spt *Tracker) OpContext(ctx context.Context, c api.Cid) context.Context {
return spt.optracker.OpContext(ctx, c) return spt.optracker.OpContext(ctx, c)
} }

View File

@ -12,7 +12,6 @@ import (
"github.com/ipfs/ipfs-cluster/state/dsstate" "github.com/ipfs/ipfs-cluster/state/dsstate"
"github.com/ipfs/ipfs-cluster/test" "github.com/ipfs/ipfs-cluster/test"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
rpc "github.com/libp2p/go-libp2p-gorpc" rpc "github.com/libp2p/go-libp2p-gorpc"
) )
@ -286,7 +285,7 @@ func TestTrackUntrackWithNoCancel(t *testing.T) {
} }
pi := spt.optracker.Get(ctx, fastPin.Cid, api.IPFSID{}) pi := spt.optracker.Get(ctx, fastPin.Cid, api.IPFSID{})
if pi.Cid == cid.Undef { if !pi.Cid.Defined() {
t.Error("fastPin should have been removed from tracker") t.Error("fastPin should have been removed from tracker")
} }
} }
@ -318,7 +317,7 @@ func TestUntrackTrackWithCancel(t *testing.T) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
pi := spt.optracker.Get(ctx, slowPin.Cid, api.IPFSID{}) pi := spt.optracker.Get(ctx, slowPin.Cid, api.IPFSID{})
if pi.Cid == cid.Undef { if !pi.Cid.Defined() {
t.Fatal("expected slowPin to be tracked") t.Fatal("expected slowPin to be tracked")
} }
@ -379,7 +378,7 @@ func TestUntrackTrackWithNoCancel(t *testing.T) {
} }
pi := spt.optracker.Get(ctx, fastPin.Cid, api.IPFSID{}) pi := spt.optracker.Get(ctx, fastPin.Cid, api.IPFSID{})
if pi.Cid == cid.Undef { if !pi.Cid.Defined() {
t.Fatal("c untrack operation should be tracked") t.Fatal("c untrack operation should be tracked")
} }

View File

@ -8,7 +8,6 @@ import (
"github.com/ipfs/ipfs-cluster/state" "github.com/ipfs/ipfs-cluster/state"
"github.com/ipfs/ipfs-cluster/version" "github.com/ipfs/ipfs-cluster/version"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
rpc "github.com/libp2p/go-libp2p-gorpc" rpc "github.com/libp2p/go-libp2p-gorpc"
@ -221,7 +220,7 @@ func (rpcapi *ClusterRPCAPI) Pins(ctx context.Context, in <-chan struct{}, out c
} }
// PinGet runs Cluster.PinGet(). // PinGet runs Cluster.PinGet().
func (rpcapi *ClusterRPCAPI) PinGet(ctx context.Context, in cid.Cid, out *api.Pin) error { func (rpcapi *ClusterRPCAPI) PinGet(ctx context.Context, in api.Cid, out *api.Pin) error {
pin, err := rpcapi.c.PinGet(ctx, in) pin, err := rpcapi.c.PinGet(ctx, in)
if err != nil { if err != nil {
return err return err
@ -294,7 +293,7 @@ func (rpcapi *ClusterRPCAPI) StatusAllLocal(ctx context.Context, in <-chan api.T
} }
// Status runs Cluster.Status(). // Status runs Cluster.Status().
func (rpcapi *ClusterRPCAPI) Status(ctx context.Context, in cid.Cid, out *api.GlobalPinInfo) error { func (rpcapi *ClusterRPCAPI) Status(ctx context.Context, in api.Cid, out *api.GlobalPinInfo) error {
pinfo, err := rpcapi.c.Status(ctx, in) pinfo, err := rpcapi.c.Status(ctx, in)
if err != nil { if err != nil {
return err return err
@ -304,7 +303,7 @@ func (rpcapi *ClusterRPCAPI) Status(ctx context.Context, in cid.Cid, out *api.Gl
} }
// StatusLocal runs Cluster.StatusLocal(). // StatusLocal runs Cluster.StatusLocal().
func (rpcapi *ClusterRPCAPI) StatusLocal(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (rpcapi *ClusterRPCAPI) StatusLocal(ctx context.Context, in api.Cid, out *api.PinInfo) error {
pinfo := rpcapi.c.StatusLocal(ctx, in) pinfo := rpcapi.c.StatusLocal(ctx, in)
*out = pinfo *out = pinfo
return nil return nil
@ -321,7 +320,7 @@ func (rpcapi *ClusterRPCAPI) RecoverAllLocal(ctx context.Context, in <-chan stru
} }
// Recover runs Cluster.Recover(). // Recover runs Cluster.Recover().
func (rpcapi *ClusterRPCAPI) Recover(ctx context.Context, in cid.Cid, out *api.GlobalPinInfo) error { func (rpcapi *ClusterRPCAPI) Recover(ctx context.Context, in api.Cid, out *api.GlobalPinInfo) error {
pinfo, err := rpcapi.c.Recover(ctx, in) pinfo, err := rpcapi.c.Recover(ctx, in)
if err != nil { if err != nil {
return err return err
@ -331,7 +330,7 @@ func (rpcapi *ClusterRPCAPI) Recover(ctx context.Context, in cid.Cid, out *api.G
} }
// RecoverLocal runs Cluster.RecoverLocal(). // RecoverLocal runs Cluster.RecoverLocal().
func (rpcapi *ClusterRPCAPI) RecoverLocal(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (rpcapi *ClusterRPCAPI) RecoverLocal(ctx context.Context, in api.Cid, out *api.PinInfo) error {
pinfo, err := rpcapi.c.RecoverLocal(ctx, in) pinfo, err := rpcapi.c.RecoverLocal(ctx, in)
if err != nil { if err != nil {
return err return err
@ -411,7 +410,7 @@ func (rpcapi *ClusterRPCAPI) RepoGCLocal(ctx context.Context, in struct{}, out *
return nil return nil
} }
// SendInformerMetric runs Cluster.sendInformerMetric(). // SendInformerMetrics runs Cluster.sendInformerMetric().
func (rpcapi *ClusterRPCAPI) SendInformerMetrics(ctx context.Context, in struct{}, out *struct{}) error { func (rpcapi *ClusterRPCAPI) SendInformerMetrics(ctx context.Context, in struct{}, out *struct{}) error {
return rpcapi.c.sendInformersMetrics(ctx) return rpcapi.c.sendInformersMetrics(ctx)
} }
@ -475,7 +474,7 @@ func (rpcapi *PinTrackerRPCAPI) StatusAll(ctx context.Context, in <-chan api.Tra
} }
// Status runs PinTracker.Status(). // Status runs PinTracker.Status().
func (rpcapi *PinTrackerRPCAPI) Status(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (rpcapi *PinTrackerRPCAPI) Status(ctx context.Context, in api.Cid, out *api.PinInfo) error {
ctx, span := trace.StartSpan(ctx, "rpc/tracker/Status") ctx, span := trace.StartSpan(ctx, "rpc/tracker/Status")
defer span.End() defer span.End()
pinfo := rpcapi.tracker.Status(ctx, in) pinfo := rpcapi.tracker.Status(ctx, in)
@ -491,7 +490,7 @@ func (rpcapi *PinTrackerRPCAPI) RecoverAll(ctx context.Context, in <-chan struct
} }
// Recover runs PinTracker.Recover(). // Recover runs PinTracker.Recover().
func (rpcapi *PinTrackerRPCAPI) Recover(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (rpcapi *PinTrackerRPCAPI) Recover(ctx context.Context, in api.Cid, out *api.PinInfo) error {
ctx, span := trace.StartSpan(ctx, "rpc/tracker/Recover") ctx, span := trace.StartSpan(ctx, "rpc/tracker/Recover")
defer span.End() defer span.End()
pinfo, err := rpcapi.tracker.Recover(ctx, in) pinfo, err := rpcapi.tracker.Recover(ctx, in)
@ -577,7 +576,7 @@ func (rpcapi *IPFSConnectorRPCAPI) BlockStream(ctx context.Context, in <-chan ap
} }
// BlockGet runs IPFSConnector.BlockGet(). // BlockGet runs IPFSConnector.BlockGet().
func (rpcapi *IPFSConnectorRPCAPI) BlockGet(ctx context.Context, in cid.Cid, out *[]byte) error { func (rpcapi *IPFSConnectorRPCAPI) BlockGet(ctx context.Context, in api.Cid, out *[]byte) error {
res, err := rpcapi.ipfs.BlockGet(ctx, in) res, err := rpcapi.ipfs.BlockGet(ctx, in)
if err != nil { if err != nil {
return err return err
@ -587,7 +586,7 @@ func (rpcapi *IPFSConnectorRPCAPI) BlockGet(ctx context.Context, in cid.Cid, out
} }
// Resolve runs IPFSConnector.Resolve(). // Resolve runs IPFSConnector.Resolve().
func (rpcapi *IPFSConnectorRPCAPI) Resolve(ctx context.Context, in string, out *cid.Cid) error { func (rpcapi *IPFSConnectorRPCAPI) Resolve(ctx context.Context, in string, out *api.Cid) error {
c, err := rpcapi.ipfs.Resolve(ctx, in) c, err := rpcapi.ipfs.Resolve(ctx, in)
if err != nil { if err != nil {
return err return err

View File

@ -15,7 +15,7 @@ test_expect_success IPFS,CLUSTER "pin data to cluster with ctl" '
' '
test_expect_success IPFS,CLUSTER "unpin data from cluster with ctl" ' test_expect_success IPFS,CLUSTER "unpin data from cluster with ctl" '
cid=`ipfs-cluster-ctl --enc=json pin ls | jq -r ".cid | .[\"/\"]" | head -1` cid=`ipfs-cluster-ctl --enc=json pin ls | jq -r ".cid" | head -1`
ipfs-cluster-ctl pin rm "$cid" && ipfs-cluster-ctl pin rm "$cid" &&
!(ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid") && !(ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid") &&
ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED" ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED"
@ -29,7 +29,7 @@ test_expect_success IPFS,CLUSTER "wait for data to pin to cluster with ctl" '
' '
test_expect_success IPFS,CLUSTER "wait for data to unpin from cluster with ctl" ' test_expect_success IPFS,CLUSTER "wait for data to unpin from cluster with ctl" '
cid=`ipfs-cluster-ctl --enc=json pin ls | jq -r ".cid | .[\"/\"]" | head -1` cid=`ipfs-cluster-ctl --enc=json pin ls | jq -r ".cid" | head -1`
ipfs-cluster-ctl pin rm --wait "$cid" | grep -q -i "UNPINNED" && ipfs-cluster-ctl pin rm --wait "$cid" | grep -q -i "UNPINNED" &&
!(ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid") && !(ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid") &&
ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED" ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED"
@ -43,7 +43,7 @@ test_expect_success IPFS,CLUSTER "wait for data to pin to cluster with ctl with
' '
test_expect_success IPFS,CLUSTER "wait for data to unpin from cluster with ctl with timeout" ' test_expect_success IPFS,CLUSTER "wait for data to unpin from cluster with ctl with timeout" '
cid=`ipfs-cluster-ctl --enc=json pin ls | jq -r ".cid | .[\"/\"]" | head -1` cid=`ipfs-cluster-ctl --enc=json pin ls | jq -r ".cid" | head -1`
ipfs-cluster-ctl pin rm --wait --wait-timeout 2s "$cid" | grep -q -i "UNPINNED" && ipfs-cluster-ctl pin rm --wait --wait-timeout 2s "$cid" | grep -q -i "UNPINNED" &&
!(ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid") && !(ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid") &&
ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED" ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED"

View File

@ -14,7 +14,7 @@ test_expect_success IPFS,CLUSTER,JQ "state export saves the correct state to exp
cluster_kill && sleep 5 && cluster_kill && sleep 5 &&
ipfs-cluster-service --debug --config "test-config" state export -f export.json && ipfs-cluster-service --debug --config "test-config" state export -f export.json &&
[ -f export.json ] && [ -f export.json ] &&
jq -r ".cid | .[\"/\"]" export.json | grep -q "$cid" jq -r ".cid" export.json | grep -q "$cid"
' '
cluster_kill cluster_kill
@ -28,7 +28,7 @@ test_expect_success IPFS,CLUSTER,JQ "state export saves the correct state to exp
cluster_kill && sleep 5 && cluster_kill && sleep 5 &&
ipfs-cluster-service --debug --config "test-config" state export -f export.json && ipfs-cluster-service --debug --config "test-config" state export -f export.json &&
[ -f export.json ] && [ -f export.json ] &&
jq -r ".cid | .[\"/\"]" export.json | grep -q "$cid" jq -r ".cid" export.json | grep -q "$cid"
' '
test_clean_ipfs test_clean_ipfs

View File

@ -10,7 +10,6 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/state" "github.com/ipfs/ipfs-cluster/state"
cid "github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
query "github.com/ipfs/go-datastore/query" query "github.com/ipfs/go-datastore/query"
dshelp "github.com/ipfs/go-ipfs-ds-help" dshelp "github.com/ipfs/go-ipfs-ds-help"
@ -79,7 +78,7 @@ func (st *State) Add(ctx context.Context, c api.Pin) error {
// Rm removes an existing Pin. It is a no-op when the // Rm removes an existing Pin. It is a no-op when the
// item does not exist. // item does not exist.
func (st *State) Rm(ctx context.Context, c cid.Cid) error { func (st *State) Rm(ctx context.Context, c api.Cid) error {
_, span := trace.StartSpan(ctx, "state/dsstate/Rm") _, span := trace.StartSpan(ctx, "state/dsstate/Rm")
defer span.End() defer span.End()
@ -93,7 +92,7 @@ func (st *State) Rm(ctx context.Context, c cid.Cid) error {
// Get returns a Pin from the store and whether it // Get returns a Pin from the store and whether it
// was present. When not present, a default pin // was present. When not present, a default pin
// is returned. // is returned.
func (st *State) Get(ctx context.Context, c cid.Cid) (api.Pin, error) { func (st *State) Get(ctx context.Context, c api.Cid) (api.Pin, error) {
_, span := trace.StartSpan(ctx, "state/dsstate/Get") _, span := trace.StartSpan(ctx, "state/dsstate/Get")
defer span.End() defer span.End()
@ -112,7 +111,7 @@ func (st *State) Get(ctx context.Context, c cid.Cid) (api.Pin, error) {
} }
// Has returns whether a Cid is stored. // Has returns whether a Cid is stored.
func (st *State) Has(ctx context.Context, c cid.Cid) (bool, error) { func (st *State) Has(ctx context.Context, c api.Cid) (bool, error) {
_, span := trace.StartSpan(ctx, "state/dsstate/Has") _, span := trace.StartSpan(ctx, "state/dsstate/Has")
defer span.End() defer span.End()
@ -254,27 +253,28 @@ func (st *State) Unmarshal(r io.Reader) error {
} }
// used to be on go-ipfs-ds-help // used to be on go-ipfs-ds-help
func cidToDsKey(c cid.Cid) ds.Key { func cidToDsKey(c api.Cid) ds.Key {
return dshelp.NewKeyFromBinary(c.Bytes()) return dshelp.NewKeyFromBinary(c.Bytes())
} }
// used to be on go-ipfs-ds-help // used to be on go-ipfs-ds-help
func dsKeyToCid(k ds.Key) (cid.Cid, error) { func dsKeyToCid(k ds.Key) (api.Cid, error) {
kb, err := dshelp.BinaryFromDsKey(k) kb, err := dshelp.BinaryFromDsKey(k)
if err != nil { if err != nil {
return cid.Undef, err return api.CidUndef, err
} }
return cid.Cast(kb) c, err := api.CastCid(kb)
return c, err
} }
// convert Cid to /namespace/cid1Key // convert Cid to /namespace/cid1Key
func (st *State) key(c cid.Cid) ds.Key { func (st *State) key(c api.Cid) ds.Key {
k := cidToDsKey(c) k := cidToDsKey(c)
return st.namespace.Child(k) return st.namespace.Child(k)
} }
// convert /namespace/cidKey to Cid // convert /namespace/cidKey to Cid
func (st *State) unkey(k ds.Key) (cid.Cid, error) { func (st *State) unkey(k ds.Key) (api.Cid, error) {
return dsKeyToCid(ds.NewKey(k.BaseNamespace())) return dsKeyToCid(ds.NewKey(k.BaseNamespace()))
} }
@ -286,7 +286,7 @@ func (st *State) serializePin(c api.Pin) ([]byte, error) {
// this deserializes a Pin object from the datastore. It should be // this deserializes a Pin object from the datastore. It should be
// the exact opposite from serializePin. // the exact opposite from serializePin.
func (st *State) deserializePin(c cid.Cid, buf []byte) (api.Pin, error) { func (st *State) deserializePin(c api.Cid, buf []byte) (api.Pin, error) {
p := api.Pin{} p := api.Pin{}
err := p.ProtoUnmarshal(buf) err := p.ProtoUnmarshal(buf)
p.Cid = c p.Cid = c

View File

@ -9,11 +9,10 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/datastore/inmem" "github.com/ipfs/ipfs-cluster/datastore/inmem"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
) )
var testCid1, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq") var testCid1, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq")
var testPeerID1, _ = peer.Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc") var testPeerID1, _ = peer.Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc")
var c = api.Pin{ var c = api.Pin{

View File

@ -4,8 +4,6 @@ import (
"context" "context"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
cid "github.com/ipfs/go-cid"
) )
type empty struct{} type empty struct{}
@ -15,11 +13,11 @@ func (e *empty) List(ctx context.Context, out chan<- api.Pin) error {
return nil return nil
} }
func (e *empty) Has(ctx context.Context, c cid.Cid) (bool, error) { func (e *empty) Has(ctx context.Context, c api.Cid) (bool, error) {
return false, nil return false, nil
} }
func (e *empty) Get(ctx context.Context, c cid.Cid) (api.Pin, error) { func (e *empty) Get(ctx context.Context, c api.Cid) (api.Pin, error) {
return api.Pin{}, ErrNotFound return api.Pin{}, ErrNotFound
} }

View File

@ -9,8 +9,6 @@ import (
"io" "io"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
cid "github.com/ipfs/go-cid"
) )
// ErrNotFound should be returned when a pin is not part of the state. // ErrNotFound should be returned when a pin is not part of the state.
@ -36,10 +34,10 @@ type ReadOnly interface {
// List lists all the pins in the state. // List lists all the pins in the state.
List(context.Context, chan<- api.Pin) error List(context.Context, chan<- api.Pin) error
// Has returns true if the state is holding information for a Cid. // Has returns true if the state is holding information for a Cid.
Has(context.Context, cid.Cid) (bool, error) Has(context.Context, api.Cid) (bool, error)
// Get returns the information attacthed to this pin, if any. If the // Get returns the information attacthed to this pin, if any. If the
// pin is not part of the state, it should return ErrNotFound. // pin is not part of the state, it should return ErrNotFound.
Get(context.Context, cid.Cid) (api.Pin, error) Get(context.Context, api.Cid) (api.Pin, error)
} }
// WriteOnly represents the write side of a State. // WriteOnly represents the write side of a State.
@ -47,7 +45,7 @@ type WriteOnly interface {
// Add adds a pin to the State // Add adds a pin to the State
Add(context.Context, api.Pin) error Add(context.Context, api.Pin) error
// Rm removes a pin from the State. // Rm removes a pin from the State.
Rm(context.Context, cid.Cid) error Rm(context.Context, api.Cid) error
} }
// BatchingState represents a state which batches write operations. // BatchingState represents a state which batches write operations.

View File

@ -1,30 +1,30 @@
package test package test
import ( import (
cid "github.com/ipfs/go-cid" "github.com/ipfs/ipfs-cluster/api"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
) )
// Common variables used all around tests. // Common variables used all around tests.
var ( var (
Cid1, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq") Cid1, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq")
Cid2, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmma") Cid2, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmma")
Cid3, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmb") Cid3, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmb")
Cid4Data = "Cid4Data" Cid4Data = "Cid4Data"
// Cid resulting from block put using blake2b-256 and raw format // Cid resulting from block put using blake2b-256 and raw format
Cid4, _ = cid.Decode("bafk2bzaceawsyhsnrwwy5mtit2emnjfalkxsyq2p2ptd6fuliolzwwjbs42fq") Cid4, _ = api.DecodeCid("bafk2bzaceawsyhsnrwwy5mtit2emnjfalkxsyq2p2ptd6fuliolzwwjbs42fq")
// Cid resulting from block put using format "v0" defaults // Cid resulting from block put using format "v0" defaults
Cid5, _ = cid.Decode("QmbgmXgsFjxAJ7cEaziL2NDSptHAkPwkEGMmKMpfyYeFXL") Cid5, _ = api.DecodeCid("QmbgmXgsFjxAJ7cEaziL2NDSptHAkPwkEGMmKMpfyYeFXL")
Cid5Data = "Cid5Data" Cid5Data = "Cid5Data"
SlowCid1, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmd") SlowCid1, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmd")
CidResolved, _ = cid.Decode("zb2rhiKhUepkTMw7oFfBUnChAN7ABAvg2hXUwmTBtZ6yxuabc") CidResolved, _ = api.DecodeCid("zb2rhiKhUepkTMw7oFfBUnChAN7ABAvg2hXUwmTBtZ6yxuabc")
// ErrorCid is meant to be used as a Cid which causes errors. i.e. the // ErrorCid is meant to be used as a Cid which causes errors. i.e. the
// ipfs mock fails when pinning this CID. // ipfs mock fails when pinning this CID.
ErrorCid, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmc") ErrorCid, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmc")
// NotFoundCid is meant to be used as a CID that doesn't exist in the // NotFoundCid is meant to be used as a CID that doesn't exist in the
// pinset. // pinset.
NotFoundCid, _ = cid.Decode("bafyreiay3jpjk74dkckv2r74eyvf3lfnxujefay2rtuluintasq2zlapv4") NotFoundCid, _ = api.DecodeCid("bafyreiay3jpjk74dkckv2r74eyvf3lfnxujefay2rtuluintasq2zlapv4")
PeerID1, _ = peer.Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc") PeerID1, _ = peer.Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc")
PeerID2, _ = peer.Decode("QmUZ13osndQ5uL4tPWHXe3iBgBgq9gfewcBMSCAuMBsDJ6") PeerID2, _ = peer.Decode("QmUZ13osndQ5uL4tPWHXe3iBgBgq9gfewcBMSCAuMBsDJ6")
PeerID3, _ = peer.Decode("QmPGDFvBkgWhvzEK9qaTWrWurSwqXNmhnK3hgELPdZZNPa") PeerID3, _ = peer.Decode("QmPGDFvBkgWhvzEK9qaTWrWurSwqXNmhnK3hgELPdZZNPa")

View File

@ -192,7 +192,7 @@ func (m *IpfsMock) handler(w http.ResponseWriter, r *http.Request) {
if arg == ErrorCid.String() { if arg == ErrorCid.String() {
goto ERROR goto ERROR
} }
c, err := cid.Decode(arg) c, err := api.DecodeCid(arg)
if err != nil { if err != nil {
goto ERROR goto ERROR
} }
@ -222,7 +222,7 @@ func (m *IpfsMock) handler(w http.ResponseWriter, r *http.Request) {
if !ok { if !ok {
goto ERROR goto ERROR
} }
c, err := cid.Decode(arg) c, err := api.DecodeCid(arg)
if err != nil { if err != nil {
goto ERROR goto ERROR
} }
@ -239,11 +239,11 @@ func (m *IpfsMock) handler(w http.ResponseWriter, r *http.Request) {
} }
fromStr := args[0] fromStr := args[0]
toStr := args[1] toStr := args[1]
from, err := cid.Decode(fromStr) from, err := api.DecodeCid(fromStr)
if err != nil { if err != nil {
goto ERROR goto ERROR
} }
to, err := cid.Decode(toStr) to, err := api.DecodeCid(toStr)
if err != nil { if err != nil {
goto ERROR goto ERROR
} }
@ -301,7 +301,7 @@ func (m *IpfsMock) handler(w http.ResponseWriter, r *http.Request) {
} }
cidStr := arg cidStr := arg
c, err := cid.Decode(cidStr) c, err := api.DecodeCid(cidStr)
if err != nil { if err != nil {
goto ERROR goto ERROR
} }
@ -443,16 +443,16 @@ func (m *IpfsMock) handler(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w) enc := json.NewEncoder(w)
resp := []mockRepoGCResp{ resp := []mockRepoGCResp{
{ {
Key: Cid1, Key: Cid1.Cid,
}, },
{ {
Key: Cid2, Key: Cid2.Cid,
}, },
{ {
Key: Cid3, Key: Cid3.Cid,
}, },
{ {
Key: Cid4, Key: Cid4.Cid,
}, },
{ {
Error: "no link by that name", Error: "no link by that name",

View File

@ -10,7 +10,6 @@ import (
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
"github.com/ipfs/ipfs-cluster/state" "github.com/ipfs/ipfs-cluster/state"
cid "github.com/ipfs/go-cid"
gopath "github.com/ipfs/go-path" gopath "github.com/ipfs/go-path"
host "github.com/libp2p/go-libp2p-core/host" host "github.com/libp2p/go-libp2p-core/host"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
@ -105,10 +104,11 @@ func (mock *mockCluster) PinPath(ctx context.Context, in api.PinPath, out *api.P
if err != nil { if err != nil {
return err return err
} }
if c.Equals(ErrorCid) { cc := api.NewCid(c)
if cc.Equals(ErrorCid) {
return ErrBadCid return ErrBadCid
} }
pin = api.PinWithOpts(c, in.PinOptions) pin = api.PinWithOpts(cc, in.PinOptions)
} else { } else {
pin = api.PinWithOpts(CidResolved, in.PinOptions) pin = api.PinWithOpts(CidResolved, in.PinOptions)
} }
@ -139,7 +139,7 @@ func (mock *mockCluster) Pins(ctx context.Context, in <-chan struct{}, out chan<
return nil return nil
} }
func (mock *mockCluster) PinGet(ctx context.Context, in cid.Cid, out *api.Pin) error { func (mock *mockCluster) PinGet(ctx context.Context, in api.Cid, out *api.Pin) error {
switch in.String() { switch in.String() {
case ErrorCid.String(): case ErrorCid.String():
return errors.New("this is an expected error when using ErrorCid") return errors.New("this is an expected error when using ErrorCid")
@ -307,7 +307,7 @@ func (mock *mockCluster) StatusAllLocal(ctx context.Context, in <-chan api.Track
return (&mockPinTracker{}).StatusAll(ctx, in, out) return (&mockPinTracker{}).StatusAll(ctx, in, out)
} }
func (mock *mockCluster) Status(ctx context.Context, in cid.Cid, out *api.GlobalPinInfo) error { func (mock *mockCluster) Status(ctx context.Context, in api.Cid, out *api.GlobalPinInfo) error {
if in.Equals(ErrorCid) { if in.Equals(ErrorCid) {
return ErrBadCid return ErrBadCid
} }
@ -335,7 +335,7 @@ func (mock *mockCluster) Status(ctx context.Context, in cid.Cid, out *api.Global
return nil return nil
} }
func (mock *mockCluster) StatusLocal(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (mock *mockCluster) StatusLocal(ctx context.Context, in api.Cid, out *api.PinInfo) error {
return (&mockPinTracker{}).Status(ctx, in, out) return (&mockPinTracker{}).Status(ctx, in, out)
} }
@ -350,11 +350,11 @@ func (mock *mockCluster) RecoverAllLocal(ctx context.Context, in <-chan struct{}
return (&mockPinTracker{}).RecoverAll(ctx, in, out) return (&mockPinTracker{}).RecoverAll(ctx, in, out)
} }
func (mock *mockCluster) Recover(ctx context.Context, in cid.Cid, out *api.GlobalPinInfo) error { func (mock *mockCluster) Recover(ctx context.Context, in api.Cid, out *api.GlobalPinInfo) error {
return mock.Status(ctx, in, out) return mock.Status(ctx, in, out)
} }
func (mock *mockCluster) RecoverLocal(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (mock *mockCluster) RecoverLocal(ctx context.Context, in api.Cid, out *api.PinInfo) error {
return (&mockPinTracker{}).Recover(ctx, in, out) return (&mockPinTracker{}).Recover(ctx, in, out)
} }
@ -469,7 +469,7 @@ func (mock *mockPinTracker) StatusAll(ctx context.Context, in <-chan api.Tracker
return nil return nil
} }
func (mock *mockPinTracker) Status(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (mock *mockPinTracker) Status(ctx context.Context, in api.Cid, out *api.PinInfo) error {
if in.Equals(ErrorCid) { if in.Equals(ErrorCid) {
return ErrBadCid return ErrBadCid
} }
@ -490,7 +490,7 @@ func (mock *mockPinTracker) RecoverAll(ctx context.Context, in <-chan struct{},
return nil return nil
} }
func (mock *mockPinTracker) Recover(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (mock *mockPinTracker) Recover(ctx context.Context, in api.Cid, out *api.PinInfo) error {
*out = api.PinInfo{ *out = api.PinInfo{
Cid: in, Cid: in,
Peer: PeerID1, Peer: PeerID1,
@ -589,7 +589,7 @@ func (mock *mockIPFSConnector) BlockStream(ctx context.Context, in <-chan api.No
return nil return nil
} }
func (mock *mockIPFSConnector) Resolve(ctx context.Context, in string, out *cid.Cid) error { func (mock *mockIPFSConnector) Resolve(ctx context.Context, in string, out *api.Cid) error {
switch in { switch in {
case ErrorCid.String(), "/ipfs/" + ErrorCid.String(): case ErrorCid.String(), "/ipfs/" + ErrorCid.String():
*out = ErrorCid *out = ErrorCid

View File

@ -12,6 +12,7 @@ import (
files "github.com/ipfs/go-ipfs-files" files "github.com/ipfs/go-ipfs-files"
format "github.com/ipfs/go-ipld-format" format "github.com/ipfs/go-ipld-format"
"github.com/ipfs/ipfs-cluster/api"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
) )
@ -62,7 +63,7 @@ var (
} }
// Used for testing blockput/blockget // Used for testing blockput/blockget
ShardCid, _ = cid.Decode("zdpuAoiNm1ntWx6jpgcReTiCWFHJSTpvTw4bAAn9p6yDnznqh") ShardCid, _ = api.DecodeCid("zdpuAoiNm1ntWx6jpgcReTiCWFHJSTpvTw4bAAn9p6yDnznqh")
ShardData, _ = hex.DecodeString("a16130d82a58230012209273fd63ec94bed5abb219b2d9cb010cabe4af7b0177292d4335eff50464060a") ShardData, _ = hex.DecodeString("a16130d82a58230012209273fd63ec94bed5abb219b2d9cb010cabe4af7b0177292d4335eff50464060a")
) )

View File

@ -9,7 +9,6 @@ import (
blake2b "golang.org/x/crypto/blake2b" blake2b "golang.org/x/crypto/blake2b"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/ipfs-cluster/api" "github.com/ipfs/ipfs-cluster/api"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
@ -100,7 +99,7 @@ type distanceChecker struct {
cache map[peer.ID]distance cache map[peer.ID]distance
} }
func (dc distanceChecker) isClosest(ci cid.Cid) bool { func (dc distanceChecker) isClosest(ci api.Cid) bool {
ciHash := convertKey(ci.KeyString()) ciHash := convertKey(ci.KeyString())
localPeerHash := dc.convertPeerID(dc.local) localPeerHash := dc.convertPeerID(dc.local)
myDistance := xor(ciHash, localPeerHash) myDistance := xor(ciHash, localPeerHash)

View File

@ -1,3 +1,4 @@
// Package version stores version information for IPFS Cluster.
package version package version
import ( import (