0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

100 Commits

Author SHA1 Message Date
XadillaX
330349f706 dns: make dns.setServers support customized port
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: https://github.com/nodejs/node/pull/13723
Refs: https://github.com/nodejs/node/issues/7903
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2017-06-20 18:42:25 -04:00
Vse Mozhet Byt
390fa0380e cluster, dns, repl, tls, util: fix RegExp nits
* Take RegExp creation out of cycles.
* Use test(), not match() in boolean context.
* Remove redundant RegExp parts.

PR-URL: https://github.com/nodejs/node/pull/13536
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-06-10 13:37:04 +03:00
XadillaX
27de36926b
dns: add resolveAny support
`dns.resolveAny` and `dns.resolve` with `"ANY"` has the similar behavior
like `$ dig <domain> any` and returns an array with several types of
records.

`dns.resolveAny` parses the result packet by several rules in turn.

Supported types:

* A
* AAAA
* CNAME
* MX
* NAPTR
* NS
* PTR
* SOA
* SRV
* TXT

Fixes: https://github.com/nodejs/node/issues/2848
PR-URL: https://github.com/nodejs/node/pull/13137
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-06-09 19:09:28 +02:00
Brian White
3c989de207
dns: use faster IP address type check on results
PR-URL: https://github.com/nodejs/node/pull/13261
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-06-01 22:00:55 -04:00
Brian White
656bb71867
dns: improve callback performance
It appears that either c-ares no longer calls callbacks synchronously
or we have since explicitly taken care of the scenarios in which
c-ares would call callbacks synchronously (e.g. resolving an IP
address or an empty hostname). Therefore we no longer need to have
machinery in place to handle possible synchronous callback invocation.
This improves performance significantly.

PR-URL: https://github.com/nodejs/node/pull/13261
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-06-01 22:00:50 -04:00
Rich Trott
758a17f1d5 dns: return TypeError on invalid resolve() input
Synchronize the argument list for `dns.resolve()` with what's in the
documentation.

Improve the error for a bad `rrtype` to be a `TypeError` rather than an
`Error`.

PR-URL: https://github.com/nodejs/node/pull/13090
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-05-28 19:49:27 -07:00
Anna Henningsen
faf6654ff7
dns: support promisified lookup(Service)
PR-URL: https://github.com/nodejs/node/pull/12442
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: William Kapke <william.kapke@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2017-05-09 15:01:46 +02:00
James M Snell
98e54b0bd4 meta: restore original copyright header
A prior io.js era commit inappropriately removed the
original copyright statements from the source. This
restores those in any files still remaining from that
edit.

Ref: https://github.com/nodejs/TSC/issues/174
Ref: https://github.com/nodejs/node/pull/10599
PR-URL: https://github.com/nodejs/node/pull/10155

Note: This PR was required, reviewed-by and approved
by the Node.js Foundation Legal Committee and the TSC.
There is no `Approved-By:` meta data.
2017-03-10 11:23:48 -08:00
James M Snell
531de63c14 dns: minor refactor of dns module
Move to the more efficient module.exports = {} pattern.

PR-URL: https://github.com/nodejs/node/pull/11597
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-03-04 14:16:03 -08:00
James M Snell
e36d0d3974 dns: avoid use of arguments
PR-URL: https://github.com/nodejs/node/pull/11359
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com
2017-02-15 10:05:32 -08:00
Ben Noordhuis
c31b507b94 dns: implement {ttl: true} for dns.resolve4()
Add an option to retrieve the Time-To-Live of the A record.

PR-URL: https://github.com/nodejs/node/pull/9296
Refs: https://github.com/nodejs/node/issues/5893
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-11-18 22:01:11 +01:00
Miguel Angel Asencio Hurtado
115bb04c01 dns: name anonymous functions
Ref: https://github.com/nodejs/node/issues/8913
PR-URL: https://github.com/nodejs/node/pull/9052
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2016-10-17 09:16:05 -07:00
yorkie
7bc6aeac86 dns: remove internal variable from makeAsync
PR-URL: https://github.com/nodejs/node/pull/8800
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-09-30 10:02:39 +08:00
Luigi Pinca
575077ae12 dns: tweak regex for IPv6 addresses
The regex used in `dns.setServers()` to match IPv6 addresses in square
brackets uses a capturing group for the port but this info is not
needed.

This commit replaces the capturing group with a non capturing one.

PR-URL: https://github.com/nodejs/node/pull/8665
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2016-09-23 01:03:09 +03:00
cjihrig
b176d30a69 dns: handle array holes in setServers()
This commit adds better handling of exceptional array formats
passed to dns.setServers(). Prior to this commit, the input
array was validated using map(), which preserves holes, allowing
them to be passed to c-ares, crashing Node. This commit replaces
map() with forEach(), which skips holes.

Fixes: https://github.com/nodejs/node/issues/8538
PR-URL: https://github.com/nodejs/node/pull/8567
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-09-20 19:56:13 -04:00
cjihrig
013d76cb73 dns: remove makeAsync() function check
makeAsync() is an internal method in the dns module. All of the
functions that call makeAsync() have already validated that the
callback is a function. This commit removes a redundant typeof
function check.

PR-URL: https://github.com/nodejs/node/pull/8170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
2016-08-22 11:07:05 -07:00
cjihrig
3a43568020 dns: lookupService() callback must be a function
lookupService() requires a callback function. This commit adds
a check to verify that the callback is actually a function.

PR-URL: https://github.com/nodejs/node/pull/8170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
2016-08-22 11:07:01 -07:00
Benjamin Gruenbaum
c9c387fdac dns: Use object without protoype for map
Currently we use `{}` for the `lookup` function to find the relevant
resolver to the dns.resolve function. It is preferable to use an
object without a Object.prototype, currently for example you can do
something like:

```js
dns.resolve("google.com", "toString", console.log);
```

And get `[Object undefined]` logged and the callback would never be
called. This is unexpected and strange behavior in my opinion.
In addition, if someone adds a property to `Object.prototype` might
also create unexpected results.

This pull request fixes it, with it an appropriate error is thrown.

PR-URL: https://github.com/nodejs/node/pull/5843
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-03-22 11:13:03 -07:00
Benjamin Gruenbaum
4985c3411f dns: Refactor forEach to map
Refactor a forEach to a `map` in the `setServers` function of the
dns module - simplifying the code. In addition, use more descriptive
variable names and `const` over `var` where possible.

PR-URL: https://github.com/nodejs/node/pull/5803
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
2016-03-22 19:58:44 +02:00
Benjamin Gruenbaum
8baaa25aec dns: use template literals
Prefer the use of template string literals over string concatenation
in the dns module, makes dns consistent with other modules basically
doing https://github.com/nodejs/node/pull/5778 for it.

PR-URL: https://github.com/nodejs/node/pull/5809
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-22 11:30:57 +02:00
Benjamin Gruenbaum
b9299884dc dns: use isIp consistently
Currently the DNS module imports isIP from both cares and `net` and
uses both of them both throughout the code base. This PR removes the
direct dependency `dns` has on `net` and uses `isIp` from c-ares all
the time. Note that both functions do the same thing.

PR-URL: https://github.com/nodejs/node/pull/5804
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-21 08:50:59 -07:00
Daniel Turing
dbdbdd4998 dns: add resolvePtr to query plain DNS PTR records
Resolving plain PTR records is used beyond reverse DNS, most
prominently with DNS-SD (RFC6763). This adds dns.resolvePtr(),
and uses it (instead of dns.reverse()) in dns.resolve().

PR-URL: https://github.com/nodejs/node/pull/4921
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-02-08 17:30:38 +01:00
Evan Lucas
f3be421c1c dns: coerce port to number in lookupService
Previously, port could be any number in dns.lookupService. This change
throws a TypeError if port is outside the range of 0-65535. It also
coerces the port to a number.

PR-URL: https://github.com/nodejs/node/pull/4883
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-01 09:36:57 -08:00
Evan Lucas
0f8e63caff dns: throw a TypeError in lookupService with invalid port
Previously, port was assumed to be a number and would cause an abort in
cares_wrap. This change throws a TypeError if port is not a number
before we actually hit C++.

Fixes: https://github.com/nodejs/node/issues/4837
PR-URL: https://github.com/nodejs/node/pull/4839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-01-25 15:15:31 -06:00
Myles Borins
b619831381 meta: remove use of profanity in source
The CoC requests to avoid the casual use of profanity.

PR-URL: https://github.com/nodejs/node/pull/4122
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2015-12-02 11:05:11 -08:00
micnic
20285ad177 lib: Consistent error messages in all modules
This commit fixes some error messages that are not consistent with
some general rules which most of the error messages follow.

PR-URL: https://github.com/nodejs/node/pull/3374
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-11-09 20:08:36 +01:00
Trevor Norris
3f476ada1e async_wrap: ensure all objects have internal field
If the constructor can't assign a class id then the heap snapshot will
not be able to report the object. So ensure that all AsyncWrap instances
use a FunctionTemplate instance with an internal field count >= 1.

PR-URL: https://github.com/nodejs/node/pull/3139
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-by: Stephen Belanger <admin@stephenbelanger.com>
2015-10-01 13:56:25 -06:00
Roman Reiss
680dda8023 dns: remove nonexistant exports.ADNAME
This error code export was mistakingly introduced in a 2012 commit which
added more error codes. The correct export.BADNAME was added in
https://github.com/nodejs/node/pull/3051.

Semver: Major
PR-URL: https://github.com/nodejs/node/pull/3051
Fixes: https://github.com/nodejs/node/issues/3050
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2015-09-27 15:34:08 +02:00
Roman Reiss
24fe112ec5 dns: add missing exports.BADNAME
Adds the documented but missing DNS error exports.BADNAME. This export
has been there before but got lost in a 2012 commit that added more
error codes. https://github.com/nodejs/node/pull/3076 will remove the
wrong error code exports.ADNAME.

PR-URL: https://github.com/nodejs/node/pull/3051
Fixes: https://github.com/nodejs/node/issues/3050
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2015-09-27 13:50:03 +02:00
cjihrig
df1994fe53 Revert "dns: remove AI_V4MAPPED hint flag on FreeBSD"
This reverts commit 04bea9f9c2.

PR-URL: https://github.com/iojs/io.js/pull/1555
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-04 11:56:10 -07:00
Brian White
5abd4ac079 lib: simplify nextTick() usage
This commit removes unnecessary nextTick() closures and adds some
shared nextTick() callbacks for better re-use.

PR-URL: https://github.com/nodejs/io.js/pull/1612
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-05-25 10:14:18 -04:00
Yosuke Furukawa
19ffb5cf1c lib: fix eslint styles
PR-URL: https://github.com/iojs/io.js/pull/1539
Fixes: https://github.com/iojs/io.js/issues/1253
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-05-09 12:10:02 +09:00
Trevor Norris
10e31ba56c node: allow multiple arguments passed to nextTick
PR-URL: https://github.com/iojs/io.js/pull/1077
Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
2015-04-15 17:02:21 -06:00
Mayhem
1832743e18 lib: add missing new for errors lib/*.js
Not including `new` adds a useless frame and removes a potentially
useful frame.

PR-URL: https://github.com/iojs/io.js/pull/1246
Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-03-24 12:42:15 -07:00
Roman Reiss
633a990848 dns: allow dns.lookup() to return all addresses
This commit adds the 'all' option to dns.lookup(), allowing
all lookup results to be returned.

Semver: Minor
Fixes: https://github.com/iojs/io.js/issues/736
PR-URL: https://github.com/iojs/io.js/pull/744
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-02-06 17:18:47 -05:00
cjihrig
6ac8bdc0ab lib: reduce util.is*() usage
Many of the util.is*() methods used to check data types
simply compare against a single value or the result of
typeof. This commit replaces calls to these methods with
equivalent checks. This commit does not touch calls to the
more complex methods (isRegExp(), isDate(), etc.).

Fixes: https://github.com/iojs/io.js/issues/607
PR-URL: https://github.com/iojs/io.js/pull/647
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-31 23:47:29 -05:00
cjihrig
804e7aa9ab lib: use const to define constants
This commit replaces a number of var statements throughout
the lib code with const statements.

PR-URL: https://github.com/iojs/io.js/pull/541
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21 16:21:31 -05:00
Fedor Indutny
04bea9f9c2 dns: remove AI_V4MAPPED hint flag on FreeBSD
FreeBSD does not support V4MAPPED.

PR-URL: https://github.com/iojs/io.js/pull/332
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-13 20:36:43 +03:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00
Trevor Norris
819690fd98 src: all wraps now use actual FunctionTemplate
Instead of simply creating a new v8::Object to contain the connection
information, instantiate a new instance of a FunctionTemplate. This will
allow future improvements for debugging and performance probes.

Additionally, the "provider" argument in the ReqWrap constructor is no
longer optional.

PR-URL: https://github.com/joyent/node/pull/8110
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
Reviewed-by: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
2014-12-09 17:57:15 +01:00
Ben Noordhuis
21130c7d6f lib: turn on strict mode
Turn on strict mode for the files in the lib/ directory.  It helps
catch bugs and can have a positive effect on performance.

PR-URL: https://github.com/node-forward/node/pull/64
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-11-22 17:23:30 +01:00
Maciej Małecki
174f7d2820 dns: include host name in error message if available
This makes errors more readable and similar to FS errors, which also
include file name.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-09-16 15:32:04 +04:00
cjihrig
5086d6ef94 dns: throw if hostname is not string or falsey
Fix assertion failure from poor argument parsing logic introduced in
6ea5d16. Add tests to make sure arguments are properly parsed.

Fixes: 6ea5d16 "dns: always set variable family in lookup()"
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-08-20 13:51:09 -07:00
cjihrig
6ea5d16731 dns: always set variable family in lookup()
Regression occurred that prevented the variable "family" from being set
properly when the lookup() function's "options" parameter was passed a
number instead of an object.

Also included a sanity check by setting the default value of "family" to
a value that will not pass verification.

Fixes: e643fe4 "dns: fix GetAddrInfo assert"
Reviewed-by: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-08-08 14:50:49 -07:00
Trevor Norris
e643fe4c4b dns: fix GetAddrInfo assert
The method GetAddrInfo() is used by more than just dns.lookup(), and in
those cases a third argument isn't passed. This caused the following
check to abort:

  assert(args[3]->IsInt32());

Fixes: 4306786 "net: don't prefer IPv4 addresses during resolution"

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-08-04 18:19:45 -07:00
cjihrig
430678640c net: don't prefer IPv4 addresses during resolution
Currently the address resolution family defaults to IPv4. Instead remove
the preference and instead resolve to a family suitable for the host.

Expose the getaddrinfo flags and allow them to be passed.

Add documentation about new flags.

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-08-04 16:57:18 -07:00
Saúl Ibarra Corretgé
35b9580cd8
dns: introduce lookupService function
Uses getnameinfo to resolve an address an port into a hostname and
service.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-27 04:02:19 +04:00
Chris Dickinson
61baefce1e dns: send lookup c-ares errors to callback
Calling dns.lookup with arguments that generate an error from c-ares
previously sent those errors back to the callback. This commit restores
the ca9eb71 behavior.

Fixes #7731.

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-24 17:08:57 -07:00
Kenan Sulayman
28dbc96a6c dns: validate arguments in resolver
Mitigate C++-land assertion error, add test accordingly.

Fix #7070
2014-02-09 13:38:23 +04:00
Kenan Sulayman
abe4c34c86 dns: verify argument is valid function in resolve
Don't use argument as callback if it's not a valid callback function.
Throw a valid exception instead explaining the issue.

Adds to #7070 ("DNS — Throw meaningful error(s)").
2014-02-09 13:37:50 +04:00