Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

feat: recursive dnslink lookups #1935

Merged
merged 6 commits into from
Apr 8, 2019
Merged

Conversation

niinpatel
Copy link
Contributor

@niinpatel niinpatel commented Mar 14, 2019

fixes #1931 .

Also, incorporated the suggestions from https://github.com/ipfs/interface-js-ipfs-core/issues/377 that ipfs dns should be recursive by default.

@niinpatel niinpatel force-pushed the feat/recursive-dns branch 9 times, most recently from 40fc330 to 5948037 Compare March 15, 2019 18:41
@niinpatel niinpatel changed the title feat: recursive dnslink lookups [WIP] feat: recursive dnslink lookups Mar 15, 2019
@niinpatel niinpatel marked this pull request as ready for review March 15, 2019 20:52
@niinpatel niinpatel force-pushed the feat/recursive-dns branch 6 times, most recently from e81b89f to 805dc4f Compare March 16, 2019 01:19
@niinpatel niinpatel changed the title [WIP] feat: recursive dnslink lookups feat: recursive dnslink lookups Mar 16, 2019
@niinpatel niinpatel force-pushed the feat/recursive-dns branch 3 times, most recently from 4e3316f to 2ec8b2a Compare March 16, 2019 09:16
@niinpatel
Copy link
Contributor Author

niinpatel commented Mar 16, 2019

Here's the quick demo of this feature working on the cli. I've included tests to make sure it works all other places like http-api, browsers, etc.

ipfs dns demo

@niinpatel
Copy link
Contributor Author

@alanshaw can you review this one when you can?

@niinpatel niinpatel force-pushed the feat/recursive-dns branch 5 times, most recently from 1d87bb0 to 19e001a Compare March 21, 2019 19:31
@alanshaw
Copy link
Member

Thanks @niinpatel - I will look at this as soon as I get a moment!

@niinpatel
Copy link
Contributor Author

@alanshaw did you get a chance to check it out?

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

Awesome work @niinpatel 🚀

src/cli/commands/dns.js Outdated Show resolved Hide resolved
module.exports = (domain, opts, callback) => {
resolveDnslink(domain)
// recursive is true by default, it's set to false only if explicitly passed as argument in opts
const recursive = opts.recursive === undefined || opts.recursive.toString() === 'true'
Copy link
Member

Choose a reason for hiding this comment

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

Default true for null/undefined and boolean value of argument otherwise:

Suggested change
const recursive = opts.recursive === undefined || opts.recursive.toString() === 'true'
const recursive = opts.recursive == null ? true : Boolean(opts.recursive)

Copy link
Contributor Author

@niinpatel niinpatel Apr 4, 2019

Choose a reason for hiding this comment

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

Boolean("false") actually returns true not false. Arguments passed via query parameters are of string type and we need to parse those too. Once easy solution I just now came up with is this:

const recursive = opts.recursive.toString() !== 'false'

If recursive is false or "false" then only we parse it as false. true when passed anything else, including null and undefined

Copy link
Contributor Author

@niinpatel niinpatel Apr 4, 2019

Choose a reason for hiding this comment

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

Edit: That wouldn't work either because error will be thrown if opts.recursive is undefined.

The original one is probably the best solution after all, with slight modifications:

const recursive = opts.recursive == null || opts.recursive.toString() !== 'false'

Copy link
Member

@alanshaw alanshaw Apr 5, 2019

Choose a reason for hiding this comment

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

Arguments passed via query parameters are of string type and we need to parse those too

It should be passed as a boolean - this is the documented type for the value. If a string is being passed then we need to fix our HTTP endpoint to properly parse query strings to the expected types for the calls to core.

We can't guarantee the passed value is a boolean but we can ensure that the value is a boolean for the rest of our code.

Copy link
Contributor Author

@niinpatel niinpatel Apr 5, 2019

Choose a reason for hiding this comment

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

That makes sense. Right now, I don't think query parameters are being parsed and "type-casted" before passing to the core API. For this PR, I've just now add it here:

// query parameters are passed as strings and need to be parsed to expected type
let recursive = request.query.recursive || request.query.r
recursive = !(recursive && recursive === 'false')
const path = await request.server.app.ipfs.dns(domain, { recursive, format })

src/core/runtime/dns-nodejs.js Outdated Show resolved Hide resolved
test/core/dns.spec.js Outdated Show resolved Hide resolved
@niinpatel
Copy link
Contributor Author

I've applied all the suggested changes.

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @niinpatel ❤️

@alanshaw alanshaw merged commit d5a1b89 into ipfs:master Apr 8, 2019
@niinpatel niinpatel deleted the feat/recursive-dns branch April 8, 2019 16:55
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.

ipfs.dns does not have "recursive" option
2 participants