Skip to content

Commit 1c8d118

Browse files
committed
fix(merkledag): address PR comments
1 parent d863a07 commit 1c8d118

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

coding_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func init() {
3030
panic(err)
3131
}
3232
benchInput = enc
33-
// println(len(benchInput))
3433
}
3534

3635
func BenchmarkRoundtrip(b *testing.B) {
@@ -46,7 +45,6 @@ func BenchmarkRoundtrip(b *testing.B) {
4645
if err != nil {
4746
b.Fatal(err)
4847
}
49-
// println(len(benchInput), len(enc))
5048
_ = enc
5149
}
5250
})

node.go

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// Common errors
1818
var (
1919
ErrNotProtobuf = fmt.Errorf("expected protobuf dag node")
20+
ErrNotRawNode = fmt.Errorf("expected raw bytes node")
2021
ErrLinkNotFound = fmt.Errorf("no link by that name")
2122
)
2223

@@ -27,6 +28,18 @@ type immutableProtoNode struct {
2728

2829
// ProtoNode represents a node in the IPFS Merkle DAG.
2930
// nodes have opaque data and a set of navigable links.
31+
// ProtoNode is a go-ipld-legacy.UniversalNode, meaning it is both
32+
// a go-ipld-prime node and a go-ipld-format node.
33+
// ProtoNode maintains compatibility with it's original implementation
34+
// as a go-ipld-format only node, which included some mutability, namely the
35+
// the ability to add/remove links in place
36+
//
37+
// TODO: We should be able to eventually replace this implementation with
38+
// * go-codec-dagpb for basic DagPB encode/decode to go-ipld-prime
39+
// * go-unixfsnode ADLs for higher level DAGPB functionality
40+
// For the time being however, go-unixfsnode is read only and
41+
// this mutable protonode implementation is needed to support go-unixfs,
42+
// the only library that implements both read and write for UnixFS v1.
3043
type ProtoNode struct {
3144
links []*format.Link
3245
data []byte

prime.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package merkledag
22

33
import (
4-
"github.com/ipld/go-ipld-prime"
54
dagpb "github.com/ipld/go-codec-dagpb"
5+
"github.com/ipld/go-ipld-prime"
66
)
77

8+
// Protonode was originally implemented as a go-ipld-format node, and included
9+
// functionality that does not fit well into the model for go-ipld-prime, namely
10+
// the ability ot modify the node in place.
11+
12+
// In order to support the go-ipld-prime interface, all of these prime methods
13+
// serialize and rebuild the go-ipld-prime node as needed, so that it remains up
14+
// to date with mutations made via the add/remove link methods
15+
816
// Kind returns a value from the Kind enum describing what the
917
// essential serializable kind of this node is (map, list, integer, etc).
1018
// Most other handling of a node requires first switching upon the kind.

raw.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (rn *RawNode) MarshalJSON() ([]byte, error) {
114114

115115
func RawNodeConverter(b blocks.Block, nd ipld.Node) (legacy.UniversalNode, error) {
116116
if nd.Kind() != ipld.Kind_Bytes {
117-
return nil, ErrNotProtobuf
117+
return nil, ErrNotRawNode
118118
}
119119
return &RawNode{b, nd}, nil
120120
}

0 commit comments

Comments
 (0)