Commit f31098b09f180884b2071fd151895b3053974d83
Pass config into server
cel committed on 11/26/2016, 9:00:17 PMParent: b6e3570cc21c40692b9e6b5806ddd1c31221bb1c
Files changed
index.js | changed |
lib/index.js | changed |
lib/server.js | changed |
index.js | ||
---|---|---|
@@ -76,14 +76,14 @@ | ||
76 | 76 … | var port = argv[1] || 53053; |
77 | 77 … | var host = argv[2] || '127.0.0.1'; |
78 | 78 … | var Client = require("ssb-client"); |
79 | 79 … | |
80 | - Client(function (err, sbot) { | |
80 … | + Client(function (err, sbot, config) { | |
81 | 81 … | if (err) throw err; |
82 | 82 … | |
83 | 83 … | Lib.server.listen(sbot, port, host, function () { |
84 | 84 … | console.log("server listening on %s:%s", host, port); |
85 | - }); | |
85 … | + }, config && config.dns); | |
86 | 86 … | }); |
87 | 87 … | }()); |
88 | 88 … | break; |
89 | 89 … | case 'publish': |
lib/index.js | ||
---|---|---|
@@ -22,6 +22,6 @@ | ||
22 | 22 … | var port = config.dns && config.dns.port || 53053; |
23 | 23 … | var host = config.dns && config.dns.host || config.host || "127.0.0.1"; |
24 | 24 … | Lib.server.listen(sbot, port, host, function () { |
25 | 25 … | console.log("%s listening on %s:%s", pkg.name, host, port); |
26 | - }); | |
26 … | + }, config.dns); | |
27 | 27 … | }; |
lib/server.js | ||
---|---|---|
@@ -25,16 +25,17 @@ | ||
25 | 25 … | return q.name + ' ' + (q.class || 'IN') + ' ' + q.type + ' ' + |
26 | 26 … | (q.serial||0); |
27 | 27 … | } |
28 | 28 … | |
29 | -function CachingResolver(sbot) { | |
29 … | +function CachingResolver(sbot, opt) { | |
30 | 30 … | this.sbot = sbot; |
31 | 31 … | this.cache = {/* name+class+type: result */}; |
32 | 32 … | this.cbs = {/* name+class+type: [callback] */}; |
33 … | + opt = opt || {}; | |
33 | 34 … | } |
34 | 35 … | |
35 | -CachingResolver.prototype.answer = function (req, res, opt) { | |
36 | - log.req(req, opt); | |
36 … | +CachingResolver.prototype.answer = function (req, res) { | |
37 … | + log.req(req, this.opt); | |
37 | 38 … | |
38 | 39 … | // one query per dns message |
39 | 40 … | var q = req.question[0]; |
40 | 41 … | |
@@ -134,15 +135,15 @@ | ||
134 | 135 … | |
135 | 136 … | var createServer = Server.create = function (sbot, port, host, cb, opt) { |
136 | 137 … | if (Net.isIPv6(host)) { host = Pad(host); } |
137 | 138 … | |
138 | - var resolver = new CachingResolver(sbot); | |
139 … | + var resolver = new CachingResolver(sbot, opt); | |
139 | 140 … | resolver.autoPurge(180e3); |
140 | 141 … | resolver.autoExpire(); |
141 | 142 … | |
142 | 143 … | var Dnsd = require("modern-dnsd"); |
143 | 144 … | var server = Dnsd.createServer(function(req, res) { |
144 | - resolver.answer(req, res, opt); | |
145 … | + resolver.answer(req, res); | |
145 | 146 … | }); |
146 | 147 … | |
147 | 148 … | server.on('error', function (msg, error, conn) { |
148 | 149 … | console.error(error.stack) |
Built with git-ssb-web