-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dns: make dns.setServers
support customized port
#13723
Conversation
Make `dns.setServers` parameter may be strings contain IP and port which split by `:`. eg. ``` dns.setServers([ "103.238.225.181:666" ]); ``` And `dns.getServers` will return IP with port if that server is not use default port. Refs: nodejs#7903
dns.setServers
support customized portdns.setServers
support customized port
@addaleax I think we can remove in progress label now. |
Maybe it's better to have the port as a separate argument so the user doesn't have to fiddle with the |
E.g.: dns.setServers([
{address: '1.2.3.4', port: 5353},
{address: '::1234:5678', port: 5353},
'2.3.4.5'
]); So the method could both take a object or a string. It also has the benefit that we could extend these objects with future per-server options if necessary. |
@silverwind You mean let the function support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a little carried away with style suggestion... 🙄
doc/api/dns.md
Outdated
@@ -59,8 +59,20 @@ the [Implementation considerations section][] for more information. | |||
added: v0.11.3 | |||
--> | |||
|
|||
Returns an array of IP address strings that are being used for name | |||
resolution. | |||
Returns an array of IP address and port strings that are being used for name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚲 🎪 Suggestion:
Returns an array of IP address strings, formatted according to [rfc3986][],
that are currently configured for DNS resolution. A string will include a port section
if a custom port is used.
...
[rfc3986]: https://tools.ietf.org/html/rfc3986#section-3.2.2
doc/api/dns.md
Outdated
@@ -484,10 +496,20 @@ added: v0.11.3 | |||
--> | |||
- `servers` {string[]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `servers` {string[]} array of [rfc3986][] formatted addresses
doc/api/dns.md
Outdated
@@ -484,10 +496,20 @@ added: v0.11.3 | |||
--> | |||
- `servers` {string[]} | |||
|
|||
Sets the IP addresses of the servers to be used when resolving. The `servers` | |||
argument is an array of IPv4 or IPv6 addresses. | |||
Sets the IP addresses and port of the servers to be used when resolving. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sets the IP address and port of servers to be used when performing DNS
resolution. If the port is the IANA default DNS port (53) it can be omitted.
lib/dns.js
Outdated
if (!val[1] || val[1] === 53) return val[0]; | ||
|
||
const ipVersion = isIP(val[0]); | ||
return ipVersion === 6 ? `[${val[0]}]:${val[1]}` : `${val[0]}:${val[1]}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal preference nit:
const host= 6 ? `[${val[0]}]` : val[0];
return ${host}:${val[1]};
lib/dns.js
Outdated
if (ipVersion !== 0) | ||
return newSet.push([ipVersion, match[1]]); | ||
if (ipVersion !== 0) { | ||
const portMatch = serv.match(addrSplitRE) || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personal style nit:
const addrSplitRE = /(^.+?)(?::(\d+))?$/;
const port = parseInt(serv.replace(addrSplitRE, '$2')) || 53;
return newSet.push([ipVersion, match[1], port);
lib/dns.js
Outdated
if (ipVersion !== 0) { | ||
const portMatch = serv.match(addrSplitRE) || []; | ||
return newSet.push([ipVersion, match[1], parseInt(portMatch[1] || 53)]); | ||
} | ||
} | ||
|
||
const s = serv.split(addrSplitRE)[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [, s, p] = serv.match(addrSplitRE);
🤔 If I understand correctly |
@refack Yes you understood right. Refer here https://nodejs.org/docs/v8.0.0/api/dns.html#dns_dns_setservers_servers.
And the |
Hmm, right the docs even mention "If a port is specified on the address, it will be removed.", so I guess we're stuck with the syntax. And no, I wouldn't support three cases. Strictly speaking, this should be semver-major, but if CITGM turns out okay (which I expect), than minor is okay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code 💯
LGTM % semver
discussion
I think after this PR is landed, we can start the test for |
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/880/ @addaleax @nodejs/ctc PTAL at semver level |
lib/dns.js
Outdated
return cares.getServers(); | ||
const ret = cares.getServers(); | ||
return ret.map((val) => { | ||
if (!val[1] || val[1] === 53) return val[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed this, IMHO we should format IPv6 with []
, so need to move the const host
up:
e.g.
return ret.map(([host, port]) => {
if (isIP(host) === 6) host = `[${host}]`;
return (!port || port === 53) host : `${host}:${port}`;
}
But that will make this semver-major
(since till now IPv6 would be represented without []
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix this in a future PR.
Ref: #13795
Need to think about semver-level, and IPv6 string format
@refack how about adding a parameter to indicate whether using customized port or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as semver-minor
CITGM is clean. |
doc/api/dns.md
Outdated
```js | ||
[ | ||
'4.4.4.4', | ||
'[2001:4860:4860::8888]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove []
for this line.
Ref: #13795
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be changed, since currently the output will be without the []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> dns.setServers(['192.168.1.1', '2001:4860:4860::8888'])
undefined
> dns.getServers()
[ '192.168.1.1', '2001:4860:4860::8888' ]
lib/dns.js
Outdated
return cares.getServers(); | ||
const ret = cares.getServers(); | ||
return ret.map((val) => { | ||
if (!val[1] || val[1] === 53) return val[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix this in a future PR.
Ref: #13795
Land this as SEMVER-MINOR? And what formatting for SEMVER-MAJOR? |
Landed in 330349f |
Extra sanity on |
allow `dns.setServers` parameter to contain port e.g. ``` dns.setServers([ '103.238.225.181:666' ]); ``` And `dns.getServers` will return IP with port if not the default port. PR-URL: #13723 Refs: #7903 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`23d41f3118`](2abaa86ba8)] [#13466](#13466) * **DNS** * The server used for DNS queries can now use a custom port. [[`2bb6614904`](8506acc1b5)] [#13723](#13723) * **V8** * The V8 engine has been upgraded to version 5.9, which has a significantly changed performance profile. [#13515](#13515) PR-URL: #13744
allow `dns.setServers` parameter to contain port e.g. ``` dns.setServers([ '103.238.225.181:666' ]); ``` And `dns.getServers` will return IP with port if not the default port. PR-URL: #13723 Refs: #7903 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`23d41f3118`](2abaa86ba8)] [#13466](#13466) * **DNS** * The server used for DNS queries can now use a custom port. [[`2bb6614904`](8506acc1b5)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`30bc9dc20f`](30bc9dc20f)] [#13137](#13137) * **V8** * The V8 engine has been upgraded to version 5.9, which has a significantly changed performance profile. [#13515](#13515) PR-URL: #13744
allow `dns.setServers` parameter to contain port e.g. ``` dns.setServers([ '103.238.225.181:666' ]); ``` And `dns.getServers` will return IP with port if not the default port. PR-URL: #13723 Refs: #7903 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`23d41f3118`](2abaa86ba8)] [#13466](#13466) * **DNS** * The server used for DNS queries can now use a custom port. [[`2bb6614904`](8506acc1b5)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`30bc9dc20f`](30bc9dc20f)] [#13137](#13137) * **V8** * The V8 engine has been upgraded to version 5.9, which has a significantly changed performance profile. [#13515](#13515) PR-URL: #13744
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`23d41f3118`](2abaa86ba8)] [#13466](#13466) * **DNS** * The server used for DNS queries can now use a custom port. [[`2bb6614904`](8506acc1b5)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`30bc9dc20f`](30bc9dc20f)] [#13137](#13137) * **V8** * The V8 engine has been upgraded to version 5.9, which has a significantly changed performance profile. [#13515](#13515) PR-URL: #13744
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`23d41f3118`](2abaa86ba8)] [#13466](#13466) * **DNS** * The server used for DNS queries can now use a custom port. [[`2bb6614904`](8506acc1b5)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`30bc9dc20f`](30bc9dc20f)] [#13137](#13137) * **V8** * The V8 engine has been upgraded to version 5.9, which has a significantly changed performance profile. [#13515](#13515) PR-URL: #13744
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`23d41f3118`](2abaa86ba8)] [#13466](#13466) * **DNS** * The server used for DNS queries can now use a custom port. [[`2bb6614904`](8506acc1b5)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`30bc9dc20f`](30bc9dc20f)] [#13137](#13137) * **V8** * The V8 engine has been upgraded to version 5.9, which has a significantly changed performance profile. [#13515](#13515) PR-URL: #13744
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`23d41f3118`](2abaa86ba8)] [#13466](#13466) * **DNS** * The server used for DNS queries can now use a custom port. [[`2bb6614904`](8506acc1b5)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`30bc9dc20f`](30bc9dc20f)] [#13137](#13137) * **V8** * The V8 engine has been upgraded to version 5.9, which has a significantly changed performance profile. [#13515](#13515) PR-URL: #13744
allow `dns.setServers` parameter to contain port e.g. ``` dns.setServers([ '103.238.225.181:666' ]); ``` And `dns.getServers` will return IP with port if not the default port. PR-URL: #13723 Refs: #7903 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`23d41f3118`](2abaa86ba8)] [#13466](#13466) * **DNS** * The server used for DNS queries can now use a custom port. [[`2bb6614904`](8506acc1b5)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`30bc9dc20f`](30bc9dc20f)] [#13137](#13137) * **V8** * The V8 engine has been upgraded to version 5.9, which has a significantly changed performance profile. [#13515](#13515) PR-URL: #13744
allow `dns.setServers` parameter to contain port e.g. ``` dns.setServers([ '103.238.225.181:666' ]); ``` And `dns.getServers` will return IP with port if not the default port. PR-URL: #13723 Refs: #7903 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`820b011ed6`](820b011ed6)] [#13466](#13466) * **Cluster** * Users now have more fine-grained control over the inspector port used by individual cluster workers. Previously, cluster workers would simply increment from the master's debug port. [[`dfc46e262a`](dfc46e262a)] [#14140](#14140) * **DNS** * The server used for DNS queries can now use a custom port. [[`ebe7bb29aa`](ebe7bb29aa)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`6e30e2558e`](6e30e2558e)] [#13137](#13137) * **npm** * The `npm` CLI has been updated to version 5.3.0. In particular, it now comes with the `npx` binary, which is also shipped with Node. [[`dc3f6b9ac1`](dc3f6b9ac1)] [#14235](#14235) * `npm` Changelogs: - [v5.0.4](https://github.com/npm/npm/releases/tag/v5.0.4) - [v5.1.0](https://github.com/npm/npm/releases/tag/v5.1.0) - [v5.2.0](https://github.com/npm/npm/releases/tag/v5.2.0) - [v5.3.0](https://github.com/npm/npm/releases/tag/v5.3.0) PR-URL: #13744
Big thanks to @addaleax who prepared the vast majority of this release. Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`820b011ed6`](nodejs@820b011ed6)] [nodejs#13466](nodejs#13466) * **Cluster** * Users now have more fine-grained control over the inspector port used by individual cluster workers. Previously, cluster workers would simply increment from the master's debug port. [[`dfc46e262a`](nodejs@dfc46e262a)] [nodejs#14140](nodejs#14140) * **DNS** * The server used for DNS queries can now use a custom port. [[`ebe7bb29aa`](nodejs@ebe7bb29aa)] [nodejs#13723](nodejs#13723) * Support for `dns.resolveAny()` has been added. [[`6e30e2558e`](nodejs@6e30e2558e)] [nodejs#13137](nodejs#13137) * **npm** * The `npm` CLI has been updated to version 5.3.0. In particular, it now comes with the `npx` binary, which is also shipped with Node. [[`dc3f6b9ac1`](nodejs@dc3f6b9ac1)] [nodejs#14235](nodejs#14235) * `npm` Changelogs: - [v5.0.4](https://github.com/npm/npm/releases/tag/v5.0.4) - [v5.1.0](https://github.com/npm/npm/releases/tag/v5.1.0) - [v5.2.0](https://github.com/npm/npm/releases/tag/v5.2.0) - [v5.3.0](https://github.com/npm/npm/releases/tag/v5.3.0) PR-URL: nodejs#13744
Big thanks to @addaleax who prepared the vast majority of this release. Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`820b011ed6`](820b011ed6)] [#13466](#13466) * **Cluster** * Users now have more fine-grained control over the inspector port used by individual cluster workers. Previously, cluster workers would simply increment from the master's debug port. [[`dfc46e262a`](dfc46e262a)] [#14140](#14140) * **DNS** * The server used for DNS queries can now use a custom port. [[`ebe7bb29aa`](ebe7bb29aa)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`6e30e2558e`](6e30e2558e)] [#13137](#13137) * **npm** * The `npm` CLI has been updated to version 5.3.0. In particular, it now comes with the `npx` binary, which is also shipped with Node. [[`dc3f6b9ac1`](dc3f6b9ac1)] [#14235](#14235) * `npm` Changelogs: - [v5.0.4](https://github.com/npm/npm/releases/tag/v5.0.4) - [v5.1.0](https://github.com/npm/npm/releases/tag/v5.1.0) - [v5.2.0](https://github.com/npm/npm/releases/tag/v5.2.0) - [v5.3.0](https://github.com/npm/npm/releases/tag/v5.3.0) PR-URL: #13744
Big thanks to @addaleax who prepared the vast majority of this release. Notable changes: * **Async Hooks** * Multiple improvements to Promise support in `async_hooks` have been made. * **Build** * The compiler version requirement to build Node with GCC has been raised to GCC 4.9.4. [[`820b011ed6`](820b011ed6)] [#13466](#13466) * **Cluster** * Users now have more fine-grained control over the inspector port used by individual cluster workers. Previously, cluster workers would simply increment from the master's debug port. [[`dfc46e262a`](dfc46e262a)] [#14140](#14140) * **DNS** * The server used for DNS queries can now use a custom port. [[`ebe7bb29aa`](ebe7bb29aa)] [#13723](#13723) * Support for `dns.resolveAny()` has been added. [[`6e30e2558e`](6e30e2558e)] [#13137](#13137) * **npm** * The `npm` CLI has been updated to version 5.3.0. In particular, it now comes with the `npx` binary, which is also shipped with Node. [[`dc3f6b9ac1`](dc3f6b9ac1)] [#14235](#14235) * `npm` Changelogs: - [v5.0.4](https://github.com/npm/npm/releases/tag/v5.0.4) - [v5.1.0](https://github.com/npm/npm/releases/tag/v5.1.0) - [v5.2.0](https://github.com/npm/npm/releases/tag/v5.2.0) - [v5.3.0](https://github.com/npm/npm/releases/tag/v5.3.0) PR-URL: #13744
Release team decided not to land on v6.x, if you disagree let us know. |
Make
dns.setServers
parameter may be strings contain IP and port whichsplit by
:
.eg.
And
dns.getServers
will return IP with port if that server is not usedefault port.
Refs: #7903
Checklist
make -j4 test
(UNIX)Affected core subsystem(s)
dns