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

83 Commits

Author SHA1 Message Date
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
Tuğrul Topuz
bddea032b7 dns: add resolveSoa and 'SOA' rrtype
You can now query for SOA records by either passing 'SOA' to `resolve`
or by using the new `resolveSoa`
2013-12-31 14:30:40 -08:00
Alexis Campailla
9be6470b53 windows: fix dns lookup of localhost with ipv6
Removing a hack intended to shortcut the resolution of 'localhost'
but which doesn't work for ipv6.
This was introduced in 2876141c42.
However it seems that the problems that this was trying to
circumvent has gone away ages ago, when dns resolution on
Windows started relying on Win32 GetAddrInfoW, which was
probably with be2320d408.

Fixes test-net-connect-options-ipv6.js on Windows.
2013-12-19 12:44:50 +04:00
Ben Noordhuis
a2d1cbef6b dns: set hostname property on error object
Make debugging and logging easier: when a DNS lookup for a hostname
fails, set the hostname as a property on the error object.

Fixes #5393.
2013-10-16 21:56:16 +02:00
Ben Noordhuis
ceb8740a63 dns: rename domain to hostname
A follow-up commit will save the domain name on the request object but
we can't call that property 'domain' because that gets intercepted by
src/node.cc and lib/domain.js to implement the node.js feature of the
same name.

To avoid confusion, rename all variables called 'domain' to 'hostname'.
2013-10-16 21:56:16 +02:00
Ben Noordhuis
03738183c7 dns: fix c-ares error reporting regression
The test case from the previous commit exposed a regression in the way
that c-ares errors are reported to JS land.  Said regression was
introduced in commit 756b622 ("src: add multi-context support").

Fixes the following test failure:

    $ out/Release/node test/simple/test-dns-regress-6244
    util.js:675
      var errname = uv.errname(err);
                       ^
    Error: err >= 0
        at Object.exports._errnoException (util.js:675:20)
        at errnoException (dns.js:43:15)
        at Object.onresolve [as oncomplete] (dns.js:145:19)

lib/dns.js erroneously assumed that the error code was a libuv error
code when it's really a c-ares status code.  Libuv handles getaddrinfo()
style lookups (which is by far the most common type of lookup), that's
why this bug wasn't discovered earlier.
2013-09-20 09:39:14 -07:00
Ben Noordhuis
6cd7fd7d24 cares_wrap: don't set oncomplete property from c++
Don't set the oncomplete property in src/cares_wrap.cc, we can do it
just as easily in lib/dns.js.

Switch two closures to the 'function with _this_ object' model. Makes
it impossible for an overzealous closure to capture too much context
and accidentally hold on to too much memory.
2013-08-12 19:08:03 +02:00
isaacs
22c68fdc1d src: Replace macros with util functions 2013-08-01 15:08:01 -07:00
Ben Noordhuis
0330bdf519 lib: macro-ify type checks
Increases the grep factor. Makes it easier to harmonize type checks
across the code base.
2013-07-24 21:49:35 +02:00
Ben Noordhuis
ca9eb718fb src, lib: update after internal api change
Libuv now returns errors directly.  Make everything in src/ and lib/
follow suit.

The changes to lib/ are not strictly necessary but they remove the need
for the abominations that are process._errno and node::SetErrno().
2013-07-20 12:09:29 +02:00
Ben Noordhuis
0161ec87af src, lib: deduplicate errnoException 2013-07-20 12:04:35 +02:00
Timothy J Fontaine
8886c6bf62 dns: add getServers and setServers
getServers returns an array of ips that are currently being used for
resolution

setServers takes an array of ips that are to be used for resolution,
this will throw if there's invalid input but preserve the original
configuration
2013-05-14 14:15:24 -07:00
Pavel Lang
2ad98725d6 DNS: Support NAPTR queries
They were previously removed in a90bc78534.
2013-03-06 14:31:22 +04:00
Xidorn Quan
009ba02e18 dns: fix ReferenceError in resolve() error path
A typo in the variable name makes it throw a ReferenceError instead of
the expected "Unknown type" error when dns.resolve() is passed a bad
record type argument.

Fixes the following exception:

  ReferenceError: type is not defined
    at Object.exports.resolve (dns.js:189:40)
    at /Users/bnoordhuis/src/master/test/simple/test-c-ares.js:48:9
    <snip>
2013-03-04 16:20:40 +01:00
Ben Noordhuis
12d0f0bd3a lib, src: remove errno global
Remove the errno global. It's a property on the process object now.

Fixes #3095.
2013-02-28 23:11:47 +01:00
Dan Milon
7295bb9435 dns: make error message match errno 2013-01-18 12:13:32 +01:00
isaacs
a90bc78534 Revert "DNS: Support NAPTR queries"
This reverts commit 91bf18fcc5.
2012-06-16 11:02:49 -07:00
ssuda
91bf18fcc5 DNS: Support NAPTR queries
Adding support for NAPTR records
fixes #3170
2012-06-16 10:56:49 -07:00