git ssb

15+

ansuz / dnssb



Commit 9a1a3f4f34f0d606445d3664852bf91d41bc8df6

Handle incremental zone transfer

cel committed on 11/26/2016, 7:51:44 PM
Parent: 0b93188a7ae3a81dd09ed48404fb602cd84ffc05

Files changed

lib/query.jschanged
lib/server.jschanged
lib/query.jsView
@@ -154,8 +154,17 @@
154154 }
155155 return [];
156156 };
157157
158 +Wildcards.prototype.getTopRecords = function () {
159 + // get records for the shortest name length
160 + if (this.lengths.length) {
161 + var len = Math.min.apply(Math, this.lengths);
162 + return this.recordsByLength[len] || [];
163 + }
164 + return [];
165 +};
166 +
158167 function ZoneSerials() {
159168 this.serials = {};
160169 }
161170
@@ -199,8 +208,9 @@
199208
200209 var nonRecurseTypes = {
201210 CNAME: true,
202211 AXFR: true,
212 + IXFR: true,
203213 };
204214
205215 Query.query = function (sbot, question, cb) {
206216 if (nonRecurseTypes[question.type]) {
@@ -259,9 +269,11 @@
259269 // look up records that match a question, including wildcard records
260270 // and zone authority records
261271 var authorityDomains = expandName(question.name);
262272 var wildcardDomains = expandName(question.name, '*');
263- var isTransfer = question.type === 'AXFR'
273 + var isIncrementalTransfer = question.type === 'IXFR'
274 + var isTransfer = isIncrementalTransfer || question.type === 'AXFR'
275 +
264276 var authorities = new Wildcards();
265277 var answers = isTransfer ? new Records() : new Wildcards();
266278 var zoneSerials = new ZoneSerials();
267279 var result = {
@@ -270,17 +282,18 @@
270282 Pull(Query.all(sbot),
271283 Pull.filter(function (record) {
272284 var recordDomains = expandName(record.name);
273285 zoneSerials.addRecord(recordDomains);
274- var nameMatches = isTransfer
275- ? question.name in recordDomains
276- : record.name in wildcardDomains;
286 + if (isIncrementalTransfer
287 + && zoneSerials.getSerial(question.name) < question.serial) {
288 + return false
289 + }
290 + var nameMatches = isTransfer ? question.name in recordDomains :
291 + record.type === 'SOA' ? record.name in authorityDomains :
292 + record.name in wildcardDomains;
277293 if (nameMatches) {
278294 result.domainExists = true;
279295 }
280- if (record.type === 'SOA') {
281- return record.name in authorityDomains;
282- }
283296 return nameMatches
284297 && (isTransfer
285298 || question.type === record.type
286299 || question.type === '*'
@@ -310,9 +323,11 @@
310323 result.answers = answers.getRecords();
311324 result.answers.forEach(function (record) {
312325 if (record.ttl < ttl) ttl = record.ttl;
313326 });
314- result.authorities = authorities.getRecords();
327 + result.authorities = isTransfer
328 + ? authorities.getTopRecords()
329 + : authorities.getRecords();
315330 result.authorities.forEach(function (auth) {
316331 if (!auth.data.serial) {
317332 // special case: calculate a serial for the SOA
318333 auth.data.serial = zoneSerials.getSerial(auth.name);
@@ -330,11 +345,14 @@
330345 // RFC 5936, Section 2.2
331346 result.questions.push(question);
332347 // pick a SOA record to use as the bookend
333348 var soa = result.authorities.splice(0)[0];
334- result.answers = [soa].concat(result.answers.filter(function (r) {
335- return r !== soa;
336- }), [soa]);
349 + if (soa) {
350 + result.answers = [soa].concat(
351 + result.answers.filter(function (r) { return r !== soa; }),
352 + [soa]
353 + );
354 + }
337355 }
338356 cb(null, result);
339357 }));
340358 };
lib/server.jsView
@@ -21,9 +21,10 @@
2121 },
2222 };
2323
2424 function queryKey(q) {
25- return q.name + ' ' + (q.class || 'IN') + ' ' + q.type;
25 + return q.name + ' ' + (q.class || 'IN') + ' ' + q.type + ' ' +
26 + (q.serial||0);
2627 }
2728
2829 function CachingResolver(sbot) {
2930 this.sbot = sbot;
@@ -44,8 +45,12 @@
4445 res.end();
4546 return;
4647 }
4748
49 + if (q.type === 'IXFR') {
50 + q.serial = req.authority[0] && req.authority[0].data.serial || 0
51 + }
52 +
4853 this.query(q, function (err, result) {
4954 if (err) {
5055 console.error(err.stack || err);
5156 res.responseCode = 2; // SERVFAIL

Built with git-ssb-web