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

Bitswap wantlist API #5077

Closed
richardschneider opened this issue Jun 5, 2018 · 6 comments
Closed

Bitswap wantlist API #5077

richardschneider opened this issue Jun 5, 2018 · 6 comments

Comments

@richardschneider
Copy link

According to the docs /api/v0/bitswap/wantlist returns Keys which is an array of string. I assume that the string is either a CID or a block's multihash.

However, Keys is actually an array of objects, with I think is an IPLD link

{"Keys":[{"/":"QmPfMX1epKLZNxG3cAoXYehjiP3inGpzFxFFKW1EregzgC"}]}

It should return something like

{"Keys":["QmPfMX1epKLZNxG3cAoXYehjiP3inGpzFxFFKW1EregzgC"]}

@magik6k
Copy link
Member

magik6k commented Jun 5, 2018

This is probably a bug in docs generator as the output type is defined as

https://github.com/ipfs/go-ipfs/blob/f7a980926bc4a60f0b51fb665a39316d2dee4890/core/commands/refs.go#L20-L23

and in go cid.Cid overrides 'standard' json serialization:

https://github.com/ipfs/go-cid/blob/078355866b1dda1658b5fdc5496ed7e25fdcf883/cid.go#L407-L415

@richardschneider
Copy link
Author

Thanks @magik6k for the code pointers.

My question is why does it override 'standard' json serialization? IPLD is a much higher 'protocol' than bitswap. Bitswap deals with blocks and CIDs.

@Mr0grog
Copy link
Contributor

Mr0grog commented Jun 6, 2018

If that’s the right output (so we don’t want to change it), it seems like we need to add a special case in the docs generator.

Anybody know if there are other types that need special casing like this?

@richardschneider
Copy link
Author

@Mr0grog I really think that the documentation is correct and the API should just return the CIDs. Why make Bitwswap API consumers know about IPLD (which seems to be WIP)?

@Mr0grog
Copy link
Contributor

Mr0grog commented Jun 6, 2018

IPLD is a much higher 'protocol' than bitswap

Sure, it’s certainly “higher” than a set of routines concerned with trading bits, but the API isn’t bitswap. It’s data about bitswap, and IPLD is concerned with how you represent and parse data.

On the other hand, I totally agree that it doesn’t seem especially useful that every instance of a CID in the API is formatted as a link (besides, a CID doesn’t even have to be formatted like {"/": "<cid>"} to be a link). It does feel like it adds a lot of noise to the API.

(It also looks to me like this was really an unintended (?) consequence of trying to make it easier for CBOR to represent a link with just a CID, rather than differentiating the two concepts. I was surprised to realize that’s how it works last week.)

From a more practical perspective, though, this has been the way the API has worked for over a year and it affects 9 API endpoints:

  • /api/v0/bitswap/stat
  • /api/v0/bitswap/wantlist
  • /api/v0/dag/put
  • /api/v0/dag/resolve
  • /api/v0/filestore/ls
  • /api/v0/filestore/verify
  • /api/v0/object/diff
  • /api/v0/repo/gc
  • /api/v0/stats/bitswap

Seems like a very non-trivial change.

I also think it’s worth considering that, as I learned during the docs research and heard repeatedly since then, the HTTP API docs are not widely considered a reliable or especially useful reference.

@Mr0grog
Copy link
Contributor

Mr0grog commented Jun 11, 2018

I didn’t mean to derail this discussion entirely! If this is still worth discussing, @richardschneider, we certainly should. I just wanted to make sure we understand the scope when making decisions on this.

Mr0grog added a commit to Mr0grog/http-api-docs that referenced this issue Jun 11, 2018
Cid objects always serialize to JSON as `{"/": "<cid string>"}` (https://github.com/ipfs/go-cid/blob/078355866b1dda1658b5fdc5496ed7e25fdcf883/cid.go#L407-L415). There's no obvious way to detect what any type's serialization behavior might be, so we need a special case explicitly for CIDs here.

Also specially calls out Multiaddrs. It doesn't appear that we have any other interfaces or pointer types besides these two that wind up in response schemas. I don't know that string checking on the type is really the best way to do this, but it seemed expendient and avoids needing to depend on CID and Multiaddr packages and make sure they stay in sync with the version of IPFS we are working against.

There is also some discussion here (ipfs/kubo#5077) on whether this is the right formatting for CIDs. For now, I'm including it here because I heard plenty of complaints about the usefulness and accuracy of these docs from users. The output of this tool is preceived as documentation and not a spec, so I think it's right that it shows what IPFS actually *does,* not just what we think it *ought* to. (If we wanted this to be more like a spec, we need a way to annotate it for users to explain the difference between implementation and spec.)

License: MIT
Signed-off-by: Rob Brackett <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants