Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Add support for CIDv1 and Base32 #9

Merged
merged 6 commits into from
Sep 28, 2018
Merged

Conversation

lidel
Copy link
Member

@lidel lidel commented Aug 16, 2018

Closes #8, see it for details.

- feat: CID support, added resolver.cid
- feat: basic support for HAMD sharded directory
  - not real support, we need ipfs.resolve for that
- fix: return data from raw dag without resolv step

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
if (dagDataObj.type === 'directory' || dagDataObj.type === 'hamt-sharded-directory') {
let isDirErr = new Error('This dag node is a directory')
// store memo of last multihash so it can be used by directory
isDirErr.cid = isDirErr.fileName = cid
Copy link
Member Author

Choose a reason for hiding this comment

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

Backward compatibility: js-ipfs uses fileName field, so we are keeping it here for now.
When ipfs-http-response is released with these changes, will PR js-ipfs to switch from fileName to cid

Context: ipfs/js-ipfs#1518

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
@lidel lidel changed the title [WIP] Add support for CIDv1 and Base32 Add support for CIDv1 and Base32 Sep 13, 2018
@lidel
Copy link
Member Author

lidel commented Sep 13, 2018

@vasco-santos I switched to latest release of js-ipfs (e320884), it includes the fix for broken tests when files.add is used with cidv1 (ipfs/js-ipfs#1518).

Tests pass locally and it is ready to merge.
Please review when you have a moment.

@vasco-santos
Copy link
Member

vasco-santos commented Sep 13, 2018

Thanks for this PR @lidel

The CI is not happy and I tested it locally and I had the same tests failing 🤔
Meanwhile, I will have a look in the code

@lidel
Copy link
Member Author

lidel commented Sep 13, 2018

Indeed something is fishy, I'll look into this.

@lidel lidel changed the title Add support for CIDv1 and Base32 [WIP] Add support for CIDv1 and Base32 Sep 15, 2018
Old CIDs were invalid as noted in:
ipfs-inactive/js-ipfs-unixfs-engine#227

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
@lidel lidel changed the title [WIP] Add support for CIDv1 and Base32 Add support for CIDv1 and Base32 Sep 22, 2018
@lidel
Copy link
Member Author

lidel commented Sep 22, 2018

@vasco-santos check now, ci/jenkins/linux/10.4.1/test is all green 🍏

(I've finally found a moment to fix it: CIDs used in tests were invalid because I generated them with js-ipfs without fix from ipfs-inactive/js-ipfs-unixfs-engine#227 🤦‍♂️)

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

Thanks @lidel for the complete PR and for a general improvement on documentation. Left just a few observations before merging this.

Meanwhile I will test this with js-ipfs and service-worker-gateway

test/index.spec.js Outdated Show resolved Hide resolved
test/index.spec.js Outdated Show resolved Hide resolved
test/index.spec.js Outdated Show resolved Hide resolved
test/index.spec.js Outdated Show resolved Hide resolved
// console.log('CIDv1', filesAdded)
const retrievedFile = filesAdded[0]
expect(new CID(retrievedFile.hash)).to.deep.equal(new CID(file.cid))
// expect(retrievedFile.size, 'ipfs.files.add result size should not be smaller than input buffer').greaterThan(file.data.length)
Copy link
Member

Choose a reason for hiding this comment

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

Don't we receive the file size with CIDv1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope :) there is a bug and size is undefined – i reported it in ipfs/js-ipfs#1585
It does not impact what this lib does, data is added correctly by js-ipfs, so I commented it out for now.

test/index.spec.js Outdated Show resolved Hide resolved
License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
@vasco-santos
Copy link
Member

@lidel Now the changes look good to me, but there are some problems with the tests. I cannot have the tests running again and they are failing in the before hook, while adding files. Do you know what the problem is?

@lidel
Copy link
Member Author

lidel commented Sep 25, 2018

This PR is officially haunted 👻 I get the same issue locally as well 👀

I am quite sure it is related to ipfs-shipyard/is-ipfs#21 and changes in cids v0.5.4-v0.5.3, namely:

  • migrate to class-is for instance comparise, fixes #53 (6b6873b)

It can be fixed in yarn via:

+  "resolutions": {
+    "cids": "^0.5.5"
+  },

But for regular npm we probably need to wait for bugfix release in js-ipfs, then we will bump version here and it will solve the issue.

cids@0.5.4 now uses class-is and checks for CIDs were failing because
tests were using the old version.

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
Our Jenkins setup changed recently and `test` is ignored

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
@lidel
Copy link
Member Author

lidel commented Sep 27, 2018

@vasco-santos I switched to latest cids v0.5.5 and the issue is gone. All green again. 🤞

ps. I had to add test:node because our Jenkins no longer runs test, but expects test:*

@vasco-santos
Copy link
Member

Nice @lidel

Thanks for the PR!

@vasco-santos vasco-santos merged commit 34a2f68 into ipfs:master Sep 28, 2018
@lidel lidel deleted the feat/cidv1b32 branch September 28, 2018 15:41
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.

Add resolver support for CIDv1 and Base32
2 participants