Skip to content

Commit 66b3194

Browse files
committed
hamt: support using CIDv1 by allowing the prefix to be set
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
1 parent 5adb2a3 commit 66b3194

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

test/sharness/t0260-sharding-flag.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,23 @@ test_expect_success "sharded and unsharded output look the same" '
5555
test_cmp sharded_out unsharded_out
5656
'
5757

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+
5877
test_done

unixfs/hamt/hamt.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
format "github.com/ipfs/go-ipfs/unixfs"
3232
upb "github.com/ipfs/go-ipfs/unixfs/pb"
3333

34+
cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
3435
node "gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
3536
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
3637
"gx/ipfs/QmfJHywXQu98UeZtGJBQrPAR6AtmDjjbe3qjTo9piXHPnx/murmur3"
@@ -50,6 +51,7 @@ type HamtShard struct {
5051
tableSize int
5152
tableSizeLg2 int
5253

54+
prefix *cid.Prefix
5355
hashFunc uint64
5456

5557
prefixPadStr string
@@ -123,9 +125,14 @@ func NewHamtFromDag(dserv dag.DAGService, nd node.Node) (*HamtShard, error) {
123125
return ds, nil
124126
}
125127

128+
func (ds *HamtShard) SetPrefix(prefix *cid.Prefix) {
129+
ds.prefix = prefix
130+
}
131+
126132
// Node serializes the HAMT structure into a merkledag node with unixfs formatting
127133
func (ds *HamtShard) Node() (node.Node, error) {
128134
out := new(dag.ProtoNode)
135+
out.SetPrefix(ds.prefix)
129136

130137
// TODO: optimized 'for each set bit'
131138
for i := 0; i < ds.tableSize; i++ {

unixfs/io/dirbuilder.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ func (d *Directory) SetPrefix(prefix *cid.Prefix) {
8585
if d.dirnode != nil {
8686
d.dirnode.SetPrefix(prefix)
8787
}
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+
}
9291
}
9392

9493
// AddChild adds a (name, key)-pair to the root node.

0 commit comments

Comments
 (0)