git ssb

15+

ansuz / dnssb



Commit 7d425ca6a31dffd00aa499e09f73177241e5dd0c

WIP dns01 hook

cel committed on 7/19/2017, 7:04:02 AM
Parent: ba41015e031972e9767b82651d823f5b439cf972

Files changed

hooks/dehydrated/dehydrated-ssb-dns01-hook.jschanged
index.jschanged
lib/server.jschanged
hooks/dehydrated/dehydrated-ssb-dns01-hook.jsView
@@ -70,9 +70,15 @@
7070 }
7171
7272 function resolveDomains(sbot, hostnames, cb) {
7373 console.log('resolve domains ', hostnames)
74- /* TODO: support wildcards and CNAMES */
74 + if (!hostnames.length) return cb()
75 + var done = multicb({pluck: 1})
76 + hostnames.forEach(function (hostname) {
77 + dns.resolve(hostname, done())
78 + })
79 + done(cb)
80 + /*
7581 pull(
7682 sbot.messagesByType('ssb-dns'),
7783 pull.filter(function (msg) {
7884 var c = msg.value.content
@@ -84,13 +90,22 @@
8490 filterBranches(),
8591 pull.map(function (msg) { return msg.value.content.record.data }),
8692 pull.collect(cb)
8793 )
94 + */
8895 }
8996
9097 function resolveNameservers(sbot, hostnames, cb) {
9198 console.log('resolve nameservers ', hostnames)
92- /* TODO: support wildcards and CNAMES */
99 + if (!hostnames.length) return cb()
100 + var done = multicb({pluck: 1})
101 + hostnames.forEach(function (hostname) {
102 + var domain = hostname.replace(/[^.]*\./, '')
103 + console.log('domain', domain)
104 + dns.resolveNs(domain, done())
105 + })
106 + done(cb)
107 + /*
93108 pull(
94109 sbot.messagesByType('ssb-dns'),
95110 pull.filter(function (msg) {
96111 var c = msg.value.content
@@ -102,12 +117,14 @@
102117 filterBranches(),
103118 pull.map(function (msg) { return msg.value.content.record.data }),
104119 pull.collect(cb)
105120 )
121 + */
106122 }
107123
108124 function getNameserverHosts(sbot, domains, cb) {
109125 resolveNameservers(sbot, domains, function (err, nameservers) {
126 + console.log('resolved', nameservers)
110127 if (err) return cb(err)
111128 resolveDomains(sbot, nameservers, cb)
112129 })
113130 }
@@ -194,14 +211,17 @@
194211 console.log('gossip msgs', msgs.map(function (msg) { return msg.key}))
195212 var records = msgs.map(function (msg) { return msg.value.content.record })
196213 var domains = records.map(function (r) { return r.name }).filter(uniques())
197214 getNameserverHosts(sbot, domains, function (err, hosts) {
198- if (err) return cb(err)
215 + if (err) {
216 + console.error('unable to get nameservers:', err)
217 + return waitForRecords(records, 900e3, [], cb)
218 + }
199219 getPubAddressesForHosts(sbot, hosts, function (err, addrs) {
200220 if (err) return cb(err)
201- gossipWithPubs(sbot, addrs, 600e3, function (err) {
221 + gossipWithPubs(sbot, addrs, 900e3, function (err) {
202222 if (err) return cb(err)
203- waitForRecords(records, 600e3, hosts, cb)
223 + waitForRecords(records, 900e3, hosts, cb)
204224 })
205225 })
206226 })
207227 }
@@ -270,9 +290,9 @@
270290 var value = {
271291 type: 'ssb-dns',
272292 record: {
273293 name: '_acme-challenge.' + challenge.domainName,
274- ttl: 180,
294 + ttl: 30,
275295 class: 'IN',
276296 type: 'TXT',
277297 data: challenge.tokenContent
278298 }
@@ -297,9 +317,9 @@
297317 sbot.publish({
298318 type: 'ssb-dns',
299319 record: {
300320 name: name,
301- ttl: 180,
321 + ttl: 30,
302322 class: 'IN',
303323 type: 'TXT',
304324 },
305325 branch: branches
@@ -319,8 +339,9 @@
319339 console.log('deployed challenges')
320340 if (err) return cb(err)
321341 gossipMsgs(sbot, msgs, function (err) {
322342 if (!err) console.log('gossip success')
343 + cb()
323344 })
324345 })
325346 })
326347 }
index.jsView
@@ -79,8 +79,11 @@
7979
8080 Client(function (err, sbot, config) {
8181 if (err) throw err;
8282
83 + // keep alive
84 + setInterval(sbot.whoami, 10e3)
85 +
8386 Lib.server.listen(sbot, port, host, function () {
8487 console.log("server listening on %s:%s", host, port);
8588 }, config && config.dns);
8689 });
lib/server.jsView
@@ -107,25 +107,30 @@
107107 var result = this.cache[key];
108108 if (result) {
109109 // cache hit
110110 if (result.expires > Date.now()) {
111 + console.log('hit', key)
111112 return cb(null, result);
112113 } else {
113114 // expired
115 + console.log('expired', key)
114116 delete this.cache[key];
115117 }
116118 }
117119
118120 var cbs = this.cbs[key];
121 + if (cbs) console.log('waiting', key)
119122 if (cbs) return cbs.push(cb);
120- else cbs = this.cbs[key] = [cb];
123 + cbs = this.cbs[key] = [cb];
124 + if (cbs) console.log('query', key)
121125
122126 if (this.verbose) {
123127 log.nonCachedQuery(req, q);
124128 }
125129
126130 var self = this;
127131 Query.query(this.sbot, q, function (err, result) {
132 + console.log('result', key, err, result)
128133 if (!err && result.cache) self.cache[key] = result;
129134 while (cbs.length) cbs.shift()(err, result);
130135 delete self.cbs[key];
131136 });
@@ -185,10 +190,9 @@
185190 var server = createServer(sbot, port, host, cb, opt);
186191
187192 var close = function () {
188193 console.error("Server connection lost. Shutting down");
189- sbot.close();
190- server.close();
194 + process.exit(1)
191195 };
192196
193197 sbot.on('closed', close);
194198 };

Built with git-ssb-web