'dns' no longer uses Promise
This commit is contained in:
parent
d0f2d465aa
commit
c04b679e12
70
doc/api.txt
70
doc/api.txt
@ -1590,85 +1590,84 @@ resolves the IP addresses which are returned.
|
||||
var dns = require("dns"),
|
||||
sys = require("sys");
|
||||
|
||||
var resolution = dns.resolve4("www.google.com");
|
||||
dns.resolve4("www.google.com", function (err, addresses, ttl, cname) {
|
||||
if (err) throw err;
|
||||
|
||||
resolution.addCallback(function (addresses, ttl, cname) {
|
||||
sys.puts("addresses: " + JSON.stringify(addresses));
|
||||
sys.puts("ttl: " + JSON.stringify(ttl));
|
||||
sys.puts("cname: " + JSON.stringify(cname));
|
||||
|
||||
for (var i = 0; i < addresses.length; i++) {
|
||||
var a = addresses[i];
|
||||
var reversing = dns.reverse(a);
|
||||
reversing.addCallback( function (domains, ttl, cname) {
|
||||
sys.puts("reverse for " + a + ": " + JSON.stringify(domains));
|
||||
});
|
||||
reversing.addErrback( function (e) {
|
||||
puts("reverse for " + a + " failed: " + e.message);
|
||||
dns.reverse(a, function (err, domains, ttl, cname) {
|
||||
if (err) {
|
||||
puts("reverse for " + a + " failed: " + e.message);
|
||||
} else {
|
||||
sys.puts("reverse for " + a + ": " + JSON.stringify(domains));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
resolution.addErrback(function (e) {
|
||||
puts("error: " + e.message);
|
||||
});
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
+dns.resolve(domain, rrtype = 'A')+::
|
||||
+dns.resolve(domain, rrtype = 'A', callback)+::
|
||||
|
||||
Resolves a domain (e.g. +"google.com"+) into an array of the record types
|
||||
specified by rrtype. Valid rrtypes are +A+ (IPV4 addresses), +AAAA+ (IPV6
|
||||
addresses), +MX+ (mail exchange records), +TXT+ (text records), +SRV+
|
||||
(SRV records), and +PTR+ (used for reverse IP lookups).
|
||||
This function returns a promise.
|
||||
- on success: returns +addresses, ttl, cname+. +ttl+ (time-to-live) is an integer
|
||||
specifying the number of seconds this result is valid for. +cname+ is the
|
||||
canonical name for the query.
|
||||
The type of each item in +addresses+ is determined by the record type, and
|
||||
described in the documentation for the corresponding lookup methods below.
|
||||
- on error: Returns an instanceof Error object, where the "errno" field is one
|
||||
of the error codes listed below and the "message" field is a string
|
||||
describing the error in English.
|
||||
+
|
||||
The callback has arguments +(err, addresses, ttl, cname)+. +ttl+
|
||||
(time-to-live) is an integer specifying the number of seconds this result is
|
||||
valid for. +cname+ is the canonical name for the query. The type of each
|
||||
item in +addresses+ is determined by the record type, and
|
||||
described in the documentation for the corresponding lookup methods below.
|
||||
+
|
||||
On error, +err+ would be an instanceof +Error+ object, where +err.errno+ is
|
||||
one of the error codes listed below and +err.message+ is a string describing
|
||||
the error in English.
|
||||
|
||||
+dns.resolve4(domain)+::
|
||||
|
||||
+dns.resolve4(domain, callback)+::
|
||||
|
||||
The same as +dns.resolve()+, but only for IPv4 queries (+A+ records).
|
||||
+addresses+ is an array of IPv4 addresses (e.g. +["74.125.79.104",
|
||||
"74.125.79.105", "74.125.79.106"]+).
|
||||
|
||||
+dns.resolve6(domain)+::
|
||||
+dns.resolve6(domain, callback)+::
|
||||
|
||||
The same as +dns.resolve4()+ except for IPv6 queries (an +AAAA+ query).
|
||||
|
||||
+dns.resolveMx(domain)+::
|
||||
|
||||
+dns.resolveMx(domain, callback)+::
|
||||
|
||||
The same as +dns.resolve()+, but only for mail exchange queries (+MX+ records).
|
||||
+addresses+ is an array of MX records, each with a priority and an exchange
|
||||
attribute (e.g. +[{"priority": 10, "exchange": "mx.example.com"},...]+).
|
||||
|
||||
+dns.resolveTxt(domain)+::
|
||||
+dns.resolveTxt(domain, callback)+::
|
||||
|
||||
The same as +dns.resolve()+, but only for text queries (+TXT+ records).
|
||||
+addresses+ is an array of the text records available for +domain+ (e.g.,
|
||||
+["v=spf1 ip4:0.0.0.0 ~all"]+).
|
||||
|
||||
+dns.resolveSrv(domain)+::
|
||||
+dns.resolveSrv(domain, callback)+::
|
||||
|
||||
The same as +dns.resolve()+, but only for service records (+SRV+ records).
|
||||
+addresses+ is an array of the SRV records available for +domain+. Properties
|
||||
of SRV records are priority, weight, port, and name (e.g., +[{"priority": 10,
|
||||
{"weight": 5, "port": 21223, "name": "service.example.com"}, ...]+).
|
||||
|
||||
+dns.reverse(ip)+::
|
||||
+dns.reverse(ip, callback)+::
|
||||
|
||||
Reverse resolves an ip address to an array of domain names.
|
||||
|
||||
- on success: returns +domains, ttl, cname+. +ttl+ (time-to-live) is an integer
|
||||
specifying the number of seconds this result is valid for. +cname+ is the
|
||||
canonical name for the query. +domains+ is an array of domains.
|
||||
- on error: Returns an instanceof Error object, where the "errno" field is one
|
||||
of the error codes listed below and the "message" field is a string
|
||||
describing the error in English.
|
||||
+
|
||||
The callback has arguments +(err, domains, ttl, cname)+. +ttl+ (time-to-live) is an integer
|
||||
specifying the number of seconds this result is valid for. +cname+ is the
|
||||
canonical name for the query. +domains+ is an array of domains.
|
||||
+
|
||||
If there an an error, +err+ will be non-null and an instanceof the Error
|
||||
object.
|
||||
|
||||
|
||||
Each DNS query can return an error code.
|
||||
@ -1680,6 +1679,7 @@ Each DNS query can return an error code.
|
||||
- +dns.NOMEM+: out of memory while processing.
|
||||
- +dns.BADQUERY+: the query is malformed.
|
||||
|
||||
|
||||
== Assert Module
|
||||
|
||||
This module is used for writing unit tests for your applications, you can access it with +require("assert")+.
|
||||
|
66
lib/dns.js
66
lib/dns.js
@ -1,62 +1,30 @@
|
||||
var events = require('events');
|
||||
|
||||
function callback (promise) {
|
||||
return function () {
|
||||
if (arguments[0] instanceof Error) {
|
||||
promise.emitError.apply(promise, arguments);
|
||||
} else {
|
||||
promise.emitSuccess.apply(promise, arguments);
|
||||
}
|
||||
exports.resolve = function (domain, type_, callback_) {
|
||||
var type, callback;
|
||||
if (typeof(type_) == 'string') {
|
||||
type = type_;
|
||||
callback = callback_;
|
||||
} else {
|
||||
type = 'A';
|
||||
callback = arguments[1];
|
||||
}
|
||||
}
|
||||
|
||||
exports.resolve = function (domain, type) {
|
||||
type = (type || 'a').toUpperCase();
|
||||
|
||||
var resolveFunc = resolveMap[type];
|
||||
|
||||
if (typeof(resolveFunc) == 'function') {
|
||||
return resolveFunc(domain);
|
||||
resolveFunc(domain, callback);
|
||||
} else {
|
||||
return undefined;
|
||||
throw new Error('Unknown type "' + type + '"');
|
||||
}
|
||||
}
|
||||
|
||||
exports.resolve4 = function (domain) {
|
||||
var promise = new events.Promise();
|
||||
process.dns.resolve4(domain, callback(promise));
|
||||
return promise;
|
||||
};
|
||||
|
||||
exports.resolve6 = function (domain) {
|
||||
var promise = new events.Promise();
|
||||
process.dns.resolve6(domain, callback(promise));
|
||||
return promise;
|
||||
};
|
||||
|
||||
exports.resolveMx = function (domain) {
|
||||
var promise = new process.Promise();
|
||||
process.dns.resolveMx(domain, callback(promise));
|
||||
return promise;
|
||||
};
|
||||
|
||||
exports.resolveTxt = function (domain) {
|
||||
var promise = new process.Promise();
|
||||
process.dns.resolveTxt(domain, callback(promise));
|
||||
return promise;
|
||||
};
|
||||
|
||||
exports.resolveSrv = function (domain) {
|
||||
var promise = new process.Promise();
|
||||
process.dns.resolveSrv(domain, callback(promise));
|
||||
return promise;
|
||||
}
|
||||
|
||||
exports.reverse = function (ip) {
|
||||
var promise = new events.Promise();
|
||||
process.dns.reverse(ip, callback(promise));
|
||||
return promise;
|
||||
};
|
||||
exports.resolve4 = process.dns.resolve4;
|
||||
exports.resolve6 = process.dns.resolve6;
|
||||
exports.resolveMx = process.dns.resolveMx;
|
||||
exports.resolveTxt = process.dns.resolveTxt;
|
||||
exports.resolveSrv = process.dns.resolveSrv;
|
||||
exports.reverse = process.dns.reverse;
|
||||
|
||||
// ERROR CODES
|
||||
|
||||
@ -78,7 +46,7 @@ exports.NOMEM = process.dns.NOMEM;
|
||||
// the query is malformed.
|
||||
exports.BADQUERY = process.dns.BADQUERY;
|
||||
|
||||
resolveMap = {
|
||||
var resolveMap = {
|
||||
'A': exports.resolve4,
|
||||
'AAAA': exports.resolve6,
|
||||
'MX': exports.resolveMx,
|
||||
|
Loading…
x
Reference in New Issue
Block a user