small refactor

This commit is contained in:
AJ ONeal 2017-09-25 15:12:58 -06:00
parent 6d0f9b1588
commit 083df5755b
1 changed files with 102 additions and 101 deletions

View File

@ -169,20 +169,19 @@ cli.main(function (args, cli) {
}); });
} }
count = query.question.length; function recurse() {
if (!count) { if (!query.header.rd) {
console.log("[Could not answer. Sent empty response.]");
sendEmptyResponse(query); sendEmptyResponse(query);
return; return;
} }
// TODO get local answer first, if available
if (query.header.rd) {
if (cli.norecurse) { if (cli.norecurse) {
console.log("[Could not answer. Sent empty response.]"); console.log("[Could not answer. Sent empty response.]");
sendEmptyResponse(query); sendEmptyResponse(query);
return; return;
} else { }
// ANY, A, AAAA, CNAME, MX, NAPTR, NS, PTR, SOA, SRV, TXT // ANY, A, AAAA, CNAME, MX, NAPTR, NS, PTR, SOA, SRV, TXT
newQuery = { newQuery = {
header: { header: {
@ -195,14 +194,7 @@ cli.main(function (args, cli) {
, ra: 0 // NA , ra: 0 // NA
, rcode: 0 // NA , rcode: 0 // NA
} }
, question: [ , question: []
/*
{ name: cli.query
, typeName: cli.type
, className: cli.class
}
*/
]
, answer: [] , answer: []
, authority: [] , authority: []
, additional: [] , additional: []
@ -276,7 +268,16 @@ cli.main(function (args, cli) {
console.log(';' + q.name + '.', ' ', q.className, q.typeName); console.log(';' + q.name + '.', ' ', q.className, q.typeName);
}); });
} }
count = query.question.length;
if (!count) {
sendEmptyResponse(query);
return;
} }
// TODO get local answer first, if available
recurse();
}; };
handlers.onListening = function () { handlers.onListening = function () {
@ -305,7 +306,7 @@ cli.main(function (args, cli) {
console.log(''); console.log('');
if (!cli.nocmd) { if (!cli.nocmd) {
console.log('; <<>> dig.js ' + 'v0.0.0' + ' <<>> ' + process.argv.slice(2)); console.log('; <<>> digd.js ' + 'v0.0.0' + ' <<>> ' + process.argv.slice(2));
console.log(';; global options: +cmd'); console.log(';; global options: +cmd');
} }