git ssb

15+

ansuz / dnssb



Commit 65803e83971d789c2e4141ec6b4474080082c080

Return CNAME resolutions in reponses

cel committed on 11/26/2016, 6:28:42 AM
Parent: bcc9d52da022e159c9c7b9d3eeeee0c08461f6dd

Files changed

lib/query.jschanged
lib/server.jschanged
lib/query.jsView
@@ -2,8 +2,25 @@
22 var KVSet = require("kvset");
33 var Pad = require("pad-ipv6");
44 var Query = module.exports = {};
55
6 +function isRecordEqual(a, b) {
7 + return (a === b) || (a && b
8 + && a.name === b.name
9 + && a.type === b.type
10 + && a.class === b.class);
11 +}
12 +
13 +function merge(into, from) {
14 + if (from) from.filter(function (a) {
15 + return into.every(function (b) {
16 + return !isRecordEqual(a, b);
17 + })
18 + }).forEach(function (rec) {
19 + into.push(rec);
20 + });
21 +}
22 +
623 Query.branches = function (sbot, name, type, _class, cb) {
724 if (!_class) _class = "IN";
825 var branches = [];
926 Pull(Query.all(sbot),
@@ -212,7 +229,30 @@
212229 if (auth.data.ttl < ttl) ttl = auth.data.ttl;
213230 }
214231 });
215232 result.expires = Date.now() + ttl * 60e3;
233 + result.additionals = [];
234 + // resolve cnames with another query
235 + if (question.type !== 'CNAME') {
236 + var cnames = result.answers.filter(function (answer) {
237 + return answer.type === 'CNAME';
238 + });
239 + var waiting = cnames.length;
240 + if (waiting > 0) {
241 + return cnames.forEach(function (record) {
242 + Query.query(sbot, {
243 + class: question.class,
244 + type: question.type,
245 + name: record.data.replace(/\.$/, '')
246 + }, next);
247 + })
248 + function next(err, res) {
249 + if (err) return waiting = 0, cb(err)
250 + merge(result.additionals, res.answers);
251 + merge(result.authorities, res.authorities);
252 + if (!--waiting) cb(err, result);
253 + }
254 + }
255 + }
216256 cb(null, result);
217257 }));
218258 };
lib/server.jsView
@@ -65,8 +65,9 @@
6565 auths ? '. auths: ' : '', auths);
6666 }
6767 res.answer = result.answers;
6868 res.authority = result.authorities;
69 + res.additional = result.additionals;
6970 res.end();
7071 });
7172 };
7273

Built with git-ssb-web