Commit 9a48ad94fa4066ea05a9ed00590bc53f6cc14d1b
Update logging
Log query cache missescel committed on 11/26/2016, 9:00:17 PM
Parent: f31098b09f180884b2071fd151895b3053974d83
Files changed
lib/server.js | changed |
lib/server.js | ||
---|---|---|
@@ -18,8 +18,12 @@ | ||
18 | 18 … | type: q.type, |
19 | 19 … | class: q.class, |
20 | 20 … | }); |
21 | 21 … | }, |
22 … | + nonCachedQuery: function (req, q) { | |
23 … | + console.log('dns', req.connection.remoteAddress, | |
24 … | + q.name, q.class, q.type, q.serial || ''); | |
25 … | + } | |
22 | 26 … | }; |
23 | 27 … | |
24 | 28 … | function queryKey(q) { |
25 | 29 … | return q.name + ' ' + (q.class || 'IN') + ' ' + q.type + ' ' + |
@@ -30,8 +34,9 @@ | ||
30 | 34 … | this.sbot = sbot; |
31 | 35 … | this.cache = {/* name+class+type: result */}; |
32 | 36 … | this.cbs = {/* name+class+type: [callback] */}; |
33 | 37 … | opt = opt || {}; |
38 … | + this.verbose = opt.verbose === undefined || opt.verbose; | |
34 | 39 … | } |
35 | 40 … | |
36 | 41 … | CachingResolver.prototype.answer = function (req, res) { |
37 | 42 … | log.req(req, this.opt); |
@@ -50,9 +55,9 @@ | ||
50 | 55 … | if (q.type === 'IXFR') { |
51 | 56 … | q.serial = req.authority[0] && req.authority[0].data.serial || 0 |
52 | 57 … | } |
53 | 58 … | |
54 | - this.query(q, function (err, result) { | |
59 … | + this.query(q, req, function (err, result) { | |
55 | 60 … | if (err) { |
56 | 61 … | console.error(err.stack || err); |
57 | 62 … | res.responseCode = 2; // SERVFAIL |
58 | 63 … | return res.end(); |
@@ -63,23 +68,25 @@ | ||
63 | 68 … | if (!result.domainExists) { |
64 | 69 … | res.responseCode = 3; // NXDOMAIN |
65 | 70 … | } |
66 | 71 … | } |
72 … | + /* | |
67 | 73 … | if (opt && opt.verbose) { |
68 | 74 … | var recs = records.map(Format.recordToLine).join(", ") |
69 | 75 … | var auths = authorities.map(Format.recordToLine).join(", ") |
70 | 76 … | console.log("%s: %s%s", q.name, recs, |
71 | 77 … | auths ? '. auths: ' : '', auths); |
72 | 78 … | } |
79 … | + */ | |
73 | 80 … | res.question = result.questions; |
74 | 81 … | res.answer = result.answers; |
75 | 82 … | res.authority = result.authorities; |
76 | 83 … | res.additional = result.additionals; |
77 | 84 … | res.end(); |
78 | 85 … | }); |
79 | 86 … | }; |
80 | 87 … | |
81 | -CachingResolver.prototype.query = function (q, cb) { | |
88 … | +CachingResolver.prototype.query = function (q, req, cb) { | |
82 | 89 … | // TODO: cache IXFR and AXFR responses and handle their invalidation |
83 | 90 … | var key = queryKey(q); |
84 | 91 … | var result = this.cache[key]; |
85 | 92 … | if (result) { |
@@ -94,10 +101,14 @@ | ||
94 | 101 … | |
95 | 102 … | var cbs = this.cbs[key]; |
96 | 103 … | if (cbs) return cbs.push(cb); |
97 | 104 … | cbs = this.cbs[key] = [cb]; |
105 … | + | |
106 … | + if (this.verbose) { | |
107 … | + log.nonCachedQuery(req, q); | |
108 … | + } | |
109 … | + | |
98 | 110 … | var self = this; |
99 | - | |
100 | 111 … | Query.query(this.sbot, q, function (err, result) { |
101 | 112 … | if (!err && result.cache) self.cache[key] = result; |
102 | 113 … | while (cbs.length) cbs.shift()(err, result); |
103 | 114 … | delete self.cbs[key]; |
Built with git-ssb-web