git ssb

15+

ansuz / dnssb



Commit f31098b09f180884b2071fd151895b3053974d83

Pass config into server

cel committed on 11/26/2016, 9:00:17 PM
Parent: b6e3570cc21c40692b9e6b5806ddd1c31221bb1c

Files changed

index.jschanged
lib/index.jschanged
lib/server.jschanged
index.jsView
@@ -76,14 +76,14 @@
7676 var port = argv[1] || 53053;
7777 var host = argv[2] || '127.0.0.1';
7878 var Client = require("ssb-client");
7979
80- Client(function (err, sbot) {
80 + Client(function (err, sbot, config) {
8181 if (err) throw err;
8282
8383 Lib.server.listen(sbot, port, host, function () {
8484 console.log("server listening on %s:%s", host, port);
85- });
85 + }, config && config.dns);
8686 });
8787 }());
8888 break;
8989 case 'publish':
lib/index.jsView
@@ -22,6 +22,6 @@
2222 var port = config.dns && config.dns.port || 53053;
2323 var host = config.dns && config.dns.host || config.host || "127.0.0.1";
2424 Lib.server.listen(sbot, port, host, function () {
2525 console.log("%s listening on %s:%s", pkg.name, host, port);
26- });
26 + }, config.dns);
2727 };
lib/server.jsView
@@ -25,16 +25,17 @@
2525 return q.name + ' ' + (q.class || 'IN') + ' ' + q.type + ' ' +
2626 (q.serial||0);
2727 }
2828
29-function CachingResolver(sbot) {
29 +function CachingResolver(sbot, opt) {
3030 this.sbot = sbot;
3131 this.cache = {/* name+class+type: result */};
3232 this.cbs = {/* name+class+type: [callback] */};
33 + opt = opt || {};
3334 }
3435
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);
3738
3839 // one query per dns message
3940 var q = req.question[0];
4041
@@ -134,15 +135,15 @@
134135
135136 var createServer = Server.create = function (sbot, port, host, cb, opt) {
136137 if (Net.isIPv6(host)) { host = Pad(host); }
137138
138- var resolver = new CachingResolver(sbot);
139 + var resolver = new CachingResolver(sbot, opt);
139140 resolver.autoPurge(180e3);
140141 resolver.autoExpire();
141142
142143 var Dnsd = require("modern-dnsd");
143144 var server = Dnsd.createServer(function(req, res) {
144- resolver.answer(req, res, opt);
145 + resolver.answer(req, res);
145146 });
146147
147148 server.on('error', function (msg, error, conn) {
148149 console.error(error.stack)

Built with git-ssb-web