Skip to content

Commit

Permalink
merkledag: Rename Get() methods to GetPB()
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Mildred Ki'Lya <mildred-pub.git@mildred.fr>
  • Loading branch information
mildred committed Mar 1, 2016
1 parent 6144ce5 commit 34f8327
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core/commands/object/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ a file containing 'bar', and returns the hash of the new object.

e := dagutils.NewDagEditor(root, nd.DAG)

childnd, err := nd.DAG.Get(req.Context(), childk)
childnd, err := nd.DAG.GetPB(req.Context(), childk)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
Expand Down
2 changes: 1 addition & 1 deletion core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string
if typeStr == "indirect" || typeStr == "all" {
ks := key.NewKeySet()
for _, k := range n.Pinning.RecursiveKeys() {
nd, err := n.DAG.Get(ctx, k)
nd, err := n.DAG.GetPB(ctx, k)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (rw *RefWriter) writeRefsRecursive(n *dag.Node) (int, error) {
return count, err
}

nd, err := ng.Get(rw.Ctx)
nd, err := ng.GetPB(rw.Ctx)
if err != nil {
return count, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func (n *IpfsNode) loadFilesRoot() error {
}
case err == nil:
k := key.Key(val.([]byte))
nd, err = n.DAG.Get(n.Context(), k)
nd, err = n.DAG.GetPB(n.Context(), k)
if err != nil {
return fmt.Errorf("error loading filesroot from DAG: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
// ev.Node < node where resolve failed
// ev.Name < new link
// but we need to patch from the root
rnode, err := i.node.DAG.Get(ctx, key.B58KeyDecode(rsegs[1]))
rnode, err := i.node.DAG.GetPB(ctx, key.B58KeyDecode(rsegs[1]))
if err != nil {
webError(w, "putHandler: Could not create DAG from request", err, http.StatusInternalServerError)
return
Expand Down Expand Up @@ -433,7 +433,7 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {

tctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
rootnd, err := i.node.Resolver.DAG.Get(tctx, key.Key(h))
rootnd, err := i.node.Resolver.DAG.GetPB(tctx, key.Key(h))
if err != nil {
webError(w, "Could not resolve root object", err, http.StatusBadRequest)
return
Expand Down
2 changes: 1 addition & 1 deletion core/coreunix/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestAddGCLive(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
root, err := node.DAG.Get(ctx, last)
root, err := node.DAG.GetPB(ctx, last)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions core/coreunix/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error) {
ukey := key.B58KeyDecode(skey)

nd, err := n.DAG.Get(n.Context(), ukey)
nd, err := n.DAG.GetPB(n.Context(), ukey)
if err != nil {
return "", err
}
Expand All @@ -37,7 +37,7 @@ func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error
func Metadata(n *core.IpfsNode, skey string) (*ft.Metadata, error) {
ukey := key.B58KeyDecode(skey)

nd, err := n.DAG.Get(n.Context(), ukey)
nd, err := n.DAG.GetPB(n.Context(), ukey)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/coreunix/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestMetadata(t *testing.T) {
t.Fatalf("something went wrong in conversion: '%s' != '%s'", rec.MimeType, m.MimeType)
}

retnode, err := ds.Get(ctx, key.B58KeyDecode(mdk))
retnode, err := ds.GetPB(ctx, key.B58KeyDecode(mdk))
if err != nil {
t.Fatal(err)
}
Expand Down
13 changes: 7 additions & 6 deletions merkledag/merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var ErrNotFound = fmt.Errorf("merkledag: not found")
// DAGService is an IPFS Merkle DAG service.
type DAGService interface {
Add(*Node) (key.Key, error)
Get(context.Context, key.Key) (*Node, error)
GetPB(context.Context, key.Key) (*Node, error)
Remove(*Node) error

// GetDAG returns, in order, all the single leve child
Expand Down Expand Up @@ -66,8 +66,9 @@ func (n *dagService) Batch() *Batch {
return &Batch{ds: n, MaxSize: 8 * 1024 * 1024}
}

// Get retrieves a node from the dagService, fetching the block in the BlockService
func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
// GetPB retrieves a Protocol Buffer node from the dagService, fetching the
// block in the BlockService
func (n *dagService) GetPB(ctx context.Context, k key.Key) (*Node, error) {
if n == nil {
return nil, fmt.Errorf("dagService is nil")
}
Expand Down Expand Up @@ -249,10 +250,10 @@ type nodePromise struct {
// from its internal channels, subsequent calls will return the
// cached node.
type NodeGetter interface {
Get(context.Context) (*Node, error)
GetPB(context.Context) (*Node, error)
}

func (np *nodePromise) Get(ctx context.Context) (*Node, error) {
func (np *nodePromise) GetPB(ctx context.Context) (*Node, error) {
if np.cache != nil {
return np.cache, nil
}
Expand Down Expand Up @@ -314,7 +315,7 @@ func EnumerateChildren(ctx context.Context, ds DAGService, root *Node, set key.K
k := key.Key(lnk.Hash)
if !set.Has(k) {
set.Add(k)
child, err := ds.Get(ctx, k)
child, err := ds.GetPB(ctx, k)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions merkledag/merkledag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
wg.Add(1)
go func(i int) {
defer wg.Done()
first, err := dagservs[i].Get(ctx, k)
first, err := dagservs[i].GetPB(ctx, k)
if err != nil {
errs <- err
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func assertCanGet(t *testing.T, ds DAGService, n *Node) {
t.Fatal(err)
}

if _, err := ds.Get(context.Background(), k); err != nil {
if _, err := ds.GetPB(context.Background(), k); err != nil {
t.Fatal(err)
}
}
Expand All @@ -253,7 +253,7 @@ func TestCantGet(t *testing.T) {
t.Fatal(err)
}

_, err = dsp.ds.Get(context.Background(), k)
_, err = dsp.ds.GetPB(context.Background(), k)
if !strings.Contains(err.Error(), "not found") {
t.Fatal("expected err not found, got: ", err)
}
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestEnumerateChildren(t *testing.T) {
if !ks.Has(k) {
t.Fatal("missing key in set!")
}
child, err := ds.Get(context.Background(), k)
child, err := ds.GetPB(context.Background(), k)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion merkledag/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func MakeLink(n *Node) (*Link, error) {

// GetNode returns the MDAG Node that this link points to
func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) {
return serv.Get(ctx, key.Key(l.Hash))
return serv.GetPB(ctx, key.Key(l.Hash))
}

// AddNodeLink adds a link to another node.
Expand Down
4 changes: 2 additions & 2 deletions merkledag/utils/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ApplyChange(ctx context.Context, ds dag.DAGService, nd *dag.Node, cs []*Cha
for _, c := range cs {
switch c.Type {
case Add:
child, err := ds.Get(ctx, c.After)
child, err := ds.GetPB(ctx, c.After)
if err != nil {
return nil, err
}
Expand All @@ -61,7 +61,7 @@ func ApplyChange(ctx context.Context, ds dag.DAGService, nd *dag.Node, cs []*Cha
if err != nil {
return nil, err
}
child, err := ds.Get(ctx, c.After)
child, err := ds.GetPB(ctx, c.After)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion path/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]*me
}

log.Debug("Resolve dag get.")
nd, err := s.DAG.Get(ctx, key.Key(h))
nd, err := s.DAG.GetPB(ctx, key.Key(h))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pin/gc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, pn pin.Pinner) (<-chan key.
func Descendants(ctx context.Context, ds dag.DAGService, set key.KeySet, roots []key.Key) error {
for _, k := range roots {
set.Add(k)
nd, err := ds.Get(ctx, k)
nd, err := ds.GetPB(ctx, k)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pin/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (p *pinner) Pin(ctx context.Context, node *mdag.Node, recurse bool) error {

p.recursePin.AddBlock(k)
} else {
if _, err := p.dserv.Get(ctx, k); err != nil {
if _, err := p.dserv.GetPB(ctx, k); err != nil {
return err
}

Expand Down Expand Up @@ -203,7 +203,7 @@ func (p *pinner) isPinnedWithType(k key.Key, typeStr string) (string, bool, erro

// Default is "indirect"
for _, rk := range p.recursePin.GetKeys() {
rnd, err := p.dserv.Get(context.Background(), rk)
rnd, err := p.dserv.GetPB(context.Background(), rk)
if err != nil {
return "", false, err
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*5)
defer cancel()

root, err := dserv.Get(ctx, rootKey)
root, err := dserv.GetPB(ctx, rootKey)
if err != nil {
return nil, fmt.Errorf("cannot find pinning root object: %v", err)
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func hasChild(ds mdag.DAGService, root *mdag.Node, child key.Key) (bool, error)
return true, nil
}

nd, err := ds.Get(context.Background(), k)
nd, err := ds.GetPB(context.Background(), k)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion unixfs/archive/tar/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (w *Writer) writeDir(nd *mdag.Node, fpath string) error {
}

for i, ng := range mdag.GetDAG(w.ctx, w.Dag, nd) {
child, err := ng.Get(w.ctx)
child, err := ng.GetPB(w.ctx)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion unixfs/io/dagreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error {
return io.EOF
}

nxt, err := dr.promises[dr.linkPosition].Get(ctx)
nxt, err := dr.promises[dr.linkPosition].GetPB(ctx)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion unixfs/io/dirbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewDirectory(dserv mdag.DAGService) *directoryBuilder {

// AddChild adds a (name, key)-pair to the root node.
func (d *directoryBuilder) AddChild(ctx context.Context, name string, k key.Key) error {
cnode, err := d.dserv.Get(ctx, k)
cnode, err := d.dserv.GetPB(ctx, k)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion unixfs/mod/dagmodifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (dm *DagModifier) Sync() error {
return err
}

nd, err := dm.dagserv.Get(dm.ctx, thisk)
nd, err := dm.dagserv.GetPB(dm.ctx, thisk)
if err != nil {
return err
}
Expand Down

0 comments on commit 34f8327

Please sign in to comment.