From d26b6711765a2a029ec11da568a27b114ca57b6f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 6 Oct 2017 18:31:59 -0600 Subject: [PATCH] WIP some local responses work --- bin/digd.js | 9 ++++++--- lib/dns-store.js | 6 ++++-- samples/zones.js | 7 +++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bin/digd.js b/bin/digd.js index 4fd908a..e15964d 100755 --- a/bin/digd.js +++ b/bin/digd.js @@ -257,7 +257,7 @@ cli.main(function (args, cli) { id: query.header.id // require('crypto').randomBytes(2).readUInt16BE(0) , qr: 0 , opcode: 0 - , aa: query.header.aa ? 1 : 0 // NA? not sure what this would do + , aa: 0 // query.header.aa ? 1 : 0 // NA? not sure what this would do , tc: 0 // NA , rd: 1 , ra: 0 // NA @@ -363,8 +363,11 @@ cli.main(function (args, cli) { } // TODO get local answer first, if available - require('../lib/dns-store').query(cli.input, query, function (err, resp) { - if (err) { console.log('[DEV] answer not found in local db, recursing'); recurse(); return; } + var path = require('path'); + require('../lib/dns-store').query(path.resolve(cli.input), query, function (err, resp) { + if (err) { console.log('[DEV] answer not found in local db, recursing'); console.error(err); recurse(); return; } + + if (SERVFAIL === resp.header.rcode) { console.log('[DEV] local cache miss, recursing'); recurse(); return; } sendResponse(resp); }); diff --git a/lib/dns-store.js b/lib/dns-store.js index 4df187f..8781679 100644 --- a/lib/dns-store.js +++ b/lib/dns-store.js @@ -6,7 +6,7 @@ module.exports.ask = function (query, cb) { }; */ -var SUCCESS = 0; +var NOERROR = 0; var NXDOMAIN = 3; var REFUSED = 5; @@ -182,7 +182,7 @@ module.exports.query = function (input, query, cb) { , tc: 0 , rd: query.header.rd // duh , ra: 0 // will be changed by cli.norecurse - , rcode: SUCCESS // 0 SUCCESS, 3 NXDOMAIN, 5 REFUSED + , rcode: NOERROR // 0 NOERROR, 3 NXDOMAIN, 5 REFUSED } , question: [], answer: [], authority: [], additional: [] }; @@ -193,6 +193,8 @@ module.exports.query = function (input, query, cb) { myRecords.forEach(function (r) { results.answer.push(dbToResourceRecord(r)); }); + results.header.rcode = NOERROR; + cb(null, results); return; } diff --git a/samples/zones.js b/samples/zones.js index 7953a55..ccf4042 100644 --- a/samples/zones.js +++ b/samples/zones.js @@ -1,14 +1,17 @@ 'use strict'; module.exports = { - "domain": [ + "domains": [ { "id": "daplie.me", "revokedAt": 0 } , { "id": "oneal.daplie.me", "revokedAt": 0 } , { "id": "aj.oneal.daplie.me", "revokedAt": 0 } ] , "records": [ // zone daplie.me should be able to have some records on its own - { "zone": "daplie.me", "type": "A", "domain": "www.daplie.me" + { "zone": "daplie.me", "type": "A", "domain": "daplie.me" + , "tld": "me", "sld": "daplie", "sub": "", "value": "23.228.168.108", "aname": "tardigrade.devices.daplie.me" } + + , { "zone": "daplie.me", "type": "A", "domain": "www.daplie.me" , "tld": "me", "sld": "daplie", "sub": "www", "value": "23.228.168.108", "aname": "tardigrade.devices.daplie.me" } , { "zone": "daplie.me", "type": "CNAME", "domain": "email.daplie.me"