Commit 8eaf9ff4 authored by Steven Allen's avatar Steven Allen

rename import of go-ipld-format from node/format to ipld

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent 19fbe75a
......@@ -13,7 +13,7 @@ import (
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
node "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
)
var log = logging.Logger("gc")
......@@ -128,13 +128,13 @@ func Descendants(ctx context.Context, getLinks dag.GetLinks, set *cid.Set, roots
// ColoredSet computes the set of nodes in the graph that are pinned by the
// pins in the given pinner.
func ColoredSet(ctx context.Context, pn pin.Pinner, ng node.NodeGetter, bestEffortRoots []*cid.Cid, output chan<- Result) (*cid.Set, error) {
func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffortRoots []*cid.Cid, output chan<- Result) (*cid.Set, error) {
// KeySet currently implemented in memory, in the future, may be bloom filter or
// disk backed to conserve memory.
errors := false
gcs := cid.NewSet()
getLinks := func(ctx context.Context, cid *cid.Cid) ([]*node.Link, error) {
links, err := node.GetLinks(ctx, ng, cid)
getLinks := func(ctx context.Context, cid *cid.Cid) ([]*ipld.Link, error) {
links, err := ipld.GetLinks(ctx, ng, cid)
if err != nil {
errors = true
output <- Result{Error: &CannotFetchLinksError{cid, err}}
......@@ -147,9 +147,9 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng node.NodeGetter, bestEffo
output <- Result{Error: err}
}
bestEffortGetLinks := func(ctx context.Context, cid *cid.Cid) ([]*node.Link, error) {
links, err := node.GetLinks(ctx, ng, cid)
if err != nil && err != node.ErrNotFound {
bestEffortGetLinks := func(ctx context.Context, cid *cid.Cid) ([]*ipld.Link, error) {
links, err := ipld.GetLinks(ctx, ng, cid)
if err != nil && err != ipld.ErrNotFound {
errors = true
output <- Result{Error: &CannotFetchLinksError{cid, err}}
}
......
......@@ -15,7 +15,7 @@ import (
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
node "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
)
var log = logging.Logger("pin")
......@@ -102,7 +102,7 @@ type Pinner interface {
IsPinnedWithType(*cid.Cid, PinMode) (string, bool, error)
// Pin the given node, optionally recursively.
Pin(ctx context.Context, node node.Node, recursive bool) error
Pin(ctx context.Context, node ipld.Node, recursive bool) error
// Unpin the given cid. If recursive is true, removes either a recursive or
// a direct pin. If recursive is false, only removes a direct pin.
......@@ -178,13 +178,13 @@ type pinner struct {
// Track the keys used for storing the pinning state, so gc does
// not delete them.
internalPin *cid.Set
dserv node.DAGService
internal node.DAGService // dagservice used to store internal objects
dserv ipld.DAGService
internal ipld.DAGService // dagservice used to store internal objects
dstore ds.Datastore
}
// NewPinner creates a new pinner using the given datastore as a backend
func NewPinner(dstore ds.Datastore, serv, internal node.DAGService) Pinner {
func NewPinner(dstore ds.Datastore, serv, internal ipld.DAGService) Pinner {
rcset := cid.NewSet()
dirset := cid.NewSet()
......@@ -200,7 +200,7 @@ func NewPinner(dstore ds.Datastore, serv, internal node.DAGService) Pinner {
}
// Pin the given node, optionally recursive
func (p *pinner) Pin(ctx context.Context, node node.Node, recurse bool) error {
func (p *pinner) Pin(ctx context.Context, node ipld.Node, recurse bool) error {
p.lock.Lock()
defer p.lock.Unlock()
err := p.dserv.Add(ctx, node)
......@@ -358,7 +358,7 @@ func (p *pinner) CheckIfPinned(cids ...*cid.Cid) ([]Pinned, error) {
// Now walk all recursive pins to check for indirect pins
var checkChildren func(*cid.Cid, *cid.Cid) error
checkChildren = func(rk, parentKey *cid.Cid) error {
links, err := node.GetLinks(context.TODO(), p.dserv, parentKey)
links, err := ipld.GetLinks(context.TODO(), p.dserv, parentKey)
if err != nil {
return err
}
......@@ -427,7 +427,7 @@ func cidSetWithValues(cids []*cid.Cid) *cid.Set {
}
// LoadPinner loads a pinner and its keysets from the given datastore
func LoadPinner(d ds.Datastore, dserv, internal node.DAGService) (Pinner, error) {
func LoadPinner(d ds.Datastore, dserv, internal ipld.DAGService) (Pinner, error) {
p := new(pinner)
rootKeyI, err := d.Get(pinDatastoreKey)
......@@ -597,8 +597,8 @@ func (p *pinner) PinWithMode(c *cid.Cid, mode PinMode) {
// hasChild recursively looks for a Cid among the children of a root Cid.
// The visit function can be used to shortcut already-visited branches.
func hasChild(ng node.NodeGetter, root *cid.Cid, child *cid.Cid, visit func(*cid.Cid) bool) (bool, error) {
links, err := node.GetLinks(context.TODO(), ng, root)
func hasChild(ng ipld.NodeGetter, root *cid.Cid, child *cid.Cid, visit func(*cid.Cid) bool) (bool, error) {
links, err := ipld.GetLinks(context.TODO(), ng, root)
if err != nil {
return false, err
}
......
......@@ -14,7 +14,7 @@ import (
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
node "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
)
const (
......@@ -39,7 +39,7 @@ type itemIterator func() (c *cid.Cid, ok bool)
type keyObserver func(*cid.Cid)
type sortByHash struct {
links []*node.Link
links []*ipld.Link
}
func (s sortByHash) Len() int {
......@@ -54,10 +54,10 @@ func (s sortByHash) Swap(a, b int) {
s.links[a], s.links[b] = s.links[b], s.links[a]
}
func storeItems(ctx context.Context, dag node.DAGService, estimatedLen uint64, depth uint32, iter itemIterator, internalKeys keyObserver) (*merkledag.ProtoNode, error) {
links := make([]*node.Link, 0, defaultFanout+maxItems)
func storeItems(ctx context.Context, dag ipld.DAGService, estimatedLen uint64, depth uint32, iter itemIterator, internalKeys keyObserver) (*merkledag.ProtoNode, error) {
links := make([]*ipld.Link, 0, defaultFanout+maxItems)
for i := 0; i < defaultFanout; i++ {
links = append(links, &node.Link{Cid: emptyKey})
links = append(links, &ipld.Link{Cid: emptyKey})
}
// add emptyKey to our set of internal pinset objects
......@@ -85,7 +85,7 @@ func storeItems(ctx context.Context, dag node.DAGService, estimatedLen uint64, d
break
}
links = append(links, &node.Link{Cid: k})
links = append(links, &ipld.Link{Cid: k})
}
n.SetLinks(links)
......@@ -148,7 +148,7 @@ func storeItems(ctx context.Context, dag node.DAGService, estimatedLen uint64, d
internalKeys(childKey)
// overwrite the 'empty key' in the existing links array
n.Links()[h] = &node.Link{
n.Links()[h] = &ipld.Link{
Cid: childKey,
Size: size,
}
......@@ -201,9 +201,9 @@ func writeHdr(n *merkledag.ProtoNode, hdr *pb.Set) error {
return nil
}
type walkerFunc func(idx int, link *node.Link) error
type walkerFunc func(idx int, link *ipld.Link) error
func walkItems(ctx context.Context, dag node.DAGService, n *merkledag.ProtoNode, fn walkerFunc, children keyObserver) error {
func walkItems(ctx context.Context, dag ipld.DAGService, n *merkledag.ProtoNode, fn walkerFunc, children keyObserver) error {
hdr, err := readHdr(n)
if err != nil {
return err
......@@ -238,7 +238,7 @@ func walkItems(ctx context.Context, dag node.DAGService, n *merkledag.ProtoNode,
return nil
}
func loadSet(ctx context.Context, dag node.DAGService, root *merkledag.ProtoNode, name string, internalKeys keyObserver) ([]*cid.Cid, error) {
func loadSet(ctx context.Context, dag ipld.DAGService, root *merkledag.ProtoNode, name string, internalKeys keyObserver) ([]*cid.Cid, error) {
l, err := root.GetNodeLink(name)
if err != nil {
return nil, err
......@@ -258,7 +258,7 @@ func loadSet(ctx context.Context, dag node.DAGService, root *merkledag.ProtoNode
}
var res []*cid.Cid
walk := func(idx int, link *node.Link) error {
walk := func(idx int, link *ipld.Link) error {
res = append(res, link.Cid)
return nil
}
......@@ -281,7 +281,7 @@ func getCidListIterator(cids []*cid.Cid) itemIterator {
}
}
func storeSet(ctx context.Context, dag node.DAGService, cids []*cid.Cid, internalKeys keyObserver) (*merkledag.ProtoNode, error) {
func storeSet(ctx context.Context, dag ipld.DAGService, cids []*cid.Cid, internalKeys keyObserver) (*merkledag.ProtoNode, error) {
iter := getCidListIterator(cids)
n, err := storeItems(ctx, dag, uint64(len(cids)), 0, iter, internalKeys)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment