Skip to content

Commit

Permalink
feat: hamt-type assertations
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Jun 7, 2023
1 parent 9f1466c commit ba816e4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tooling/car/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ipfs/boxo/blockservice"
"github.com/ipfs/boxo/ipld/car/v2/blockstore"
"github.com/ipfs/boxo/ipld/merkledag"
"github.com/ipfs/boxo/ipld/unixfs"
"github.com/ipfs/boxo/ipld/unixfs/hamt"
uio "github.com/ipfs/boxo/ipld/unixfs/io"
"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -228,6 +229,26 @@ func (d *UnixfsDag) MustGetCIDsInHAMTTraversal(path []string, child string) []st
tracker := dservTrackingWrapper{
DAGService: node.dsvc,
}

// Do some assertations to ensure that the HAMT is well-formed.
pbnd, ok := node.node.(*merkledag.ProtoNode)
if !ok {
panic(merkledag.ErrNotProtobuf)
}

fsn, err := unixfs.FSNodeFromBytes(pbnd.Data())
if err != nil {
panic(err)
}

if fsn.Type() != unixfs.THAMTShard {
panic(fmt.Errorf("node was not a dir shard"))
}

if fsn.HashType() != hamt.HashMurmur3 {
panic(fmt.Errorf("only murmur3 supported as hash function"))
}

h, err := hamt.NewHamtFromDag(&tracker, node.node)
if err != nil {
panic(err)
Expand Down

0 comments on commit ba816e4

Please sign in to comment.