| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Review requested:
|
Sorry, something went wrong.
|
Thanks for the reviews. My schedule got a little busy; I'll address them later this week. One thing that has occurred to me: I think I misunderstood the exact behavior of ares_set_local_ip4 and ares_set_local_ip6. I thought they set a single source address option, but it looks like they maintain separate settings for IPv4 and IPv6 and the source address used depends on the IP version of the server used at resolve time. node/deps/cares/src/ares_process.c Lines 1018 to 1037 in 4cfcaae If you wanted to set both IPv4 and v6 source addresses with the current implementation of this PR, one could do something like resolver.setLocalAddress('127.0.0.1');
resolver.setLocalAddress('::1');…but that seems a little goofy. Any suggestions for a good API? I'm thinking: resolver.setLocalAddress('127.0.0.1'); // sets IPv4, clears IPv6
resolver.setLocalAddress('::1'); // sets IPv6, clears IPv4
resolver.setLocalAddress('127.0.0.1', '::1'); // sets both
resolver.setLocalAddress(null); // clears both? or just '0.0.0.0' instead of null?
// or should we require both v4 and v6 args to avoid ambiguity when calling with a single arg? |
Sorry, something went wrong.
|
That's a good point. Borrowing from python, explicit > implicit, so maybe this? resolver.setLocalAddressIPv4('127.0.0.1')
resolver.setLocalAddressIPv6('::1')
resolver.setLocalAddressIPv4('::1') // throws
resolver.setLocalAddressIPv6('127.0.0.1') // ditto |
Sorry, something went wrong.
|
Should probably add this as dns.setLocalAddress and make Resolver inherit it so it works on both cases, like dns.setServers. Also for parity with dig, it would be nice to also have the ability to set the source port, so a host:port syntax may be appropriate. Also, I think we can call it setSource(ip, port). -b address[#port]
Set the source IP address of the query. The address must be a valid address on one of the host's
network interfaces, or "0.0.0.0" or "::". An optional port may be specified by appending "#<port>"
Why would you want to do that? a packet can only have one source address. |
Sorry, something went wrong.
|
Our handling of the differences between ipv4 and ipv6 are way too consistent across the codebase. Sometimes we use argument/option values like IPv4 and IPv6, other places we use things like udp4 and udp6. For the net.BlockList, I opted to go for an argument 'ipv4' and 'ipv6' and will be opening a PR that makes those case-insensitive. Let's standardize on that approach. resolver.setLocalAddress('127.0.0.1') // defaults to ipv4
resolver.setLocalAddress('127.0.0.1', 'ipv4')
resolver.setLocalAddress('::1', 'ipv6') |
Sorry, something went wrong.
|
I've pushed commits addressing the review comments above. On the topic of what exactly the JS API should look like, I'm not in love with the idea of calling the same method multiple times since it is ambiguous to the caller how exactly the internals handle those calls. Does the IPv6 call replace the IPv4 setting or are they managed separately? If a user only sets an IPv4 address, will they be surprised when a v6 request goes over the default interface? This could be solved in the documentation, but I think it's preferable to have an interface works without ambiguity in the first place. That's why I proposed having a call that always sets IP 4 and 6, perhaps making it mandatory to specify both so there are no surprises.
|
Sorry, something went wrong.
There's already hundrets of such possibilities in various Node.js API, having one more probably does not hurt. Users concerned about it can use Resolver but for simple use cases, global API should be compatible.
If it's not too much work, I would suggest having it available. As for API, how about .setSourceAddress('1.2.3.4')
.setSourceAddress('1.2.3.4:1234')
.setSourceAddress('1.2.3.4', '1:2:3:4::')
.setSourceAddress('1.2.3.4', '[1:2:3:4::]:1234')
.setSourceAddress('1.2.3.4:1234', '[1:2:3:4::]:1234')First argument is IPv4, second IPv6 in host:port syntax like in URLs. If any of them is falsy, ignore and don't change the source address/port. If argument is truthy and not an IP, e.g. net.isIP(ip) is 0, throw an error. I have to disagree with suggested ('127.0.0.1', 'ipv4') API, we have the ability to detect IP version (and in my example above we actually only need to validate) and not doing so puts unnecessary burden on the consumer. |
Sorry, something went wrong.
|
c-ares does not provide an API for changing the source port option after initialization, so we can't change it from an instance method — ie, we can't do .setSourceAddress('ip:port'). If source port is to be an option, it must be passed in to the Resolver constructor. |
Sorry, something went wrong.
|
Happy to omit a port option in that case as it's a rather obscure option anyways. |
Sorry, something went wrong.
|
987294a2264e9cf750ebf226cbd6c2a85c2c57e5 clarifies the API's handling of IPv4 and IPv6 source addresses. The signature is now setLocalAddress([ipv4][, ipv6]) and I've updated the docs:
Regarding making this available on the default resolver (ie dns.setLocalAddress(…)): After some investigation, it looks like doing so is not trivial. This is because dns.setServers(…) actually replaces the entire Resolver instance used as the default resolver: https://github.com/nodejs/node/blob/9ac125bd378660181529e7f1099c318345d8ab21/lib/dns.js#L268-L277 ares does not provide a way to get the current local IP configuration, so we'd have to maintain additional state regarding the local address and then make sure it is re-applied whenever the global Resolver is swapped out. It's doable, but I'd personally prefer to avoid the extra complexity. |
Sorry, something went wrong.
|
I think everything outstanding has been resolved (unless anyone still thinks the API needs some work). |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM with 2 comments (we always use error codes for new errors)
Sorry, something went wrong.
There was a problem hiding this comment.
Any reason not to do the input validation in JS?
Sorry, something went wrong.
There was a problem hiding this comment.
It would be redundant since we need to parse the strings in C land anyway and call ares_set_local_ip4/ares_set_local_ip6 as appropriate.
Sorry, something went wrong.
|
The merge commit was breaking our tools, I've rebased it against master to allow it to land cleanly. |
Sorry, something went wrong.
Codecov ReportAttention: Patch coverage is 79.59184% with 10 lines in your changes missing coverage. Please review.
@@ Coverage Diff @@
## master #34824 +/- ##
==========================================
- Coverage 88.21% 87.90% -0.31%
==========================================
Files 479 477 -2
Lines 113942 113132 -810
Branches 25649 24648 -1001
==========================================
- Hits 100509 99453 -1056
- Misses 7676 7961 +285
+ Partials 5757 5718 -39
|
Sorry, something went wrong.
Sorry, something went wrong.
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: TODO
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: #35948
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: #35948
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: #35948
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: #35948
| Back | FazBrowse Home | New Git URL |
Checklist
This allows users to specify the (local source) IP address used when a dns.Resolver instance makes DNS requests.
Closes #34818