Skip to content

Commit 86b9376

Browse files
Merge pull request #86 from ipfs/feat/config-def-mh
allow configuration of ipldStores default hash function
2 parents a12de32 + a73d038 commit 86b9376

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

store.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
cbg "github.com/whyrusleeping/cbor-gen"
1414
)
1515

16+
const DefaultMultihash = uint64(mh.BLAKE2B_MIN + 31)
17+
1618
// IpldStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
1719
type IpldStore interface {
1820
Get(ctx context.Context, c cid.Cid, out interface{}) error
@@ -41,6 +43,8 @@ type BasicIpldStore struct {
4143
Viewer IpldBlockstoreViewer
4244

4345
Atlas *atlas.Atlas
46+
47+
DefaultMultihash uint64
4448
}
4549

4650
var _ IpldStore = &BasicIpldStore{}
@@ -89,7 +93,11 @@ type cidProvider interface {
8993

9094
// Put marshals and writes content `v` to the backing blockstore returning its CID.
9195
func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) {
92-
mhType := uint64(mh.BLAKE2B_MIN + 31)
96+
mhType := DefaultMultihash
97+
if s.DefaultMultihash != 0 {
98+
mhType = s.DefaultMultihash
99+
}
100+
93101
mhLen := -1
94102
codec := uint64(cid.DagCBOR)
95103

0 commit comments

Comments
 (0)