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

Support specify hash algorithm in files.add #597

Merged
merged 4 commits into from
Sep 8, 2017

Conversation

alanshaw
Copy link
Contributor

@alanshaw alanshaw commented Sep 8, 2017

Specify multihash hashing alogrithm

This allows the optional param hash or hashAlg to be passed to files.add in order to specify the hash algorithm that should be used when generating the multihash(es) for the added content.

This PR also is more strict about what query string options js-ipfs-api supports by pulling out the supported params into a new query string object.

It also allows camel case aliases for params that are dash separated. This is because the HTTP API uses dash separated param names, but it is far easier to use camel case param names for internal APIs.

The other reason for allowing these aliases is because this code may be called when talking to a remote IPFS instance via the CLI where the qs params will have already been converted into camelCase.

Change object/get and object/data to accept CIDs

This is necessary because get-dagnode.js uses object/get and object/data immediately after adding files. When specifying --cid-version or using --hash (which has the effect of setting --cidversion=true) get-dagnode.js is passed a CIDv1 not a multihash/CIDv0.

Previously get-dagnode.js was extracting a multihash from a CID and sending that, effectively downgrading a CIDv1 to a CIDv0.

That causes the object to not be found (see ipfs-inactive/js-ipfs-unixfs-engine#185) since you have to retrieve using the same CID version as the data was stored.

This actually brings js-ipfs more in line with go-ipfs. Where both object/get and object/data accept a CID:

# With go ipfs daemon running...
$ ipfs add test.txt --cid-version=1 --raw-leaves=false
added zdj7WdDqrSLbsDNdtsHU5eWAeBukPoKfX9doKuTAphCowKjZR test.txt
$ ipfs object get zdj7WdDqrSLbsDNdtsHU5eWAeBukPoKfX9doKuTAphCowKjZR
{"Links":[],"Data":"\u0008\u0002\u0012\u001f(╯°□°)╯︵ ┻━┻\n\u0018\u001f"}
$ ipfs object data zdj7WdDqrSLbsDNdtsHU5eWAeBukPoKfX9doKuTAphCowKjZR
(╯°□°)╯︵ ┻━┻

Copy link
Contributor

@daviddias daviddias left a comment

Choose a reason for hiding this comment

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

minor nitpicks, otherwise LGTM 👍

@@ -14,7 +14,7 @@ const lruOptions = {
const cache = LRU(lruOptions)

module.exports = (send) => {
return promisify((multihash, options, callback) => {
return promisify((hash, options, callback) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If it is going to support both, better call it cid

@@ -24,21 +24,24 @@ module.exports = (send) => {
options = {}
}

let cid, b58Hash
Copy link
Contributor

Choose a reason for hiding this comment

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

We default to declare each variable in separate lines. Mind replacing for:

let cid
let b58Hash

Also, with the added support to cid, makes sense to call it cidB58Str

@daviddias daviddias merged commit ed68657 into ipfs-inactive:master Sep 8, 2017
dryajov pushed a commit that referenced this pull request Oct 2, 2017
*  support support specify hash alg

* Add test for add with --hash option. Pass raw cid/multihash to ipfs object get/data

* Allow object get/data to accept CID

* Var naming tweaks from review
dryajov pushed a commit that referenced this pull request Oct 2, 2017
*  support support specify hash alg

* Add test for add with --hash option. Pass raw cid/multihash to ipfs object get/data

* Allow object get/data to accept CID

* Var naming tweaks from review
daviddias pushed a commit that referenced this pull request Oct 18, 2017
* Adds wiring for a progress bar

Passes the progress bar option for tranfers over http. Progress is shown for your payload being streamed upto the server. There is a pause. Then you get your list of files.

* feat: Support specify hash algorithm in files.add (#597)

*  support support specify hash alg

* Add test for add with --hash option. Pass raw cid/multihash to ipfs object get/data

* Allow object get/data to accept CID

* Var naming tweaks from review

* feat: track progress events

* tesT: add more tests

* fix: tidy up tests

* feat: send errors as trailer headers

* fix: remove .only from tests

* feat: signal error on reponse stream if x-stream-error

* test: adding tests for trailer header errors

* chore: update interface-ipfs-core

* chore: upgrade to latest interface-ipfs-core
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants