提交 eeab5f9b 作者: Jeromy

fix issue with blocks not actually being stored via dagservice

上级 4b97f1f2
......@@ -57,7 +57,6 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
if !ok {
return nil, fmt.Errorf("data associated with %s is not a []byte", k)
}
u.DOut("Got data: %v\n", bdata)
return &blocks.Block{
Multihash: mh.Multihash(k),
Data: bdata,
......
......@@ -12,7 +12,6 @@ import (
importer "github.com/jbenet/go-ipfs/importer"
dag "github.com/jbenet/go-ipfs/merkledag"
u "github.com/jbenet/go-ipfs/util"
mh "github.com/jbenet/go-multihash"
)
// Error indicating the max depth has been exceded.
......@@ -121,14 +120,13 @@ func addFile(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
// addNode adds the node to the graph + local storage
func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error {
// add the file to the graph + local storage
k, err := n.DAG.Put(nd)
err := n.DAG.AddRecursive(nd)
if err != nil {
return err
}
u.POut("added %s %s\n", fpath, mh.Multihash(k).B58String())
return nil
u.POut("added %s\n", fpath)
// ensure we keep it. atm no-op
// return n.PinDagNode(root)
return n.PinDagNode(nd)
}
......@@ -37,10 +37,22 @@ func catCmd(c *commander.Command, inp []string) error {
return err
}
fmt.Println("Printing Data!")
_, err = fmt.Printf("%s", nd.Data)
if err != nil {
return err
}
fmt.Println("Printing child nodes:")
for _, subn := range nd.Links {
k := u.Key(subn.Hash)
blk, err := n.Blocks.GetBlock(k)
fmt.Printf("Getting link: %s\n", k.Pretty())
if err != nil {
return err
}
fmt.Println(string(blk.Data))
}
}
return nil
}
......@@ -147,3 +147,8 @@ func loadBitswap(cfg *config.Config, d ds.Datastore) (*bitswap.BitSwap, error) {
return bitswap.NewBitSwap(local, net, d, route), nil
}
func (n *IpfsNode) PinDagNode(nd *merkledag.Node) error {
u.POut("Pinning node. Currently No-Op\n")
return nil
}
......@@ -22,7 +22,7 @@ type PrivKey interface {
// Decrypt a message encrypted with this keys public key
Decrypt([]byte) ([]byte, error)
// Return a public key paired with this private key
// Return the public key paired with this private key
GetPublic() PubKey
// Generate a secret string of bytes
......
......@@ -30,6 +30,9 @@ func NewDagFromReader(r io.Reader) (*dag.Node, error) {
return nil, err
}
}
fmt.Println(root.Links)
return root, nil
}
......
......@@ -55,6 +55,7 @@ func (n *Node) AddNodeLink(name string, that *Node) error {
Name: name,
Size: s,
Hash: h,
Node: that,
})
return nil
}
......@@ -97,8 +98,10 @@ type DAGService struct {
Blocks *bserv.BlockService
}
// Put adds a node to the DAGService, storing the block in the BlockService
func (n *DAGService) Put(nd *Node) (u.Key, error) {
// Add adds a node to the DAGService, storing the block in the BlockService
func (n *DAGService) Add(nd *Node) (u.Key, error) {
k, _ := nd.Key()
u.DOut("DagService Add [%s]\n", k.Pretty())
if n == nil {
return "", fmt.Errorf("DAGService is nil")
}
......@@ -116,6 +119,26 @@ func (n *DAGService) Put(nd *Node) (u.Key, error) {
return n.Blocks.AddBlock(b)
}
func (n *DAGService) AddRecursive(nd *Node) error {
_, err := n.Add(nd)
if err != nil {
return err
}
for _, link := range nd.Links {
fmt.Println("Adding link.")
if link.Node == nil {
panic("Why does this node have a nil link?\n")
}
err := n.AddRecursive(link.Node)
if err != nil {
return err
}
}
return nil
}
// Get retrieves a node from the DAGService, fetching the block in the BlockService
func (n *DAGService) Get(k u.Key) (*Node, error) {
if n == nil {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论