-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
RFC: coreapi.Dag #4471
Conversation
core/coreapi/dag.go
Outdated
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) |
There was a problem hiding this comment.
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
13b7adb
to
c780466
Compare
core/coreapi/interface/interface.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
c780466
to
0a9cf52
Compare
53a14fd
to
34fe6d0
Compare
core/coreapi/dag.go
Outdated
return api.core().ResolveNode(ctx, path) | ||
} | ||
|
||
func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, depth int) ([]coreiface.Path, error) { |
There was a problem hiding this comment.
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
core/coreapi/dag_test.go
Outdated
t.Error(err) | ||
} | ||
|
||
_, err = api.Dag().Put(ctx, strings.NewReader(`"Hello"`), "json", nil) |
There was a problem hiding this comment.
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.
core/coreapi/interface/interface.go
Outdated
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? |
There was a problem hiding this comment.
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
753540a
to
7b5b4f1
Compare
7b5b4f1
to
11bc903
Compare
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
4b62309
to
b9be6c1
Compare
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
b9be6c1
to
f153c01
Compare
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? |
core/coreapi/interface/interface.go
Outdated
// 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 |
There was a problem hiding this comment.
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.
core/coreapi/interface/interface.go
Outdated
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) |
There was a problem hiding this comment.
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 Node
s?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 👍
a3952e2
to
460e0ae
Compare
Made |
460e0ae
to
f213060
Compare
@magik6k any idea why the tests are all failing? |
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
f213060
to
db31833
Compare
TODO: