git ssb

15+

ansuz / dnssb



Commit f1f274f05206d55e420bda9b925f413cc9df624d

Fix bugs

cel committed on 11/1/2016, 1:07:24 AM
Parent: 4db28fa74d1966cfd674440c08a8bf2eb36f7c79

Files changed

lib/server.jschanged
lib/ssb-dns.jschanged
lib/server.jsView
@@ -28,16 +28,17 @@
2828 res.end();
2929 return;
3030 }
3131
32- var qMap = q.reduce(function (map, q) {
33- map[q.name.toLowerCase() + ':' + q.type] = true;
34- }, {});
32 + var qMap = {}
33 + q.forEach(function (q) {
34 + qMap[q.name.toLowerCase() + ':' + q.type] = true;
35 + });
3536
3637 Pull(sbot.messagesByType({
3738 type: 'ssb-dns',
3839 }),
39- pull.filter(function (msg) {
40 + Pull.filter(function (msg) {
4041 var c = msg.value.content;
4142 var record = c && c.record;
4243 return record && qMap[record.name + ':' + record.type];
4344 }),
@@ -47,12 +48,8 @@
4748 var types = records.map(function (r) { return r.type }).join(', ');
4849 var vals = records.map(function (r) { return r.value }).join(', ');
4950 console.log("%s (%s) => %s", names, types, vals);
5051 }
51- records.forEach(function (r) {
52- if (!r.ttl) r.ttl = 500;
53- if (!r.class) r.class = "IN";
54- })
5552 res.answer = records;
5653 res.end();
5754 }));
5855 };
lib/ssb-dns.jsView
@@ -1,7 +1,13 @@
11 var Pull = require("pull-stream");
22 var KVSet = require("kvset");
33
4 +function fixRecord(r) {
5 + if (!r.ttl) r.ttl = 500;
6 + if (!r.class) r.class = "IN";
7 + if (r.value) r.data = r.value, delete r.value
8 +}
9 +
410 module.exports = function SsbDns(cb) {
511 var set = new KVSet()
612 return Pull.drain(function (msg) {
713 var c = msg.value.content;
@@ -12,9 +18,11 @@
1218 for (var key in set.heads) {
1319 var value = set.heads[key];
1420 var c = value.content;
1521 var record = c && c.record;
16- if (record) records.push(record);
22 + if (!record) continue;
23 + fixRecord(record);
24 + records.push(record);
1725 }
1826 cb(err, records);
1927 });
2028 };

Built with git-ssb-web