Skip to content

Commit

Permalink
Use 'dag' forall namespace import prefixes of merkledag
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <[email protected]>
  • Loading branch information
rht committed Dec 16, 2015
1 parent 5bf3a59 commit 224f7c3
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 111 deletions.
4 changes: 2 additions & 2 deletions core/commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

cmds "github.com/ipfs/go-ipfs/commands"
core "github.com/ipfs/go-ipfs/core"
merkledag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
path "github.com/ipfs/go-ipfs/path"
unixfs "github.com/ipfs/go-ipfs/unixfs"
unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
Expand Down Expand Up @@ -61,7 +61,7 @@ it contains, with the following format:

paths := req.Arguments()

var dagnodes []*merkledag.Node
var dagnodes []*dag.Node
for _, fpath := range paths {
dagnode, err := core.Resolve(req.Context(), node, path.Path(fpath))
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (
mfs "github.com/ipfs/go-ipfs/mfs"

mount "github.com/ipfs/go-ipfs/fuse/mount"
merkledag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
namesys "github.com/ipfs/go-ipfs/namesys"
ipnsrp "github.com/ipfs/go-ipfs/namesys/republisher"
path "github.com/ipfs/go-ipfs/path"
Expand Down Expand Up @@ -91,11 +91,11 @@ type IpfsNode struct {
PrivateKey ic.PrivKey // the local node's private Key

// Services
Peerstore peer.Peerstore // storage for other Peer instances
Blockstore bstore.GCBlockstore // the block store (lower level)
Blocks *bserv.BlockService // the block service, get/add blocks.
DAG merkledag.DAGService // the merkle dag service, get/add objects.
Resolver *path.Resolver // the path resolution system
Peerstore peer.Peerstore // storage for other Peer instances
Blockstore bstore.GCBlockstore // the block store (lower level)
Blocks *bserv.BlockService // the block service, get/add blocks.
DAG dag.DAGService // the merkle dag service, get/add objects.
Resolver *path.Resolver // the path resolution system
Reporter metrics.Reporter
Discovery discovery.Service
FilesRoot *mfs.Root
Expand Down Expand Up @@ -477,7 +477,7 @@ func (n *IpfsNode) loadFilesRoot() error {
return n.Repo.Datastore().Put(dsk, []byte(k))
}

var nd *merkledag.Node
var nd *dag.Node
val, err := n.Repo.Datastore().Get(dsk)

switch {
Expand Down
6 changes: 3 additions & 3 deletions core/coreunix/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import (
offline "github.com/ipfs/go-ipfs/exchange/offline"
importer "github.com/ipfs/go-ipfs/importer"
chunk "github.com/ipfs/go-ipfs/importer/chunk"
merkledag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
ft "github.com/ipfs/go-ipfs/unixfs"
uio "github.com/ipfs/go-ipfs/unixfs/io"
u "github.com/ipfs/go-ipfs/util"
)

func getDagserv(t *testing.T) merkledag.DAGService {
func getDagserv(t *testing.T) dag.DAGService {
db := dssync.MutexWrap(ds.NewMapDatastore())
bs := bstore.NewBlockstore(db)
blockserv := bserv.New(bs, offline.Exchange(bs))
return merkledag.NewDAGService(blockserv)
return dag.NewDAGService(blockserv)
}

func TestMetadata(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/pathresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"

merkledag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
path "github.com/ipfs/go-ipfs/path"
)

Expand All @@ -19,7 +19,7 @@ var ErrNoNamesys = errors.New(
// entries (e.g. /ipns/<node-key>) and then going through the /ipfs/
// entries and returning the final merkledag node. Effectively
// enables /ipns/, /dns/, etc. in commands.
func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (*merkledag.Node, error) {
func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (*dag.Node, error) {
if strings.HasPrefix(p.String(), "/ipns/") {
// resolve ipns paths

Expand Down
4 changes: 2 additions & 2 deletions fuse/ipns/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"

"github.com/ipfs/go-ipfs/core"
mdag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
nsys "github.com/ipfs/go-ipfs/namesys"
ci "github.com/ipfs/go-ipfs/p2p/crypto"
path "github.com/ipfs/go-ipfs/path"
Expand All @@ -14,7 +14,7 @@ import (
// InitializeKeyspace sets the ipns record for the given key to
// point to an empty directory.
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
emptyDir := &mdag.Node{Data: ft.FolderPBData()}
emptyDir := &dag.Node{Data: ft.FolderPBData()}
nodek, err := n.DAG.Add(emptyDir)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions fuse/readonly/readonly_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
core "github.com/ipfs/go-ipfs/core"
mdag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
path "github.com/ipfs/go-ipfs/path"
uio "github.com/ipfs/go-ipfs/unixfs/io"
ftpb "github.com/ipfs/go-ipfs/unixfs/pb"
Expand Down Expand Up @@ -77,7 +77,7 @@ func (*Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
// Node is the core object representing a filesystem tree node.
type Node struct {
Ipfs *core.IpfsNode
Nd *mdag.Node
Nd *dag.Node
fd *uio.DagReader
cached *ftpb.Data
}
Expand Down
10 changes: 5 additions & 5 deletions importer/trickle/trickle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
chunk "github.com/ipfs/go-ipfs/importer/chunk"
h "github.com/ipfs/go-ipfs/importer/helpers"
merkledag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
pin "github.com/ipfs/go-ipfs/pin"
ft "github.com/ipfs/go-ipfs/unixfs"
uio "github.com/ipfs/go-ipfs/unixfs/io"
u "github.com/ipfs/go-ipfs/util"
)

func buildTestDag(ds merkledag.DAGService, spl chunk.Splitter) (*merkledag.Node, error) {
func buildTestDag(ds dag.DAGService, spl chunk.Splitter) (*dag.Node, error) {
dbp := h.DagBuilderParams{
Dagserv: ds,
Maxlinks: h.DefaultLinksPerBlock,
Expand Down Expand Up @@ -121,7 +121,7 @@ func arrComp(a, b []byte) error {
}

type dagservAndPinner struct {
ds merkledag.DAGService
ds dag.DAGService
mp pin.Pinner
}

Expand Down Expand Up @@ -523,7 +523,7 @@ func TestAppendSingleBytesToEmpty(t *testing.T) {

data := []byte("AB")

nd := new(merkledag.Node)
nd := new(dag.Node)
nd.Data = ft.FilePBData(nil, 0)

dbp := &h.DagBuilderParams{
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestAppendSingleBytesToEmpty(t *testing.T) {
}
}

func printDag(nd *merkledag.Node, ds merkledag.DAGService, indent int) {
func printDag(nd *dag.Node, ds dag.DAGService, indent int) {
pbd, err := ft.FromBytes(nd.Data)
if err != nil {
panic(err)
Expand Down
20 changes: 10 additions & 10 deletions merkledag/traverse/traverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"

mdag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
)

// Order is an identifier for traversal algorithm orders
Expand All @@ -20,17 +20,17 @@ const (

// Options specifies a series of traversal options
type Options struct {
DAG mdag.DAGService // the dagservice to fetch nodes
Order Order // what order to traverse in
Func Func // the function to perform at each step
ErrFunc ErrFunc // see ErrFunc. Optional
DAG dag.DAGService // the dagservice to fetch nodes
Order Order // what order to traverse in
Func Func // the function to perform at each step
ErrFunc ErrFunc // see ErrFunc. Optional

SkipDuplicates bool // whether to skip duplicate nodes
}

// State is a current traversal state
type State struct {
Node *mdag.Node
Node *dag.Node
Depth int
}

Expand All @@ -39,7 +39,7 @@ type traversal struct {
seen map[string]struct{}
}

func (t *traversal) shouldSkip(n *mdag.Node) (bool, error) {
func (t *traversal) shouldSkip(n *dag.Node) (bool, error) {
if t.opts.SkipDuplicates {
k, err := n.Key()
if err != nil {
Expand All @@ -63,9 +63,9 @@ func (t *traversal) callFunc(next State) error {
// stop processing. if it returns a nil node, just skip it.
//
// the error handling is a little complicated.
func (t *traversal) getNode(link *mdag.Link) (*mdag.Node, error) {
func (t *traversal) getNode(link *dag.Link) (*dag.Node, error) {

getNode := func(l *mdag.Link) (*mdag.Node, error) {
getNode := func(l *dag.Link) (*dag.Node, error) {
next, err := l.GetNode(context.TODO(), t.opts.DAG)
if err != nil {
return nil, err
Expand Down Expand Up @@ -103,7 +103,7 @@ type Func func(current State) error
//
type ErrFunc func(err error) error

func Traverse(root *mdag.Node, o Options) error {
func Traverse(root *dag.Node, o Options) error {
t := traversal{
opts: o,
seen: map[string]struct{}{},
Expand Down
26 changes: 13 additions & 13 deletions merkledag/traverse/traverse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

mdag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
)

func TestDFSPreNoSkip(t *testing.T) {
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestBFSSkip(t *testing.T) {
`))
}

func testWalkOutputs(t *testing.T, root *mdag.Node, opts Options, expect []byte) {
func testWalkOutputs(t *testing.T, root *dag.Node, opts Options, expect []byte) {
expect = bytes.TrimLeft(expect, "\n")

buf := new(bytes.Buffer)
Expand All @@ -341,26 +341,26 @@ func testWalkOutputs(t *testing.T, root *mdag.Node, opts Options, expect []byte)
}
}

func newFan(t *testing.T) *mdag.Node {
a := &mdag.Node{Data: []byte("/a")}
func newFan(t *testing.T) *dag.Node {
a := &dag.Node{Data: []byte("/a")}
addChild(t, a, "aa")
addChild(t, a, "ab")
addChild(t, a, "ac")
addChild(t, a, "ad")
return a
}

func newLinkedList(t *testing.T) *mdag.Node {
a := &mdag.Node{Data: []byte("/a")}
func newLinkedList(t *testing.T) *dag.Node {
a := &dag.Node{Data: []byte("/a")}
aa := addChild(t, a, "aa")
aaa := addChild(t, aa, "aaa")
aaaa := addChild(t, aaa, "aaaa")
addChild(t, aaaa, "aaaaa")
return a
}

func newBinaryTree(t *testing.T) *mdag.Node {
a := &mdag.Node{Data: []byte("/a")}
func newBinaryTree(t *testing.T) *dag.Node {
a := &dag.Node{Data: []byte("/a")}
aa := addChild(t, a, "aa")
ab := addChild(t, a, "ab")
addChild(t, aa, "aaa")
Expand All @@ -370,8 +370,8 @@ func newBinaryTree(t *testing.T) *mdag.Node {
return a
}

func newBinaryDAG(t *testing.T) *mdag.Node {
a := &mdag.Node{Data: []byte("/a")}
func newBinaryDAG(t *testing.T) *dag.Node {
a := &dag.Node{Data: []byte("/a")}
aa := addChild(t, a, "aa")
aaa := addChild(t, aa, "aaa")
aaaa := addChild(t, aaa, "aaaa")
Expand All @@ -383,15 +383,15 @@ func newBinaryDAG(t *testing.T) *mdag.Node {
return a
}

func addLink(t *testing.T, a, b *mdag.Node) {
func addLink(t *testing.T, a, b *dag.Node) {
to := string(a.Data) + "2" + string(b.Data)
if err := a.AddNodeLink(to, b); err != nil {
t.Error(err)
}
}

func addChild(t *testing.T, a *mdag.Node, name string) *mdag.Node {
c := &mdag.Node{Data: []byte(string(a.Data) + "/" + name)}
func addChild(t *testing.T, a *dag.Node, name string) *dag.Node {
c := &dag.Node{Data: []byte(string(a.Data) + "/" + name)}
addLink(t, a, c)
return c
}
14 changes: 7 additions & 7 deletions path/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"

key "github.com/ipfs/go-ipfs/blocks/key"
merkledag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
)

Expand All @@ -33,7 +33,7 @@ func (e ErrNoLink) Error() string {
// Resolver provides path resolution to IPFS
// It has a pointer to a DAGService, which is uses to resolve nodes.
type Resolver struct {
DAG merkledag.DAGService
DAG dag.DAGService
}

// SplitAbsPath clean up and split fpath. It extracts the first component (which
Expand Down Expand Up @@ -64,7 +64,7 @@ func SplitAbsPath(fpath Path) (mh.Multihash, []string, error) {

// ResolvePath fetches the node for given path. It returns the last item
// returned by ResolvePathComponents.
func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (*merkledag.Node, error) {
func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (*dag.Node, error) {
// validate path
if err := fpath.IsValid(); err != nil {
return nil, err
Expand All @@ -80,7 +80,7 @@ func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (*merkledag.Node
// ResolvePathComponents fetches the nodes for each segment of the given path.
// It uses the first path component as a hash (key) of the first node, then
// resolves all other components walking the links, with ResolveLinks.
func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]*merkledag.Node, error) {
func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]*dag.Node, error) {
h, parts, err := SplitAbsPath(fpath)
if err != nil {
return nil, err
Expand All @@ -102,17 +102,17 @@ func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]*me
//
// ResolveLinks(nd, []string{"foo", "bar", "baz"})
// would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links
func (s *Resolver) ResolveLinks(ctx context.Context, ndd *merkledag.Node, names []string) ([]*merkledag.Node, error) {
func (s *Resolver) ResolveLinks(ctx context.Context, ndd *dag.Node, names []string) ([]*dag.Node, error) {

result := make([]*merkledag.Node, 0, len(names)+1)
result := make([]*dag.Node, 0, len(names)+1)
result = append(result, ndd)
nd := ndd // dup arg workaround

// for each of the path components
for _, name := range names {

var next key.Key
var nlink *merkledag.Link
var nlink *dag.Link
// for each of the links in nd, the current object
for _, link := range nd.Links {
if link.Name == name {
Expand Down
6 changes: 3 additions & 3 deletions path/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"

key "github.com/ipfs/go-ipfs/blocks/key"
merkledag "github.com/ipfs/go-ipfs/merkledag"
dag "github.com/ipfs/go-ipfs/merkledag"
dagmock "github.com/ipfs/go-ipfs/merkledag/test"
path "github.com/ipfs/go-ipfs/path"
util "github.com/ipfs/go-ipfs/util"
)

func randNode() (*merkledag.Node, key.Key) {
node := new(merkledag.Node)
func randNode() (*dag.Node, key.Key) {
node := new(dag.Node)
node.Data = make([]byte, 32)
util.NewTimeSeededRand().Read(node.Data)
k, _ := node.Key()
Expand Down
Loading

0 comments on commit 224f7c3

Please sign in to comment.