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

fix: add support for resolving links by name #78

Merged
merged 4 commits into from
Jul 20, 2018
Merged

Conversation

daviddias
Copy link
Member

@daviddias daviddias commented Jul 19, 2018

This is just a stab at fixing the resolve links by name on dag-pb nodes. This PR is not finished (at all) but it shows what is missing.

Short story: go-ipfs and js-ipfs historically have supported the ability to do jsipfs dag get CID/a where a is a named link in a dag-pb.

So a dag-pb node like this.

{
  Data: <some data>
  Links: [
    {
       Name: a
       Hash: b58...
       Size: 1000
    }
  ]
}

Should support resolving the link through name so that both jsipfs dag get CID/a and jsipfs dag get CID/Links/0/Hash are equivalent.

@daviddias daviddias added kind/bug A bug in existing code (including security flaws) P0 Critical: Tackled by core team ASAP exp/expert Having worked on the specific codebase is important labels Jul 19, 2018
@ipld ipld deleted a comment from codecov bot Jul 19, 2018
@codecov
Copy link

codecov bot commented Jul 19, 2018

Codecov Report

Merging #78 into master will increase coverage by 0.2%.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master     #78     +/-   ##
========================================
+ Coverage    90.6%   90.8%   +0.2%     
========================================
  Files          13      13             
  Lines         266     272      +6     
========================================
+ Hits          241     247      +6     
  Misses         25      25
Impacted Files Coverage Δ
src/resolver.js 95.65% <100%> (+0.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fda23c4...bfd2886. Read the comment docs.

@daviddias
Copy link
Member Author

@vmx can you check on this with @olizilla and @alanshaw. They are looking for this feature in for the WebUI.

@victorbjelkholm can we make sure to disable codecov comments?

@vmx
Copy link
Member

vmx commented Jul 19, 2018

@diasdavid Do you mean that I should finish this PR?

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
@alanshaw
Copy link
Member

I hope you don't mind, I made some fixes and added a test - should be good to go now.

@alanshaw alanshaw changed the title wip - fix: add support for resolving links by name fix: add support for resolving links by name Jul 19, 2018
Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

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

I did a review. If I should take this PR over (I'd prefer not to), please let me know an I'd fix those things myself.

src/resolver.js Outdated
// TODO by enabling something to resolve through link name, we are
// applying a transformation (a view) to the data, confirm if this
// is exactly what we want
values[i] = values[link.name] = {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think values[link.name] is needed here. The case is handled below.

Please also remove the "TODO".

Copy link
Member

Choose a reason for hiding this comment

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

This was already in the code base although I don't think it was working correctly:

// TODO by enabling something to resolve through link name, we are
// applying a transformation (a view) to the data, confirm if this
// is exactly what we want
values[link.name] = link.multihash

It allows you to reference links by name via Links e.g. /ipfs/QmHash/Links/myNamedLink

Copy link
Member

Choose a reason for hiding this comment

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

Got it. So this is kind of the IPFS vs. IPLD like traversal.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't know if it's really necessary to be able to /ipfs/QmHash/Links/myNamedLink as well as /ipfs/QmHash/myNamedLink but the former was already there and we're adding the latter.

Copy link
Member

Choose a reason for hiding this comment

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

/ipfs/QmHash/Links/myNamedLink is what I call IPLD-like traversal. It will then be use if you use the /ipld prefix.

src/resolver.js Outdated
@@ -74,6 +73,31 @@ exports.resolve = (binaryBlob, path, callback) => {
} else if (split[0] === 'Data') {
cb(null, { value: node.data, remainderPath: '' })
} else {
const values = {}
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment saying that this is the case of a named link? It took me a while to figure that out.

src/resolver.js Outdated
// TODO by enabling something to resolve through link name, we are
// applying a transformation (a view) to the data, confirm if this
// is exactly what we want
values[i] = values[link.name] = {
Copy link
Member

Choose a reason for hiding this comment

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

The assignment to values[i] is not needed here and I find it rather confusing.

Please remote the comments/change them to make the saying the right thing.

done()
})
})

Copy link
Member

Choose a reason for hiding this comment

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

Could you please add tests for:

  • named link and a remainder path
  • error case for non-existent named link

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
@alanshaw
Copy link
Member

Is good now @vmx? macOS tests are npm failure not test failure.

Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

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

Thanks!

Please merge it (I normally let the author merge). Please squash them up into a single commit as it is one unit of change.

@vmx
Copy link
Member

vmx commented Jul 20, 2018

@alanshaw yes it's good to be merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/expert Having worked on the specific codebase is important kind/bug A bug in existing code (including security flaws) P0 Critical: Tackled by core team ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants