Commit 8a47786c authored by Kevin Atkinson's avatar Kevin Atkinson

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

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent 076d0bd9
......@@ -55,4 +55,23 @@ test_expect_success "sharded and unsharded output look the same" '
test_cmp sharded_out unsharded_out
'
test_add_large_dir_v1() {
exphash="$1"
test_expect_success "ipfs add (CIDv1) on very large directory succeeds" '
ipfs add -r -q --cid-version=1 testdata | tail -n1 > sharddir_out &&
echo "$exphash" > sharddir_exp &&
test_cmp sharddir_exp sharddir_out
'
}
# this hash implies both the directory and the leaf entries are CIDv1
SHARDEDV1="zdj7WX91spg4DsnNpvoBLjyjXUGgcTTWavygBbSifpmJdgPUA"
test_add_large_dir_v1 "$SHARDEDV1"
test_launch_ipfs_daemon
test_add_large_dir_v1 "$SHARDEDV1"
test_kill_ipfs_daemon
test_done
......@@ -31,6 +31,7 @@ import (
format "github.com/ipfs/go-ipfs/unixfs"
upb "github.com/ipfs/go-ipfs/unixfs/pb"
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
"gx/ipfs/QmfJHywXQu98UeZtGJBQrPAR6AtmDjjbe3qjTo9piXHPnx/murmur3"
......@@ -50,6 +51,7 @@ type HamtShard struct {
tableSize int
tableSizeLg2 int
prefix *cid.Prefix
hashFunc uint64
prefixPadStr string
......@@ -123,9 +125,14 @@ func NewHamtFromDag(dserv dag.DAGService, nd node.Node) (*HamtShard, error) {
return ds, nil
}
func (ds *HamtShard) SetPrefix(prefix *cid.Prefix) {
ds.prefix = prefix
}
// Node serializes the HAMT structure into a merkledag node with unixfs formatting
func (ds *HamtShard) Node() (node.Node, error) {
out := new(dag.ProtoNode)
out.SetPrefix(ds.prefix)
// TODO: optimized 'for each set bit'
for i := 0; i < ds.tableSize; i++ {
......
......@@ -85,10 +85,9 @@ func (d *Directory) SetPrefix(prefix *cid.Prefix) {
if d.dirnode != nil {
d.dirnode.SetPrefix(prefix)
}
// FIXME: Should we do this? -- kevina
//if d.shard != nil {
// d.shard.SetPrefix(prefix)
//}
if d.shard != nil {
d.shard.SetPrefix(prefix)
}
}
// AddChild adds a (name, key)-pair to the root node.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment