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

RFC: coreapi.Dag #4471

Merged
merged 4 commits into from
Dec 31, 2017
Merged

RFC: coreapi.Dag #4471

merged 4 commits into from
Dec 31, 2017

Conversation

magik6k
Copy link
Member

@magik6k magik6k commented Dec 8, 2017

TODO:

  • Review
  • Docs
  • Tests

@magik6k magik6k requested a review from a user December 8, 2017 22:03
@ghost ghost assigned magik6k Dec 8, 2017
@ghost ghost added the status/in-progress In progress label Dec 8, 2017
type DagAPI CoreAPI

func (api *DagAPI) Add(ctx context.Context, src io.Reader, inputEnc string, format cid.Prefix) ([]coreiface.Node, error) {
nds, err := coredag.ParseInputs(inputEnc, cid.CodecToStr[format.Codec], src, format.MhType, format.MhLength)
Copy link
Member

Choose a reason for hiding this comment

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

we should probably validate format.Codec, otherwise we would return bad data from the cid.CodeToStr map

@@ -38,6 +40,12 @@ type UnixfsAPI interface {
Ls(context.Context, Path) ([]*Link, error)
}

type DagAPI interface {
Add(ctx context.Context, src io.Reader, inputEnc string, format cid.Prefix) ([]Node, error)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe Put instead of Add?

I also think its important for people to be able to call these methods without having to import other packages. So making the format argument a pointer, and having some sort of defaults for when the user passes nil is something we should think about.

return api.core().ResolveNode(ctx, path)
}

func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, depth int) ([]coreiface.Path, error) {
Copy link
Member

Choose a reason for hiding this comment

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

this makes me realize we should have an ipfs dag tree command

t.Error(err)
}

_, err = api.Dag().Put(ctx, strings.NewReader(`"Hello"`), "json", nil)
Copy link
Member

Choose a reason for hiding this comment

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

I would check the Cid of the created object. Just one more additional protection against us breaking things in the future.

ResolvePath(context.Context, Path) (Path, error)
ResolveNode(context.Context, Path) (Node, error)
ResolveNode(context.Context, Path) (Node, error) //TODO: should this get dropped in favor of DagAPI.Get?
Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine to keep as a helper alias

License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
@magik6k magik6k force-pushed the feat/coreapi/dag branch 3 times, most recently from 4b62309 to b9be6c1 Compare December 20, 2017 12:57
License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
@magik6k
Copy link
Member Author

magik6k commented Dec 20, 2017

This is the first PR in the coreapi series that needs to get merged, mostly due to test utils being done here.

@whyrusleeping do you see anything more TODO here?

// DagAPI specifies the interface to IPLD
type DagAPI interface {
// Put inserts data using specified format and input encoding.
// If format is not specified (nil), default dag-cbor/sha256 is used
Copy link

Choose a reason for hiding this comment

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

Unless used with WithCodec or WithHash, the defaults "dag-cbor" and "sha256" are used.

type DagAPI interface {
// Put inserts data using specified format and input encoding.
// If format is not specified (nil), default dag-cbor/sha256 is used
Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) ([]Node, error)
Copy link

Choose a reason for hiding this comment

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

Why is it desirable to have Put() return a slide of Nodes?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it could return a slice of cids instead. But we need to know what was added.

Copy link

Choose a reason for hiding this comment

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

I mean why is it desirable that it's a slice -- isn't there a root node for the added dag?

Copy link
Member

Choose a reason for hiding this comment

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

hrm... I think all of our current usecases would be fine with just the 'root' cid. Can you confirm that @magik6k ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be fine, yes. I decided to return a slice as it is what was returned by coredag.ParseInputs, I think the reasoning behind it was that the reader can provide more than one node, though it's not implemented now.

Copy link

Choose a reason for hiding this comment

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

Mh okay but what's the scenario that makes us want a slice returned here, versus just calling Tree() with the Node.Cid() returned from Put()? We'll keep all those nodes around in memory to return them from a function whose purpose isn't to iterate a graph (that's what Tree() is for).

I feel like we can rather be consistent with js-ipfs here.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Two tiny comments, LGTM otherwise 👍

@magik6k
Copy link
Member Author

magik6k commented Dec 22, 2017

Made Dag.Put return a single node, this makes more sense than a slice. When we add a batching interface here in the future, having this method return a slice would be redundant (plus this wasn't really a batching interface..).

@whyrusleeping
Copy link
Member

@magik6k any idea why the tests are all failing?

License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
@whyrusleeping whyrusleeping merged commit 952a143 into master Dec 31, 2017
@whyrusleeping whyrusleeping deleted the feat/coreapi/dag branch December 31, 2017 20:58
@ghost ghost removed the status/in-progress In progress label Dec 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/core-api Topic core-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants