Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow configuration of ipldStores default hash function #86

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
cbg "github.com/whyrusleeping/cbor-gen"
)

const DefaultMultihash = uint64(mh.BLAKE2B_MIN + 31)

// IpldStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
type IpldStore interface {
Get(ctx context.Context, c cid.Cid, out interface{}) error
Expand Down Expand Up @@ -41,6 +43,8 @@ type BasicIpldStore struct {
Viewer IpldBlockstoreViewer

Atlas *atlas.Atlas

DefaultMultihash uint64
}

var _ IpldStore = &BasicIpldStore{}
Expand Down Expand Up @@ -89,7 +93,11 @@ type cidProvider interface {

// Put marshals and writes content `v` to the backing blockstore returning its CID.
func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) {
mhType := uint64(mh.BLAKE2B_MIN + 31)
mhType := DefaultMultihash
if s.DefaultMultihash != 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.... this technically conflicts with the identity hash. I mean, that doesn't make sense as the default anyways, so maybe we're fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I could make it a pointer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though if you really want the identity hash you can use the cid provider thing right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. And, honestly, you shouldn't make the default "identity". That's just absolutely stupid.

mhType = s.DefaultMultihash
}

mhLen := -1
codec := uint64(cid.DagCBOR)

Expand Down