Skip to content

Commit

Permalink
hamt: support using CIDv1 by allowing the prefix to be set
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Mar 31, 2017
1 parent 5adb2a3 commit 66b3194
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
19 changes: 19 additions & 0 deletions test/sharness/t0260-sharding-flag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions unixfs/hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
format "github.com/ipfs/go-ipfs/unixfs"
upb "github.com/ipfs/go-ipfs/unixfs/pb"

cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
node "gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
"gx/ipfs/QmfJHywXQu98UeZtGJBQrPAR6AtmDjjbe3qjTo9piXHPnx/murmur3"
Expand All @@ -50,6 +51,7 @@ type HamtShard struct {
tableSize int
tableSizeLg2 int

prefix *cid.Prefix
hashFunc uint64

prefixPadStr string
Expand Down Expand Up @@ -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++ {
Expand Down
7 changes: 3 additions & 4 deletions unixfs/io/dirbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 66b3194

Please sign in to comment.