respond without ra on timeout

This commit is contained in:
AJ ONeal 2017-10-06 16:39:57 -06:00
parent df78e13ef2
commit f945da161b
1 changed files with 17 additions and 12 deletions

View File

@ -211,7 +211,7 @@ cli.main(function (args, cli) {
}
server.send(newAb, rinfo.port, rinfo.address, function () {
console.log('[DEV] response sent (empty)');
console.log('[DEV] response sent (empty)', rinfo.port, rinfo.address);
});
}
@ -227,7 +227,7 @@ cli.main(function (args, cli) {
}
server.send(newAb, rinfo.port, rinfo.address, function () {
console.log('[DEV] response sent (local query)');
console.log('[DEV] response sent (local query)', rinfo.port, rinfo.address);
});
}
@ -275,7 +275,7 @@ cli.main(function (args, cli) {
var newAb;
count -= 1;
if (!count) {
if (count <= 0) {
try {
newAb = dnsjs.DNSPacket.write(newResponse);
} catch(e) {
@ -285,7 +285,7 @@ cli.main(function (args, cli) {
}
server.send(newAb, rinfo.port, rinfo.address, function () {
console.log('[DEV] response sent');
console.log('[DEV] response sent', rinfo.port, rinfo.address);
});
}
}
@ -295,6 +295,8 @@ cli.main(function (args, cli) {
updateCount();
}
, onMessage: function (packet) {
// yay! recursion was available after all!
newResponse.header.ra = 1;
(packet.answer||[]).forEach(function (a) {
// TODO copy each relevant property
@ -323,18 +325,21 @@ cli.main(function (args, cli) {
console.log('request sent to', res.nameserver);
}
*/
console.log('[DEV] response sent (recurse)');
console.log('[DEV] query sent (recurse)', rinfo.port, rinfo.address);
}
, onTimeout: function (res) {
console.log(";; [" + q.name + "] connection timed out; no servers could be reached");
console.log(";; [timed out after " + res.timeout + "ms and 1 tries]");
count = 1;
updateCount();
}
, onClose: function () {
console.log('');
}
, mdns: cli.mdns
, nameserver: cli.nameserver
, port: cli.port
, nameserver: cli.chosenNameserver
, port: cli.resolverPort || 53 // TOODO accept resolverPort
, timeout: cli.timeout
};
@ -346,7 +351,7 @@ cli.main(function (args, cli) {
}
count = query.question.length;
if (!count) {
if (count <= 0) {
sendEmptyResponse(query);
return;
}
@ -363,14 +368,14 @@ cli.main(function (args, cli) {
handlers.onListening = function () {
/*jshint validthis:true*/
var server = this;
var nameserver = cli.nameserver;
cli.chosenNameserver = cli.nameserver;
var index;
if (!nameserver) {
if (!cli.chosenNameserver) {
index = crypto.randomBytes(2).readUInt16BE(0) % defaultNameservers.length;
nameserver = defaultNameservers[index];
cli.chosenNameserver = defaultNameservers[index];
if (cli.debug) {
console.log(index, defaultNameservers);
console.log('index, defaultNameservers', index, defaultNameservers);
}
}