git ssb

15+

ansuz / dnssb



Commit 9a48ad94fa4066ea05a9ed00590bc53f6cc14d1b

Update logging

Log query cache misses
cel committed on 11/26/2016, 9:00:17 PM
Parent: f31098b09f180884b2071fd151895b3053974d83

Files changed

lib/server.jschanged
lib/server.jsView
@@ -18,8 +18,12 @@
1818 type: q.type,
1919 class: q.class,
2020 });
2121 },
22 + nonCachedQuery: function (req, q) {
23 + console.log('dns', req.connection.remoteAddress,
24 + q.name, q.class, q.type, q.serial || '');
25 + }
2226 };
2327
2428 function queryKey(q) {
2529 return q.name + ' ' + (q.class || 'IN') + ' ' + q.type + ' ' +
@@ -30,8 +34,9 @@
3034 this.sbot = sbot;
3135 this.cache = {/* name+class+type: result */};
3236 this.cbs = {/* name+class+type: [callback] */};
3337 opt = opt || {};
38 + this.verbose = opt.verbose === undefined || opt.verbose;
3439 }
3540
3641 CachingResolver.prototype.answer = function (req, res) {
3742 log.req(req, this.opt);
@@ -50,9 +55,9 @@
5055 if (q.type === 'IXFR') {
5156 q.serial = req.authority[0] && req.authority[0].data.serial || 0
5257 }
5358
54- this.query(q, function (err, result) {
59 + this.query(q, req, function (err, result) {
5560 if (err) {
5661 console.error(err.stack || err);
5762 res.responseCode = 2; // SERVFAIL
5863 return res.end();
@@ -63,23 +68,25 @@
6368 if (!result.domainExists) {
6469 res.responseCode = 3; // NXDOMAIN
6570 }
6671 }
72 + /*
6773 if (opt && opt.verbose) {
6874 var recs = records.map(Format.recordToLine).join(", ")
6975 var auths = authorities.map(Format.recordToLine).join(", ")
7076 console.log("%s: %s%s", q.name, recs,
7177 auths ? '. auths: ' : '', auths);
7278 }
79 + */
7380 res.question = result.questions;
7481 res.answer = result.answers;
7582 res.authority = result.authorities;
7683 res.additional = result.additionals;
7784 res.end();
7885 });
7986 };
8087
81-CachingResolver.prototype.query = function (q, cb) {
88 +CachingResolver.prototype.query = function (q, req, cb) {
8289 // TODO: cache IXFR and AXFR responses and handle their invalidation
8390 var key = queryKey(q);
8491 var result = this.cache[key];
8592 if (result) {
@@ -94,10 +101,14 @@
94101
95102 var cbs = this.cbs[key];
96103 if (cbs) return cbs.push(cb);
97104 cbs = this.cbs[key] = [cb];
105 +
106 + if (this.verbose) {
107 + log.nonCachedQuery(req, q);
108 + }
109 +
98110 var self = this;
99-
100111 Query.query(this.sbot, q, function (err, result) {
101112 if (!err && result.cache) self.cache[key] = result;
102113 while (cbs.length) cbs.shift()(err, result);
103114 delete self.cbs[key];

Built with git-ssb-web