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