-
-
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
Add global option to specify the multibase encoding (server side) #5789
Conversation
ba61e50
to
f124585
Compare
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 there is a better way to integrate this using CoreAPI:
- Pick what to use for global options in CoreAPI - CoreApi.Offline #5654 (to be consistent)
- Define new CID interface:
- Only for use in user-facing apis, internally we still want to use the string-backed version because performance
- Instead of
apicid.Hash
we create implementation of this interface which keeps track of encoding - Calling
.String
on the encoding-tracking impl will get us the right base without having to remember to use cidenc everywhere
- We switch all coreapi methods to the new cid interface. This should be more contained as most of coreapi operates on path interface, which centralizes the change and makes it harder to miss places that care about encoding.
- Then we implement global coreapi option which allows user to specify encoding returned by default.
- If a coreapi method accepts path we use encoding from the given path instead of one defined by the global option
- Or provide 2 global options, one allowing to override path encoding
@Stebalien @kevina Does that make sense?
@magik6k I think that perhaps that is something we can do later. As many of the command listed above have not been converted to the CoreAPI I don't see how it will help much for now. Also, I attempted to do something like you proposed (strong multibase encoding with CID) and received considerable push back from @Stebalien (see ipfs/go-cid#64 and the discussion in #5349). Although in all fairness I was proposing we use the interface type everywhere, if we limit the new CID type to the CoreAPI interface it may become more acceptable. It sound to be like if we go with your proposal we will effectively be setting the base server side. Correct? Above else, keeping this P.R. up to date has been a time sink. I would like to get something in as this is a component of the P0 base32 work and overdue by several months. My goal now is to simplify things as much as possible so this can get in quickly. We can work on a better interface later. |
b7a1aa6
to
58caabb
Compare
58caabb
to
cbcd6dc
Compare
@kevina what's the next steps for this PR? @magik6k do you have comments based on @kevina's response last comment? Do you think it's reasonable to merge based on the current implementation? Or do you want to kick it upstairs to @Stebalien to see what he thinks? If you guys want you might consider making time to chat amongst the three of you - Steven has a Calendly (which he's soon going to regret) available here: https://calendly.com/stebalien/30min/11-28-2018?back=1 so you can make time for a 15 minute sync conversation if that's useful. |
@eingenito this p.r. is a change in direction from what me and @Stebalien agree on, the other p.r. #5777 is closer to the solution we discussed. See the comments at the end of #5349 for more context. I would like to get this p.r. pretty much as is and then if possible refine it later. I specially designed it to be an non-invasive as possible so that we will not be locked into a particular implementation. We do need to agree on is the choice of flags |
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.
Given the time constraints I think this is a decent solution.
We may also want:
ipfs dag put
- there is no way to specify encoding currentlyipfs dag get
- might be quite tricky, maybe as a separate PR
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'm actually quite impressed at how non-invasive you've been able to make this. This approach looks like it'll work quite well (baring unforeseen circumstances...).
See #5349 (comment) and #5349 (comment)
I'd rather make the CoreAPI as clean as possible for libraries. That is, a go application using the CoreAPI as a library should also be able to use a local IPLD DAGService etc. without having to use multiple CID types. @kevina is there any thing else that needs commenting on for me to unblock this? |
If we only apply this to exposed string hashes then yeah, this is fine. I don't think there is anything in CoreAPI that returns those, so 👍. |
b528a34
to
fe3e1d8
Compare
This is almost ready to go. I did some additional simplifications and updated the top-level description. Please reread it. I will rebase to clean up my commits once near the end to let people who already started to review this a change to see what's new. |
@Stebalien the test failures on Travis CI seam unrelated to my changes, and the shareness tests are passing on Cicle CI and Jenkins so we should be good to go test wise. |
For the record, one of the reasons I objected to such a long name is in the command line help text, which is now (cut off at 80 cols):
Not a super big deal and something that we can perhaps fix later. Also, for the record, my original objection to just But again, I don't think is is a big deal, especially since it won't be used much, and am more interested in getting this in, then anything else, so I am happy with |
Travis issue is #5845. Jenkins is another random fail. Also, needs a rebase. |
I've not got strong feels on this one |
@Stebalien let me know when you want to get this in and I will rebase just before. |
Nvm. It probably doesn't need another review. |
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.
Mostly nits except the panic issue in CidEncoderFromPath
. I'm find punting on the nits but they should be easy to fix.
I'll merge as soon as they're fixed and a rebase is done so rebase at will.
// GetLowLevelCidEncoder is like GetCidEncoder but meant to be used by | ||
// lower level commands. It differs from GetCidEncoder in that CIDv0 | ||
// and not, by default, auto-upgraded to CIDv1. | ||
func GetLowLevelCidEncoder(req *cmds.Request) (cidenc.Encoder, 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.
These functions should be named by what they do, not where they're used. GetLowLevelCidEncoder
doesn't tell me how this is different from GetCidEncoder
.
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 hate naming, is it okay if we punt on this?
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
502da5d
to
ccca905
Compare
This does it on ther server side for most commands. This also adds a global --output-cidv1 option. License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
ParsePath does not preserve the multibase. License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
87688df
to
f31e6b6
Compare
@Stebalien this should be good to go. Not sure why |
28f68de
to
f96bd5f
Compare
Primarily, get rid of extractCidString and cidVer. Neither of these functions did sane things when a path when a path didn't actually include a CID. For example, "boo" would yield a base32 encoder. Also: * Avoid "optional" errors. * Make it a pure function of the input path. * Extract the multibase from *any* type of path of the form /namespace/cid-like-thing/... This is a DWIM function. License: MIT Signed-off-by: Steven Allen <[email protected]>
f96bd5f
to
19d8f62
Compare
(Everything passed, just not all at once. Jenkins is a not having a good day.) |
🎆 🚀 🎆 |
Redo of #5464 but this time doing it (mostly) on the server side.
This may not be the most elegant implementation, but for now I think it is the most practical, espacally if we also want to support
?cid-base
end points for API requests. We can clean this up later to make things more elegant.It does all the work in the
core/commands
package and does not leak into other API's except for theipfs filestore
command where we need to pass an encoder function toFormatLong
method.See #5777 for an alternative client side implementation.
This adds support for
--cid-base
and--output-cidv1
option to the command line and HTTP API for the following commands:Due to the fact that some commands return the CID itself and not a string, some command support the base conversion in text output only until we upgrade to something like
refmt
which will give us more control over the JSON output:ipfs dag get
currently does not support--cid-base
due to the way it is implemented. This is considered a bug.For some commands the original path string is preserved without any additional processing and is thus unaffected by
--cid-base
:In addition all commands under
bitswap
,object
, anddag
do not, by default, auto-upgrade CIDv0 to CIDv1 as these commands are considered low-level and the conversion could cause problems (for example a dag will not survive aipfs object get' / 'ipfs object put
round trip. This can be changes by using--output-cidv1=true
.Todo:
cidenc.Interface
for right now it doesn't serve a useful purpose and it may make more sense to define it to only have anEncode
method (and noRecode
method) so the existingcid.Encoder
also implements the interface.apicid
concept all together as that will be a holdover from the client side implementation and moveapicid.Cid
tocidenc.Cid
.--output-cidv1
|--force-multibase-cids|--force-cid-base
option nameDepends on ipfs/go-cidutil#10.
Closes #5233. Closes #5234. Closes #5349.