@cryptotaxi247 / kubo / commits / 8a47786c6

hamt: support using CIDv1 by allowing the prefix to be set

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Mar 31, 2017 at 01:00 UTC 8a47786c6727a0433c7a298b2a779f9817773695
3 files changed +29 -4
test/sharness/t0260-sharding-flag.sh
+19
@@ -55,4 +55,23 @@ test_expect_success "sharded and unsharded output look the same" '
55 test_cmp sharded_out unsharded_out
56 '
57
58 +test_add_large_dir_v1() {
59 + exphash="$1"
60 + test_expect_success "ipfs add (CIDv1) on very large directory succeeds" '
61 + ipfs add -r -q --cid-version=1 testdata | tail -n1 > sharddir_out &&
62 + echo "$exphash" > sharddir_exp &&
63 + test_cmp sharddir_exp sharddir_out
64 + '
65 +}
66 +
67 +# this hash implies both the directory and the leaf entries are CIDv1
68 +SHARDEDV1="zdj7WX91spg4DsnNpvoBLjyjXUGgcTTWavygBbSifpmJdgPUA"
69 +test_add_large_dir_v1 "$SHARDEDV1"
70 +
71 +test_launch_ipfs_daemon
72 +
73 +test_add_large_dir_v1 "$SHARDEDV1"
74 +
75 +test_kill_ipfs_daemon
76 +
77 test_done
unixfs/hamt/hamt.go
+7
@@ -31,6 +31,7 @@ import (
31 format "github.com/ipfs/go-ipfs/unixfs"
32 upb "github.com/ipfs/go-ipfs/unixfs/pb"
33
34 + cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
35 proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
36 node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
37 "gx/ipfs/QmfJHywXQu98UeZtGJBQrPAR6AtmDjjbe3qjTo9piXHPnx/murmur3"
@@ -50,6 +51,7 @@ type HamtShard struct {
51 tableSize int
52 tableSizeLg2 int
53
54 + prefix *cid.Prefix
55 hashFunc uint64
56
57 prefixPadStr string
@@ -123,9 +125,14 @@ func NewHamtFromDag(dserv dag.DAGService, nd node.Node) (*HamtShard, error) {
125 return ds, nil
126 }
127
128 +func (ds *HamtShard) SetPrefix(prefix *cid.Prefix) {
129 + ds.prefix = prefix
130 +}
131 +
132 // Node serializes the HAMT structure into a merkledag node with unixfs formatting
133 func (ds *HamtShard) Node() (node.Node, error) {
134 out := new(dag.ProtoNode)
135 + out.SetPrefix(ds.prefix)
136
137 // TODO: optimized 'for each set bit'
138 for i := 0; i < ds.tableSize; i++ {
unixfs/io/dirbuilder.go
+3 -4
@@ -85,10 +85,9 @@ func (d *Directory) SetPrefix(prefix *cid.Prefix) {
85 if d.dirnode != nil {
86 d.dirnode.SetPrefix(prefix)
87 }
88 - // FIXME: Should we do this? -- kevina
89 - //if d.shard != nil {
90 - // d.shard.SetPrefix(prefix)
91 - //}
88 + if d.shard != nil {
89 + d.shard.SetPrefix(prefix)
90 + }
91 }
92
93 // AddChild adds a (name, key)-pair to the root node.