Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat: support DAG API #534

Merged
merged 8 commits into from
Apr 5, 2018
Merged

feat: support DAG API #534

merged 8 commits into from
Apr 5, 2018

Conversation

daviddias
Copy link
Contributor

Will need changes that come from ipfs/kubo#3771 (comment)

@daviddias daviddias requested review from whyrusleeping and removed request for whyrusleeping March 9, 2017 16:14
This was referenced Mar 10, 2017
@magik6k magik6k mentioned this pull request May 4, 2017
@atfornes
Copy link
Contributor

@diasdavid, could you please share what have to be done to complete the DAG API?

you mentioned that different formats have to be supported at #549, is it related with https://github.com/ipld/interface-ipld-format implementations?

if the tasks are relatively easy I can try to help with this in the JavaScript part.

Thanks

@daviddias
Copy link
Contributor Author

Right now, we just need these tasks to be done: ipfs/kubo#3771 (comment), essentially, the http-api needs to support what we need in order to complete the JS. Would you like to take a look at that? :)

@atfornes
Copy link
Contributor

@diasdavid, I am afraid I am not familiar enough with Go language to help with the http-api. Is there something else I can do to help pushing forward the solution for this issue?

@atfornes
Copy link
Contributor

@diasdavid, what about implementing it in js-ipfs http API? does it makes sense? https://github.com/ipfs/js-ipfs/tree/master/src/http-api

@magik6k
Copy link
Contributor

magik6k commented Aug 12, 2017

So with fixes/additions in ipfs/kubo#4133 current status is that:

  • dag.put works on both sides both for dag-cbor and dag-pb
  • dag.get doesn't because:
    • We need to resolve top level block in path, get it, resolve remaining path on JS side
    • For that either ipfs resolve must be extended to return IPLD path remainder or something like ipfs dag resolve must be added
    • We then need to block get the resolved block and parse it on JS side
    • Then return subnode under whatever remainder path it was within a block.

@diasdavid Is my thinking here correct or do you think this can be solved in a simpler way?

@magik6k magik6k force-pushed the feat/dag-api branch 2 times, most recently from 8e6d61b to 1caafb8 Compare August 13, 2017 18:51
@magik6k
Copy link
Contributor

magik6k commented Aug 13, 2017

So I rebased this on current master and implemented get as as dag resolve+block get. Everything seems to work on both (go-ipfs / js-api) sides, test failures here appear to be related more to the tests itself or deeper IPLD stuff.

src/dag/get.js Outdated
dagPB.resolver.resolve(blk, path, cb)
}
}
], callback)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@magik6k this is an interesting approach. It misses any other format that is not dag-cbor and or dag-pb. I also believe that it won't pass every test currently present in https://github.com/ipfs/interface-ipfs-core/blob/master/src/dag.js, which is a requisite to get things merged in js-ipfs-api.

I had understood that you were working on implementing the dag api on go-ipfs, is there anything blocking you there from finishing the implementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

go-ipfs side is done. Now that i think of it, is there any reason the code for put which was here earlier didn't just pass the data as json to go-ipfs? Passing json directly instead of serializing it here would allow to support every encoding go side supports without additional work here.

The same is the case for get with the difference that using go-ipfs dag get doesn't return remainderPath(I don't think there is any case where it wouldn't be empty). Does the value passed to callback in get implement any API or is it much like just like parsing json from ipfs dag get?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing json directly instead of serializing it here would allow to support every encoding go side supports without additional work here.

Using json for all the serialization has a big drawback described here: https://github.com/ipfs/interface-ipfs-core/issues/81#issuecomment-277271941

tl;dr; JSON doesn't support Buffers, which makes it really hard to distinguish a Buffer from a String, you can see that we do a cast to Buffer every single time in object get just because we know that Data in the protobuf is always binary. This is the tl;dr; but please do read the whole thread :)

The same is the case for get with the difference that using go-ipfs dag get doesn't return remainderPath(I don't think there is any case where it wouldn't be empty)

remainderPath should return any path that the node wasn't able to resolve either because it couldn't find more nodes or because it didn't have the right parser for it.

if (format === 'dag-pb') {
dagPB.util.serialize(dagNode, finalize)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@daviddias daviddias changed the title feat: DAG API feat: support DAG API Oct 9, 2017
@daviddias daviddias mentioned this pull request Oct 9, 2017
@daviddias daviddias removed the backlog label Oct 13, 2017
@koalalorenzo
Copy link

Do we have any update on this? ETA? :)
Do you need any help for this PR?

@vmx
Copy link
Contributor

vmx commented Feb 12, 2018

@koalalorenzo I don't have an ETA for this. I currently working on getting the CLI to support the dag command (ipfs/js-ipfs#1212).

In regards to help: sure, any help is welcome. After a quick look at this PR, I think it shouldn't use the IPLD formats directly, but instead use the API from https://github.com/ipld/js-ipld. This way you needed care format specific things yourself, but have support for all.

@diasdavid Do you agree that using js-ipld would make sense?

@pcardune
Copy link

pcardune commented Feb 15, 2018

I got here looking for a way to put an IPLD serialized object into an IPFS node while that IPFS node was running as a daemon. I'm aware that this can now be done with ipfs dag put < somedata.json, but I'm looking for something that doesn't require spawning subprocesses.

I figured out how to use ipld-js to store the data while the IPFS node is not running: https://gist.github.com/pcardune/411c93eb4dd7d15a642b3750a4bd8cfa. But then you have to start the IPFS node to make that data available publicly.

I'm guessing that this PR would solve my problem, but since it's unclear if and when this PR is going to get merged, I'm wondering if there is another way to accomplish this?

cc @jaycenhorton

@daviddias
Copy link
Contributor Author

@diasdavid Do you agree that using js-ipld would make sense?

I do :) That was my realization on #534 (comment), that we can use js-ipld and use the ipfsAPI.block as the block service that js-ipld uses. This way we don't have any serialization problems.

@vmx
Copy link
Contributor

vmx commented Feb 16, 2018

@koalalorenzo @pcardune @jaycenhorton I'm working on this now. I thought it's a piece of cake, but it turned out that it's harder than I thought (too many bugs and outdated code on the way). Though I'll have a look again next week.

@vmx
Copy link
Contributor

vmx commented Feb 22, 2018

A quick update: I run into more troubles than expected. I'll link the issues here in case someone wants to know more.

@daviddias
Copy link
Contributor Author

@vmx AFAIU you won't get the nice dag API -- as in https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md -- from go-ipfs http-api soon due to how things are wired inside go-ipfs (@Stebalien can confirm). You will need to implement the dag API by bringing js-ipld and mounting it on top of the Block API, making the resolve happen clientside.

@vmx
Copy link
Contributor

vmx commented Feb 22, 2018

@diasdavid ipfs/kubo#4728 (comment) sounds promising.

At least it should be possible to do it "manually" in JS land. But currently even that is not really possible. If you request <cid>/Data you will get an error and not the CID with Data as remainder path back. Just to be clear that totally makes sense, the JS implementations do the same for paths they don't know. So let's just keep the fingers crossed that there will be a js-ipld compatible representation of Protocol Buffer blocks in the future. Until then it will just not be supported by js-ipfs-api.

There was a refactoring, now the usual way of doing a HTTP request
is through SendOneFile.
@vmx
Copy link
Contributor

vmx commented Apr 3, 2018

Many people have worked on this. I've rebased the commits and added my own ones. This is ready for review, so @diasdavid and @magik6k please review it.

}
if (format === 'dag-pb') {
dagPB.util.serialize(dagNode, finalize)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about all the other types?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use js-ipld here

Copy link
Contributor

Choose a reason for hiding this comment

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

Later. This PR is on for almost a year.

The plan surely is to use js-ipld. But that's not straight forward as js-ipld currently only works with local repositories and not with remote ones (that's what I wanted to mention in the JS Dev call but couldn't remember).

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough.

I'd import git here too as it's the one other (well) supported codec on go-ipfs side (and would be really handy to have for https://github.com/ipfs-shipyard/IGiS which can't use window.ipfs from api now)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it OK if I I open an issue for it and do it in a separate PR? That' also something newcomers can work on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR won't let users resolve through multiple IPLD formats.

Copy link
Contributor

Choose a reason for hiding this comment

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

@diasdavid Sounds like a test for that is missing in interface-ipfs-core then.

It will work once js-ipld is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Summary of this thread: everything mentioned here is solved if js-ipld is used. Hence I propose merging this change as is currently is and open a new issue (I'll do that) to use js-ipld instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good my IPLD captain! 🚢

@daviddias daviddias merged commit 9c37213 into master Apr 5, 2018
@daviddias daviddias deleted the feat/dag-api branch April 5, 2018 15:02
@ghost ghost removed the in progress label Apr 5, 2018
@vmx vmx mentioned this pull request Apr 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants