Uh oh!
There was an error while loading. Please reload this page.
dns - add 'all' option to dns.lookup - #744
Conversation
There was a problem hiding this comment.
Can you do this with a for loop instead of map() for performance reasons.
There was a problem hiding this comment.
Sure, if the difference is worthwile.
bnoordhuis
commented
Feb 6, 2015
That seems reasonable.
Wrong. :-) The logic is in AfterGetAddrInfo() in src/cares_wrap.cc and probably needs to be adjusted in this PR. In a nutshell, you can tell c-ares to query for IPv4 and IPv6 by setting the address family to AF_UNSPEC (family=0 in JS.)
Not easily, I think. |
There was a problem hiding this comment.
addr.includes(':')?
EDIT: Never mind, just noticed that onlookup() does the same.
cjihrig
commented
Feb 6, 2015
@bnoordhuis why does the C++ logic need to change? It's returning the correct array based on the desired family. The JS logic is just giving all the results back instead of the first result. |
bnoordhuis
commented
Feb 6, 2015
@cjihrig Please disregard that remark. I wrote that before I realized that lib/dns.js already does an ersatz IPv6 check. |
There was a problem hiding this comment.
Can you add a test that doesn't specify the family and check for mixed results.
There was a problem hiding this comment.
You mean fail the test if mixed results are obtained?
There was a problem hiding this comment.
No. If you don't specify the family, you should be able to get all IPv4 and IPv6 addresses.
There was a problem hiding this comment.
Ah, I see what you mean:
> require("dns").lookup("www.google.com", {all: true}, console.log)
null [ { address: '188.21.9.123', family: 4 },
{ address: '188.21.9.117', family: 4 },
{ address: '188.21.9.121', family: 4 },
{ address: '188.21.9.122', family: 4 },
{ address: '188.21.9.118', family: 4 },
{ address: '188.21.9.119', family: 4 },
{ address: '188.21.9.116', family: 4 },
{ address: '188.21.9.120', family: 4 },
{ address: '2a00:1450:4014:80a::1010', family: 6 } ]
silverwind
commented
Feb 6, 2015
So, no change need there? I see that |
There was a problem hiding this comment.
This describes how the callback arguments are changed, but doesn't really describe the purpose of all. Can you add something like "Return all matching addresses when true"
bnoordhuis
commented
Feb 6, 2015
Yep, it's fine. |
silverwind
commented
Feb 6, 2015
Mixed test done. Had to fight a few other test failing, but both appear to be because of my specific dns setup. Just to note, the failing tests on OS X were:
|
There was a problem hiding this comment.
This should go before the With the all option set,... sentence.
There was a problem hiding this comment.
Yes. I think it's helpful to define the default behavior before going into what it means for all to be set.
silverwind
commented
Feb 6, 2015
All done. I restructured the docs to make more sense in the last commit. Let me know when to squash, as I'd like to fix the commit message. |
There was a problem hiding this comment.
Tiny style nit, but can you put the var here.
There was a problem hiding this comment.
Sure. Generally, I try to put var at the start of the scope, but i guess I'll follow the style of that file.
cjihrig
commented
Feb 6, 2015
There is one case that hasn't been covered - https://github.com/iojs/io.js/blob/v1.x/lib/dns.js#L130. Other than that, and the style nit, LGTM. You can squash, the commits and follow the instructions in https://github.com/iojs/io.js/blob/v1.x/CONTRIBUTING.md#step-3-commit |
silverwind
commented
Feb 6, 2015
@cjihrig honored your last suggestions and also added two more tests. do these look good to you so I can squash? |
There was a problem hiding this comment.
It doesn't matter a ton since this is a test, but I think you'd want to check for Array.isArray(ips) before checking the ips.length.
There was a problem hiding this comment.
Right, I'll reorder the type checks to be on top.
The 'all' option allows to retrieve all addresses returned by `getaddrinfo` using the system resolver. While `dns.resolve` already does return multiple results, it's often preferable to use the system resolver, like for mDNS.
f27e8af to
0a914bfComparesilverwind
commented
Feb 6, 2015
And it's squashed. |
cjihrig
commented
Feb 6, 2015
Let's see what the CI thinks. https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/154/ I'll do some testing locally too. I don't think the CI runs the internet tests. |
cjihrig
commented
Feb 6, 2015
CI seems happy - the FreeBSD and Arm failures are pretty standard. I also ran the Internet tests locally, and they passed. This is a semver minor bump, but that window is already open due to #697. |
cjihrig
commented
Feb 6, 2015
Thanks! Landed in eb30009de65a9432b59ae77a425b623df28dbd27 with a tweaked commit message. EDIT: Someone performed a force push after I landed this. So the mentioned commit was overwritten. The actual commit is now 633a990 |
micnic
commented
Feb 6, 2015
@cjihrig, oops, it was me, sorry for that, I edited a wrong commit message |
cjihrig
commented
Feb 6, 2015
@micnic no big deal. It's taken care of. |
Issue: #736
Open questions:
dns.lookup(null, {all: true}) return an empty array (returnsnullright now)?addresses. Correct?!this.familycode path?/cc @bnoordhuis