@cryptotaxi247 / kubo / commits / eeab5f9bd

fix issue with blocks not actually being stored via dagservice

Jeromy committed Sep 4, 2014 at 03:37 UTC eeab5f9bd960f8e3a698b81252bcb73c80e9e219
7 files changed +49 -9
blockservice/blockservice.go
-1
@@ -57,7 +57,6 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
57 if !ok {
58 return nil, fmt.Errorf("data associated with %s is not a []byte", k)
59 }
60 - u.DOut("Got data: %v\n", bdata)
60 return &blocks.Block{
61 Multihash: mh.Multihash(k),
62 Data: bdata,
cmd/ipfs/add.go
+3 -5
@@ -12,7 +12,6 @@ import (
12 importer "github.com/jbenet/go-ipfs/importer"
13 dag "github.com/jbenet/go-ipfs/merkledag"
14 u "github.com/jbenet/go-ipfs/util"
15 - mh "github.com/jbenet/go-multihash"
15 )
16
17 // Error indicating the max depth has been exceded.
@@ -121,14 +120,13 @@ func addFile(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
120 // addNode adds the node to the graph + local storage
121 func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error {
122 // add the file to the graph + local storage
124 - k, err := n.DAG.Put(nd)
123 + err := n.DAG.AddRecursive(nd)
124 if err != nil {
125 return err
126 }
127
129 - u.POut("added %s %s\n", fpath, mh.Multihash(k).B58String())
130 - return nil
128 + u.POut("added %s\n", fpath)
129
130 // ensure we keep it. atm no-op
133 - // return n.PinDagNode(root)
131 + return n.PinDagNode(nd)
132 }
cmd/ipfs/cat.go
+12
@@ -37,10 +37,22 @@ func catCmd(c *commander.Command, inp []string) error {
37 return err
38 }
39
40 + fmt.Println("Printing Data!")
41 _, err = fmt.Printf("%s", nd.Data)
42 if err != nil {
43 return err
44 }
45 +
46 + fmt.Println("Printing child nodes:")
47 + for _, subn := range nd.Links {
48 + k := u.Key(subn.Hash)
49 + blk, err := n.Blocks.GetBlock(k)
50 + fmt.Printf("Getting link: %s\n", k.Pretty())
51 + if err != nil {
52 + return err
53 + }
54 + fmt.Println(string(blk.Data))
55 + }
56 }
57 return nil
58 }
core/core.go
+5
@@ -147,3 +147,8 @@ func loadBitswap(cfg *config.Config, d ds.Datastore) (*bitswap.BitSwap, error) {
147
148 return bitswap.NewBitSwap(local, net, d, route), nil
149 }
150 +
151 +func (n *IpfsNode) PinDagNode(nd *merkledag.Node) error {
152 + u.POut("Pinning node. Currently No-Op\n")
153 + return nil
154 +}
crypto/key.go
+1 -1
@@ -22,7 +22,7 @@ type PrivKey interface {
22 // Decrypt a message encrypted with this keys public key
23 Decrypt([]byte) ([]byte, error)
24
25 - // Return a public key paired with this private key
25 + // Return the public key paired with this private key
26 GetPublic() PubKey
27
28 // Generate a secret string of bytes
importer/importer.go
+3
@@ -30,6 +30,9 @@ func NewDagFromReader(r io.Reader) (*dag.Node, error) {
30 return nil, err
31 }
32 }
33 +
34 + fmt.Println(root.Links)
35 +
36 return root, nil
37 }
38
merkledag/merkledag.go
+25 -2
@@ -55,6 +55,7 @@ func (n *Node) AddNodeLink(name string, that *Node) error {
55 Name: name,
56 Size: s,
57 Hash: h,
58 + Node: that,
59 })
60 return nil
61 }
@@ -97,8 +98,10 @@ type DAGService struct {
98 Blocks *bserv.BlockService
99 }
100
100 -// Put adds a node to the DAGService, storing the block in the BlockService
101 -func (n *DAGService) Put(nd *Node) (u.Key, error) {
101 +// Add adds a node to the DAGService, storing the block in the BlockService
102 +func (n *DAGService) Add(nd *Node) (u.Key, error) {
103 + k, _ := nd.Key()
104 + u.DOut("DagService Add [%s]\n", k.Pretty())
105 if n == nil {
106 return "", fmt.Errorf("DAGService is nil")
107 }
@@ -116,6 +119,26 @@ func (n *DAGService) Put(nd *Node) (u.Key, error) {
119 return n.Blocks.AddBlock(b)
120 }
121
122 +func (n *DAGService) AddRecursive(nd *Node) error {
123 + _, err := n.Add(nd)
124 + if err != nil {
125 + return err
126 + }
127 +
128 + for _, link := range nd.Links {
129 + fmt.Println("Adding link.")
130 + if link.Node == nil {
131 + panic("Why does this node have a nil link?\n")
132 + }
133 + err := n.AddRecursive(link.Node)
134 + if err != nil {
135 + return err
136 + }
137 + }
138 +
139 + return nil
140 +}
141 +
142 // Get retrieves a node from the DAGService, fetching the block in the BlockService
143 func (n *DAGService) Get(k u.Key) (*Node, error) {
144 if n == nil {