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