diff --git a/api/types.go b/api/types.go index 606867d8..7f783edf 100644 --- a/api/types.go +++ b/api/types.go @@ -332,55 +332,56 @@ func (addrsS MultiaddrsSerial) ToMultiaddrs() []ma.Multiaddr { return addrs } -// CidArg is an arguments that carry a Cid. It may carry more things in the +// Pin is an argument that carries a Cid. It may carry more things in the // future. -type CidArg struct { - Cid *cid.Cid - Allocations []peer.ID - Everywhere bool +type Pin struct { + Cid *cid.Cid + Allocations []peer.ID + Everywhere bool + ReplicationFactor int } -// CidArgCid is a shorcut to create a CidArg only with a Cid. -func CidArgCid(c *cid.Cid) CidArg { - return CidArg{ +// PinCid is a shorcut to create a Pin only with a Cid. +func PinCid(c *cid.Cid) Pin { + return Pin{ Cid: c, } } -// CidArgSerial is a serializable version of CidArg -type CidArgSerial struct { +// PinSerial is a serializable version of Pin +type PinSerial struct { Cid string `json:"cid"` Allocations []string `json:"allocations"` Everywhere bool `json:"everywhere"` } -// ToSerial converts a CidArg to CidArgSerial. -func (carg CidArg) ToSerial() CidArgSerial { - lenAllocs := len(carg.Allocations) +// ToSerial converts a Pin to PinSerial. +func (pin Pin) ToSerial() PinSerial { + lenAllocs := len(pin.Allocations) allocs := make([]string, lenAllocs, lenAllocs) - for i, p := range carg.Allocations { + for i, p := range pin.Allocations { allocs[i] = peer.IDB58Encode(p) } - return CidArgSerial{ - Cid: carg.Cid.String(), + return PinSerial{ + Cid: pin.Cid.String(), Allocations: allocs, - Everywhere: carg.Everywhere, + Everywhere: pin.Everywhere, } } -// ToCidArg converts a CidArgSerial to its native form. -func (cargs CidArgSerial) ToCidArg() CidArg { - c, _ := cid.Decode(cargs.Cid) - lenAllocs := len(cargs.Allocations) +// ToPin converts a PinSerial to its native form. +func (pins PinSerial) ToPin() Pin { + c, _ := cid.Decode(pins.Cid) + lenAllocs := len(pins.Allocations) allocs := make([]peer.ID, lenAllocs, lenAllocs) - for i, p := range cargs.Allocations { + for i, p := range pins.Allocations { allocs[i], _ = peer.IDB58Decode(p) } - return CidArg{ + return Pin{ Cid: c, Allocations: allocs, - Everywhere: cargs.Everywhere, + Everywhere: pins.Everywhere, } } diff --git a/api/types_test.go b/api/types_test.go index 95b05658..d7395576 100644 --- a/api/types_test.go +++ b/api/types_test.go @@ -133,20 +133,20 @@ func TestMultiaddrConv(t *testing.T) { } } -func TestCidArgConv(t *testing.T) { +func TestPinConv(t *testing.T) { defer func() { if r := recover(); r != nil { t.Fatal("paniced") } }() - c := CidArg{ + c := Pin{ Cid: testCid1, Allocations: []peer.ID{testPeerID1}, Everywhere: true, } - newc := c.ToSerial().ToCidArg() + newc := c.ToSerial().ToPin() if c.Cid.String() != newc.Cid.String() || c.Allocations[0] != newc.Allocations[0] || c.Everywhere != newc.Everywhere { diff --git a/cluster.go b/cluster.go index a75d1f34..2d05275e 100644 --- a/cluster.go +++ b/cluster.go @@ -616,10 +616,10 @@ func (c *Cluster) StateSync() ([]api.PinInfo, error) { var changed []*cid.Cid // Track items which are not tracked - for _, carg := range clusterPins { - if c.tracker.Status(carg.Cid).Status == api.TrackerStatusUnpinned { - changed = append(changed, carg.Cid) - go c.tracker.Track(carg) + for _, pin := range clusterPins { + if c.tracker.Status(pin.Cid).Status == api.TrackerStatusUnpinned { + changed = append(changed, pin.Cid) + go c.tracker.Track(pin) } } @@ -706,11 +706,11 @@ func (c *Cluster) Recover(h *cid.Cid) (api.GlobalPinInfo, error) { // Pins returns the list of Cids managed by Cluster and which are part // of the current global state. This is the source of truth as to which // pins are managed, but does not indicate if the item is successfully pinned. -func (c *Cluster) Pins() []api.CidArg { +func (c *Cluster) Pins() []api.Pin { cState, err := c.consensus.State() if err != nil { logger.Error(err) - return []api.CidArg{} + return []api.Pin{} } return cState.List() @@ -725,7 +725,7 @@ func (c *Cluster) Pins() []api.CidArg { // to the global state. Pin does not reflect the success or failure // of underlying IPFS daemon pinning operations. func (c *Cluster) Pin(h *cid.Cid) error { - cidArg := api.CidArg{ + pin := api.Pin{ Cid: h, } @@ -734,7 +734,7 @@ func (c *Cluster) Pin(h *cid.Cid) error { case rpl == 0: return errors.New("replication factor is 0") case rpl < 0: - cidArg.Everywhere = true + pin.Everywhere = true logger.Infof("IPFS cluster pinning %s everywhere:", h) case rpl > 0: @@ -742,12 +742,12 @@ func (c *Cluster) Pin(h *cid.Cid) error { if err != nil { return err } - cidArg.Allocations = allocs - logger.Infof("IPFS cluster pinning %s on %s:", h, cidArg.Allocations) + pin.Allocations = allocs + logger.Infof("IPFS cluster pinning %s on %s:", h, pin.Allocations) } - err := c.consensus.LogPin(cidArg) + err := c.consensus.LogPin(pin) if err != nil { return err } @@ -763,11 +763,11 @@ func (c *Cluster) Pin(h *cid.Cid) error { func (c *Cluster) Unpin(h *cid.Cid) error { logger.Info("IPFS cluster unpinning:", h) - carg := api.CidArg{ + pin := api.Pin{ Cid: h, } - err := c.consensus.LogUnpin(carg) + err := c.consensus.LogUnpin(pin) if err != nil { return err } @@ -865,7 +865,7 @@ func (c *Cluster) globalPinInfoCid(method string, h *cid.Cid) (api.GlobalPinInfo members := c.peerManager.peers() replies := make([]api.PinInfoSerial, len(members), len(members)) - arg := api.CidArg{ + arg := api.Pin{ Cid: h, } errs := c.multiRPC(members, @@ -982,8 +982,8 @@ func (c *Cluster) allocate(hash *cid.Cid) ([]peer.ID, error) { // problem, we would fail to commit anyway. currentlyAllocatedPeers = []peer.ID{} } else { - carg := st.Get(hash) - currentlyAllocatedPeers = carg.Allocations + pin := st.Get(hash) + currentlyAllocatedPeers = pin.Allocations } // initialize a candidate metrics map with all current clusterPeers diff --git a/consensus.go b/consensus.go index 647ab6fa..e6119601 100644 --- a/consensus.go +++ b/consensus.go @@ -187,9 +187,9 @@ func (cc *Consensus) Ready() <-chan struct{} { func (cc *Consensus) op(argi interface{}, t LogOpType) *LogOp { switch argi.(type) { - case api.CidArg: + case api.Pin: return &LogOp{ - Cid: argi.(api.CidArg).ToSerial(), + Cid: argi.(api.Pin).ToSerial(), Type: t, } case ma.Multiaddr: @@ -226,12 +226,12 @@ func (cc *Consensus) redirectToLeader(method string, arg interface{}) (bool, err return true, err } -func (cc *Consensus) logOpCid(rpcOp string, opType LogOpType, carg api.CidArg) error { +func (cc *Consensus) logOpCid(rpcOp string, opType LogOpType, pin api.Pin) error { var finalErr error for i := 0; i < CommitRetries; i++ { logger.Debugf("Try %d", i) redirected, err := cc.redirectToLeader( - rpcOp, carg.ToSerial()) + rpcOp, pin.ToSerial()) if err != nil { finalErr = err continue @@ -243,7 +243,7 @@ func (cc *Consensus) logOpCid(rpcOp string, opType LogOpType, carg api.CidArg) e // It seems WE are the leader. - op := cc.op(carg, opType) + op := cc.op(pin, opType) _, err = cc.consensus.CommitOp(op) if err != nil { // This means the op did not make it to the log @@ -260,21 +260,21 @@ func (cc *Consensus) logOpCid(rpcOp string, opType LogOpType, carg api.CidArg) e switch opType { case LogOpPin: - logger.Infof("pin committed to global state: %s", carg.Cid) + logger.Infof("pin committed to global state: %s", pin.Cid) case LogOpUnpin: - logger.Infof("unpin committed to global state: %s", carg.Cid) + logger.Infof("unpin committed to global state: %s", pin.Cid) } return nil } // LogPin submits a Cid to the shared state of the cluster. It will forward // the operation to the leader if this is not it. -func (cc *Consensus) LogPin(c api.CidArg) error { +func (cc *Consensus) LogPin(c api.Pin) error { return cc.logOpCid("ConsensusLogPin", LogOpPin, c) } // LogUnpin removes a Cid from the shared state of the cluster. -func (cc *Consensus) LogUnpin(c api.CidArg) error { +func (cc *Consensus) LogUnpin(c api.Pin) error { return cc.logOpCid("ConsensusLogUnpin", LogOpUnpin, c) } diff --git a/consensus_test.go b/consensus_test.go index f12edac8..e6eb13ac 100644 --- a/consensus_test.go +++ b/consensus_test.go @@ -59,7 +59,7 @@ func TestConsensusPin(t *testing.T) { defer cc.Shutdown() c, _ := cid.Decode(test.TestCid1) - err := cc.LogPin(api.CidArg{Cid: c, Everywhere: true}) + err := cc.LogPin(api.Pin{Cid: c, Everywhere: true}) if err != nil { t.Error("the operation did not make it to the log:", err) } @@ -82,7 +82,7 @@ func TestConsensusUnpin(t *testing.T) { defer cc.Shutdown() c, _ := cid.Decode(test.TestCid2) - err := cc.LogUnpin(api.CidArgCid(c)) + err := cc.LogUnpin(api.PinCid(c)) if err != nil { t.Error("the operation did not make it to the log:", err) } diff --git a/ipfs-cluster-ctl/formatters.go b/ipfs-cluster-ctl/formatters.go index 9ecbd63f..e951dfea 100644 --- a/ipfs-cluster-ctl/formatters.go +++ b/ipfs-cluster-ctl/formatters.go @@ -14,7 +14,7 @@ const ( formatGPInfo formatString formatVersion - formatCidArg + formatPin ) type format int @@ -46,10 +46,10 @@ func textFormatObject(body []byte, format int) { var obj api.Version textFormatDecodeOn(body, &obj) textFormatPrintVersion(&obj) - case formatCidArg: - var obj api.CidArgSerial + case formatPin: + var obj api.PinSerial textFormatDecodeOn(body, &obj) - textFormatPrintCidArg(&obj) + textFormatPrintPin(&obj) default: var obj interface{} textFormatDecodeOn(body, &obj) @@ -105,11 +105,11 @@ func textFormatPrintVersion(obj *api.Version) { fmt.Println(obj.Version) } -func textFormatPrintCidArg(obj *api.CidArgSerial) { +func textFormatPrintPin(obj *api.PinSerial) { fmt.Printf("%s | Allocations: ", obj.Cid) if obj.Everywhere { fmt.Printf("[everywhere]\n") } else { - fmt.Printf("%s", obj.Allocations) + fmt.Printf("%s\n", obj.Allocations) } } diff --git a/ipfs-cluster-ctl/main.go b/ipfs-cluster-ctl/main.go index e2296d0e..89e28691 100644 --- a/ipfs-cluster-ctl/main.go +++ b/ipfs-cluster-ctl/main.go @@ -267,7 +267,7 @@ any monitoring information about the merely represents the list of pins which are part of the global state of the cluster. For specific information, use "status". `, - Flags: []cli.Flag{parseFlag(formatCidArg)}, + Flags: []cli.Flag{parseFlag(formatPin)}, Action: func(c *cli.Context) error { resp := request("GET", "/pinlist", nil) formatResponse(c, resp) diff --git a/ipfs_http_connector.go b/ipfs_http_connector.go index 3389a410..f7655548 100644 --- a/ipfs_http_connector.go +++ b/ipfs_http_connector.go @@ -241,7 +241,7 @@ func (ipfs *IPFSHTTPConnector) pinOpHandler(op string, w http.ResponseWriter, r err = ipfs.rpcClient.Call("", "Cluster", op, - api.CidArgSerial{ + api.PinSerial{ Cid: arg, }, &struct{}{}) @@ -272,7 +272,7 @@ func (ipfs *IPFSHTTPConnector) pinLsHandler(w http.ResponseWriter, r *http.Reque pinLs := ipfsPinLsResp{} pinLs.Keys = make(map[string]ipfsPinType) - var pins []api.CidArgSerial + var pins []api.PinSerial err := ipfs.rpcClient.Call("", "Cluster", "PinList", diff --git a/ipfscluster.go b/ipfscluster.go index 074043b1..08dbf047 100644 --- a/ipfscluster.go +++ b/ipfscluster.go @@ -59,15 +59,15 @@ type Peered interface { // objects which objects are pinned. This component should be thread safe. type State interface { // Add adds a pin to the State - Add(api.CidArg) error + Add(api.Pin) error // Rm removes a pin from the State Rm(*cid.Cid) error // List lists all the pins in the state - List() []api.CidArg + List() []api.Pin // Has returns true if the state is holding information for a Cid Has(*cid.Cid) bool // Get returns the information attacthed to this pin - Get(*cid.Cid) api.CidArg + Get(*cid.Cid) api.Pin } // PinTracker represents a component which tracks the status of @@ -77,7 +77,7 @@ type PinTracker interface { Component // Track tells the tracker that a Cid is now under its supervision // The tracker may decide to perform an IPFS pin. - Track(api.CidArg) error + Track(api.Pin) error // Untrack tells the tracker that a Cid is to be forgotten. The tracker // may perform an IPFS unpin operation. Untrack(*cid.Cid) error diff --git a/log_op.go b/log_op.go index 3b3c5861..3b2ea78a 100644 --- a/log_op.go +++ b/log_op.go @@ -27,7 +27,7 @@ type LogOpType int // It implements the consensus.Op interface and it is used by the // Consensus component. type LogOp struct { - Cid api.CidArgSerial + Cid api.PinSerial Peer api.MultiaddrSerial Type LogOpType ctx context.Context @@ -45,7 +45,7 @@ func (op *LogOp) ApplyTo(cstate consensus.State) (consensus.State, error) { switch op.Type { case LogOpPin: - arg := op.Cid.ToCidArg() + arg := op.Cid.ToPin() err = state.Add(arg) if err != nil { goto ROLLBACK @@ -58,7 +58,7 @@ func (op *LogOp) ApplyTo(cstate consensus.State) (consensus.State, error) { &struct{}{}, nil) case LogOpUnpin: - arg := op.Cid.ToCidArg() + arg := op.Cid.ToPin() err = state.Rm(arg.Cid) if err != nil { goto ROLLBACK diff --git a/log_op_test.go b/log_op_test.go index a2e0fd8a..9e075c42 100644 --- a/log_op_test.go +++ b/log_op_test.go @@ -13,7 +13,7 @@ import ( func TestApplyToPin(t *testing.T) { op := &LogOp{ - Cid: api.CidArgSerial{Cid: test.TestCid1}, + Cid: api.PinSerial{Cid: test.TestCid1}, Type: LogOpPin, ctx: context.Background(), rpcClient: test.NewMockRPCClient(t), @@ -29,7 +29,7 @@ func TestApplyToPin(t *testing.T) { func TestApplyToUnpin(t *testing.T) { op := &LogOp{ - Cid: api.CidArgSerial{Cid: test.TestCid1}, + Cid: api.PinSerial{Cid: test.TestCid1}, Type: LogOpUnpin, ctx: context.Background(), rpcClient: test.NewMockRPCClient(t), @@ -37,7 +37,7 @@ func TestApplyToUnpin(t *testing.T) { st := mapstate.NewMapState() c, _ := cid.Decode(test.TestCid1) - st.Add(api.CidArg{Cid: c, Everywhere: true}) + st.Add(api.Pin{Cid: c, Everywhere: true}) op.ApplyTo(st) pins := st.List() if len(pins) != 0 { @@ -53,7 +53,7 @@ func TestApplyToBadState(t *testing.T) { }() op := &LogOp{ - Cid: api.CidArgSerial{Cid: test.TestCid1}, + Cid: api.PinSerial{Cid: test.TestCid1}, Type: LogOpUnpin, ctx: context.Background(), rpcClient: test.NewMockRPCClient(t), @@ -71,7 +71,7 @@ func TestApplyToBadState(t *testing.T) { // }() // op := &LogOp{ -// Cid: api.CidArgSerial{Cid: "agadfaegf"}, +// Cid: api.PinSerial{Cid: "agadfaegf"}, // Type: LogOpPin, // ctx: context.Background(), // rpcClient: test.NewMockRPCClient(t), diff --git a/map_pin_tracker.go b/map_pin_tracker.go index e7037aca..25523671 100644 --- a/map_pin_tracker.go +++ b/map_pin_tracker.go @@ -46,8 +46,8 @@ type MapPinTracker struct { rpcReady chan struct{} peerID peer.ID - pinCh chan api.CidArg - unpinCh chan api.CidArg + pinCh chan api.Pin + unpinCh chan api.Pin shutdownLock sync.Mutex shutdown bool @@ -65,8 +65,8 @@ func NewMapPinTracker(cfg *Config) *MapPinTracker { status: make(map[string]api.PinInfo), rpcReady: make(chan struct{}, 1), peerID: cfg.ID, - pinCh: make(chan api.CidArg, PinQueueSize), - unpinCh: make(chan api.CidArg, PinQueueSize), + pinCh: make(chan api.Pin, PinQueueSize), + unpinCh: make(chan api.Pin, PinQueueSize), } go mpt.pinWorker() go mpt.unpinWorker() @@ -186,7 +186,7 @@ func (mpt *MapPinTracker) unsafeSetError(c *cid.Cid, err error) { } } -func (mpt *MapPinTracker) isRemote(c api.CidArg) bool { +func (mpt *MapPinTracker) isRemote(c api.Pin) bool { if c.Everywhere { return false } @@ -199,7 +199,7 @@ func (mpt *MapPinTracker) isRemote(c api.CidArg) bool { return true } -func (mpt *MapPinTracker) pin(c api.CidArg) error { +func (mpt *MapPinTracker) pin(c api.Pin) error { mpt.set(c.Cid, api.TrackerStatusPinning) err := mpt.rpcClient.Call("", "Cluster", @@ -216,7 +216,7 @@ func (mpt *MapPinTracker) pin(c api.CidArg) error { return nil } -func (mpt *MapPinTracker) unpin(c api.CidArg) error { +func (mpt *MapPinTracker) unpin(c api.Pin) error { err := mpt.rpcClient.Call("", "Cluster", "IPFSUnpin", @@ -233,7 +233,7 @@ func (mpt *MapPinTracker) unpin(c api.CidArg) error { // Track tells the MapPinTracker to start managing a Cid, // possibly trigerring Pin operations on the IPFS daemon. -func (mpt *MapPinTracker) Track(c api.CidArg) error { +func (mpt *MapPinTracker) Track(c api.Pin) error { if mpt.isRemote(c) { if mpt.get(c.Cid).Status == api.TrackerStatusPinned { mpt.unpin(c) @@ -257,7 +257,7 @@ func (mpt *MapPinTracker) Track(c api.CidArg) error { func (mpt *MapPinTracker) Untrack(c *cid.Cid) error { mpt.set(c, api.TrackerStatusUnpinning) select { - case mpt.unpinCh <- api.CidArgCid(c): + case mpt.unpinCh <- api.PinCid(c): default: mpt.setError(c, errors.New("unpin queue is full")) return logError("map_pin_tracker unpin queue is full") @@ -296,7 +296,7 @@ func (mpt *MapPinTracker) Sync(c *cid.Cid) (api.PinInfo, error) { err := mpt.rpcClient.Call("", "Cluster", "IPFSPinLsCid", - api.CidArgCid(c).ToSerial(), + api.PinCid(c).ToSerial(), &ips) if err != nil { mpt.setError(c, err) @@ -401,9 +401,9 @@ func (mpt *MapPinTracker) Recover(c *cid.Cid) (api.PinInfo, error) { var err error switch p.Status { case api.TrackerStatusPinError: - err = mpt.pin(api.CidArg{Cid: c}) + err = mpt.pin(api.Pin{Cid: c}) case api.TrackerStatusUnpinError: - err = mpt.unpin(api.CidArg{Cid: c}) + err = mpt.unpin(api.Pin{Cid: c}) } if err != nil { logger.Errorf("error recovering %s: %s", c, err) diff --git a/rest_api.go b/rest_api.go index fd39fc07..2da128eb 100644 --- a/rest_api.go +++ b/rest_api.go @@ -353,7 +353,7 @@ func (rest *RESTAPI) unpinHandler(w http.ResponseWriter, r *http.Request) { } func (rest *RESTAPI) pinListHandler(w http.ResponseWriter, r *http.Request) { - var pins []api.CidArgSerial + var pins []api.PinSerial err := rest.rpcClient.Call("", "Cluster", "PinList", @@ -418,15 +418,15 @@ func (rest *RESTAPI) recoverHandler(w http.ResponseWriter, r *http.Request) { } } -func parseCidOrError(w http.ResponseWriter, r *http.Request) api.CidArgSerial { +func parseCidOrError(w http.ResponseWriter, r *http.Request) api.PinSerial { vars := mux.Vars(r) hash := vars["hash"] _, err := cid.Decode(hash) if err != nil { sendErrorResponse(w, 400, "error decoding Cid: "+err.Error()) - return api.CidArgSerial{Cid: ""} + return api.PinSerial{Cid: ""} } - return api.CidArgSerial{Cid: hash} + return api.PinSerial{Cid: hash} } func parsePidOrError(w http.ResponseWriter, r *http.Request) peer.ID { diff --git a/rest_api_test.go b/rest_api_test.go index d04acf75..39857c94 100644 --- a/rest_api_test.go +++ b/rest_api_test.go @@ -190,7 +190,7 @@ func TestRESTAPIPinListEndpoint(t *testing.T) { rest := testRESTAPI(t) defer rest.Shutdown() - var resp []api.CidArgSerial + var resp []api.PinSerial makeGet(t, "/pinlist", &resp) if len(resp) != 3 || resp[0].Cid != test.TestCid1 || resp[1].Cid != test.TestCid2 || diff --git a/rpc_api.go b/rpc_api.go index d90aa587..b7a2abc9 100644 --- a/rpc_api.go +++ b/rpc_api.go @@ -31,21 +31,21 @@ func (rpcapi *RPCAPI) ID(in struct{}, out *api.IDSerial) error { } // Pin runs Cluster.Pin(). -func (rpcapi *RPCAPI) Pin(in api.CidArgSerial, out *struct{}) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) Pin(in api.PinSerial, out *struct{}) error { + c := in.ToPin().Cid return rpcapi.c.Pin(c) } // Unpin runs Cluster.Unpin(). -func (rpcapi *RPCAPI) Unpin(in api.CidArgSerial, out *struct{}) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) Unpin(in api.PinSerial, out *struct{}) error { + c := in.ToPin().Cid return rpcapi.c.Unpin(c) } // PinList runs Cluster.Pins(). -func (rpcapi *RPCAPI) PinList(in struct{}, out *[]api.CidArgSerial) error { +func (rpcapi *RPCAPI) PinList(in struct{}, out *[]api.PinSerial) error { cidList := rpcapi.c.Pins() - cidSerialList := make([]api.CidArgSerial, 0, len(cidList)) + cidSerialList := make([]api.PinSerial, 0, len(cidList)) for _, c := range cidList { cidSerialList = append(cidSerialList, c.ToSerial()) } @@ -100,8 +100,8 @@ func (rpcapi *RPCAPI) StatusAll(in struct{}, out *[]api.GlobalPinInfoSerial) err } // Status runs Cluster.Status(). -func (rpcapi *RPCAPI) Status(in api.CidArgSerial, out *api.GlobalPinInfoSerial) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) Status(in api.PinSerial, out *api.GlobalPinInfoSerial) error { + c := in.ToPin().Cid pinfo, err := rpcapi.c.Status(c) *out = pinfo.ToSerial() return err @@ -115,8 +115,8 @@ func (rpcapi *RPCAPI) SyncAllLocal(in struct{}, out *[]api.PinInfoSerial) error } // SyncLocal runs Cluster.SyncLocal(). -func (rpcapi *RPCAPI) SyncLocal(in api.CidArgSerial, out *api.PinInfoSerial) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) SyncLocal(in api.PinSerial, out *api.PinInfoSerial) error { + c := in.ToPin().Cid pinfo, err := rpcapi.c.SyncLocal(c) *out = pinfo.ToSerial() return err @@ -130,8 +130,8 @@ func (rpcapi *RPCAPI) SyncAll(in struct{}, out *[]api.GlobalPinInfoSerial) error } // Sync runs Cluster.Sync(). -func (rpcapi *RPCAPI) Sync(in api.CidArgSerial, out *api.GlobalPinInfoSerial) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) Sync(in api.PinSerial, out *api.GlobalPinInfoSerial) error { + c := in.ToPin().Cid pinfo, err := rpcapi.c.Sync(c) *out = pinfo.ToSerial() return err @@ -145,8 +145,8 @@ func (rpcapi *RPCAPI) StateSync(in struct{}, out *[]api.PinInfoSerial) error { } // Recover runs Cluster.Recover(). -func (rpcapi *RPCAPI) Recover(in api.CidArgSerial, out *api.GlobalPinInfoSerial) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) Recover(in api.PinSerial, out *api.GlobalPinInfoSerial) error { + c := in.ToPin().Cid pinfo, err := rpcapi.c.Recover(c) *out = pinfo.ToSerial() return err @@ -157,13 +157,13 @@ func (rpcapi *RPCAPI) Recover(in api.CidArgSerial, out *api.GlobalPinInfoSerial) */ // Track runs PinTracker.Track(). -func (rpcapi *RPCAPI) Track(in api.CidArgSerial, out *struct{}) error { - return rpcapi.c.tracker.Track(in.ToCidArg()) +func (rpcapi *RPCAPI) Track(in api.PinSerial, out *struct{}) error { + return rpcapi.c.tracker.Track(in.ToPin()) } // Untrack runs PinTracker.Untrack(). -func (rpcapi *RPCAPI) Untrack(in api.CidArgSerial, out *struct{}) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) Untrack(in api.PinSerial, out *struct{}) error { + c := in.ToPin().Cid return rpcapi.c.tracker.Untrack(c) } @@ -174,16 +174,16 @@ func (rpcapi *RPCAPI) TrackerStatusAll(in struct{}, out *[]api.PinInfoSerial) er } // TrackerStatus runs PinTracker.Status(). -func (rpcapi *RPCAPI) TrackerStatus(in api.CidArgSerial, out *api.PinInfoSerial) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) TrackerStatus(in api.PinSerial, out *api.PinInfoSerial) error { + c := in.ToPin().Cid pinfo := rpcapi.c.tracker.Status(c) *out = pinfo.ToSerial() return nil } // TrackerRecover runs PinTracker.Recover(). -func (rpcapi *RPCAPI) TrackerRecover(in api.CidArgSerial, out *api.PinInfoSerial) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) TrackerRecover(in api.PinSerial, out *api.PinInfoSerial) error { + c := in.ToPin().Cid pinfo, err := rpcapi.c.tracker.Recover(c) *out = pinfo.ToSerial() return err @@ -194,20 +194,20 @@ func (rpcapi *RPCAPI) TrackerRecover(in api.CidArgSerial, out *api.PinInfoSerial */ // IPFSPin runs IPFSConnector.Pin(). -func (rpcapi *RPCAPI) IPFSPin(in api.CidArgSerial, out *struct{}) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) IPFSPin(in api.PinSerial, out *struct{}) error { + c := in.ToPin().Cid return rpcapi.c.ipfs.Pin(c) } // IPFSUnpin runs IPFSConnector.Unpin(). -func (rpcapi *RPCAPI) IPFSUnpin(in api.CidArgSerial, out *struct{}) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) IPFSUnpin(in api.PinSerial, out *struct{}) error { + c := in.ToPin().Cid return rpcapi.c.ipfs.Unpin(c) } // IPFSPinLsCid runs IPFSConnector.PinLsCid(). -func (rpcapi *RPCAPI) IPFSPinLsCid(in api.CidArgSerial, out *api.IPFSPinStatus) error { - c := in.ToCidArg().Cid +func (rpcapi *RPCAPI) IPFSPinLsCid(in api.PinSerial, out *api.IPFSPinStatus) error { + c := in.ToPin().Cid b, err := rpcapi.c.ipfs.PinLsCid(c) *out = b return err @@ -225,14 +225,14 @@ func (rpcapi *RPCAPI) IPFSPinLs(in string, out *map[string]api.IPFSPinStatus) er */ // ConsensusLogPin runs Consensus.LogPin(). -func (rpcapi *RPCAPI) ConsensusLogPin(in api.CidArgSerial, out *struct{}) error { - c := in.ToCidArg() +func (rpcapi *RPCAPI) ConsensusLogPin(in api.PinSerial, out *struct{}) error { + c := in.ToPin() return rpcapi.c.consensus.LogPin(c) } // ConsensusLogUnpin runs Consensus.LogUnpin(). -func (rpcapi *RPCAPI) ConsensusLogUnpin(in api.CidArgSerial, out *struct{}) error { - c := in.ToCidArg() +func (rpcapi *RPCAPI) ConsensusLogUnpin(in api.PinSerial, out *struct{}) error { + c := in.ToPin() return rpcapi.c.consensus.LogUnpin(c) } diff --git a/state/mapstate/map_state.go b/state/mapstate/map_state.go index ae706033..e7fa6d77 100644 --- a/state/mapstate/map_state.go +++ b/state/mapstate/map_state.go @@ -16,19 +16,19 @@ const Version = 1 // using a Go map. It is thread safe. It implements the State interface. type MapState struct { pinMux sync.RWMutex - PinMap map[string]api.CidArgSerial + PinMap map[string]api.PinSerial Version int } // NewMapState initializes the internal map and returns a new MapState object. func NewMapState() *MapState { return &MapState{ - PinMap: make(map[string]api.CidArgSerial), + PinMap: make(map[string]api.PinSerial), } } -// Add adds a CidArg to the internal map. -func (st *MapState) Add(c api.CidArg) error { +// Add adds a Pin to the internal map. +func (st *MapState) Add(c api.Pin) error { st.pinMux.Lock() defer st.pinMux.Unlock() st.PinMap[c.Cid.String()] = c.ToSerial() @@ -43,15 +43,15 @@ func (st *MapState) Rm(c *cid.Cid) error { return nil } -// Get returns CidArg information for a CID. -func (st *MapState) Get(c *cid.Cid) api.CidArg { +// Get returns Pin information for a CID. +func (st *MapState) Get(c *cid.Cid) api.Pin { st.pinMux.RLock() defer st.pinMux.RUnlock() - cargs, ok := st.PinMap[c.String()] + pins, ok := st.PinMap[c.String()] if !ok { // make sure no panics - return api.CidArg{} + return api.Pin{} } - return cargs.ToCidArg() + return pins.ToPin() } // Has returns true if the Cid belongs to the State. @@ -62,13 +62,13 @@ func (st *MapState) Has(c *cid.Cid) bool { return ok } -// List provides the list of tracked CidArgs. -func (st *MapState) List() []api.CidArg { +// List provides the list of tracked Pins. +func (st *MapState) List() []api.Pin { st.pinMux.RLock() defer st.pinMux.RUnlock() - cids := make([]api.CidArg, 0, len(st.PinMap)) + cids := make([]api.Pin, 0, len(st.PinMap)) for _, v := range st.PinMap { - cids = append(cids, v.ToCidArg()) + cids = append(cids, v.ToPin()) } return cids } diff --git a/state/mapstate/map_state_test.go b/state/mapstate/map_state_test.go index f8073bec..bddb274a 100644 --- a/state/mapstate/map_state_test.go +++ b/state/mapstate/map_state_test.go @@ -12,7 +12,7 @@ import ( var testCid1, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq") var testPeerID1, _ = peer.IDB58Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc") -var c = api.CidArg{ +var c = api.Pin{ Cid: testCid1, Allocations: []peer.ID{testPeerID1}, Everywhere: false, diff --git a/test/ipfs_mock.go b/test/ipfs_mock.go index 650164a2..0e9b7624 100644 --- a/test/ipfs_mock.go +++ b/test/ipfs_mock.go @@ -93,7 +93,7 @@ func (m *IpfsMock) handler(w http.ResponseWriter, r *http.Request) { if err != nil { goto ERROR } - m.pinMap.Add(api.CidArgCid(c)) + m.pinMap.Add(api.PinCid(c)) resp := mockPinResp{ Pins: []string{cidStr}, } diff --git a/test/rpc_api_mock.go b/test/rpc_api_mock.go index 77d10507..e8d9f1b2 100644 --- a/test/rpc_api_mock.go +++ b/test/rpc_api_mock.go @@ -30,22 +30,22 @@ func NewMockRPCClient(t *testing.T) *rpc.Client { return c } -func (mock *mockService) Pin(in api.CidArgSerial, out *struct{}) error { +func (mock *mockService) Pin(in api.PinSerial, out *struct{}) error { if in.Cid == ErrorCid { return ErrBadCid } return nil } -func (mock *mockService) Unpin(in api.CidArgSerial, out *struct{}) error { +func (mock *mockService) Unpin(in api.PinSerial, out *struct{}) error { if in.Cid == ErrorCid { return ErrBadCid } return nil } -func (mock *mockService) PinList(in struct{}, out *[]api.CidArgSerial) error { - *out = []api.CidArgSerial{ +func (mock *mockService) PinList(in struct{}, out *[]api.PinSerial) error { + *out = []api.PinSerial{ { Cid: TestCid1, }, @@ -151,7 +151,7 @@ func (mock *mockService) StatusAll(in struct{}, out *[]api.GlobalPinInfoSerial) return nil } -func (mock *mockService) Status(in api.CidArgSerial, out *api.GlobalPinInfoSerial) error { +func (mock *mockService) Status(in api.PinSerial, out *api.GlobalPinInfoSerial) error { if in.Cid == ErrorCid { return ErrBadCid } @@ -174,7 +174,7 @@ func (mock *mockService) SyncAll(in struct{}, out *[]api.GlobalPinInfoSerial) er return mock.StatusAll(in, out) } -func (mock *mockService) Sync(in api.CidArgSerial, out *api.GlobalPinInfoSerial) error { +func (mock *mockService) Sync(in api.PinSerial, out *api.GlobalPinInfoSerial) error { return mock.Status(in, out) } @@ -183,15 +183,15 @@ func (mock *mockService) StateSync(in struct{}, out *[]api.PinInfoSerial) error return nil } -func (mock *mockService) Recover(in api.CidArgSerial, out *api.GlobalPinInfoSerial) error { +func (mock *mockService) Recover(in api.PinSerial, out *api.GlobalPinInfoSerial) error { return mock.Status(in, out) } -func (mock *mockService) Track(in api.CidArgSerial, out *struct{}) error { +func (mock *mockService) Track(in api.PinSerial, out *struct{}) error { return nil } -func (mock *mockService) Untrack(in api.CidArgSerial, out *struct{}) error { +func (mock *mockService) Untrack(in api.PinSerial, out *struct{}) error { return nil }