提交 8a47786c 作者: Kevin Atkinson

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

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 076d0bd9
...@@ -55,4 +55,23 @@ test_expect_success "sharded and unsharded output look the same" ' ...@@ -55,4 +55,23 @@ test_expect_success "sharded and unsharded output look the same" '
test_cmp sharded_out unsharded_out 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 test_done
...@@ -31,6 +31,7 @@ import ( ...@@ -31,6 +31,7 @@ import (
format "github.com/ipfs/go-ipfs/unixfs" format "github.com/ipfs/go-ipfs/unixfs"
upb "github.com/ipfs/go-ipfs/unixfs/pb" upb "github.com/ipfs/go-ipfs/unixfs/pb"
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format" node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
"gx/ipfs/QmfJHywXQu98UeZtGJBQrPAR6AtmDjjbe3qjTo9piXHPnx/murmur3" "gx/ipfs/QmfJHywXQu98UeZtGJBQrPAR6AtmDjjbe3qjTo9piXHPnx/murmur3"
...@@ -50,6 +51,7 @@ type HamtShard struct { ...@@ -50,6 +51,7 @@ type HamtShard struct {
tableSize int tableSize int
tableSizeLg2 int tableSizeLg2 int
prefix *cid.Prefix
hashFunc uint64 hashFunc uint64
prefixPadStr string prefixPadStr string
...@@ -123,9 +125,14 @@ func NewHamtFromDag(dserv dag.DAGService, nd node.Node) (*HamtShard, error) { ...@@ -123,9 +125,14 @@ func NewHamtFromDag(dserv dag.DAGService, nd node.Node) (*HamtShard, error) {
return ds, nil 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 // Node serializes the HAMT structure into a merkledag node with unixfs formatting
func (ds *HamtShard) Node() (node.Node, error) { func (ds *HamtShard) Node() (node.Node, error) {
out := new(dag.ProtoNode) out := new(dag.ProtoNode)
out.SetPrefix(ds.prefix)
// TODO: optimized 'for each set bit' // TODO: optimized 'for each set bit'
for i := 0; i < ds.tableSize; i++ { for i := 0; i < ds.tableSize; i++ {
......
...@@ -85,10 +85,9 @@ func (d *Directory) SetPrefix(prefix *cid.Prefix) { ...@@ -85,10 +85,9 @@ func (d *Directory) SetPrefix(prefix *cid.Prefix) {
if d.dirnode != nil { if d.dirnode != nil {
d.dirnode.SetPrefix(prefix) d.dirnode.SetPrefix(prefix)
} }
// FIXME: Should we do this? -- kevina if d.shard != nil {
//if d.shard != nil { d.shard.SetPrefix(prefix)
// d.shard.SetPrefix(prefix) }
//}
} }
// AddChild adds a (name, key)-pair to the root node. // AddChild adds a (name, key)-pair to the root node.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论