git ssb

15+

ansuz / dnssb



Commit b357b56dacd821a496aeddf0de4a7b1713bc34a9

use pull-streams properly

* domains must always be lowercase
* always return something, even if it's nothing
ansuz committed on 10/31/2016, 4:03:44 PM
Parent: fe970e28e308489bb390816eaf391da29c39b0b7

Files changed

index.jschanged
publish.jschanged
index.jsView
@@ -1,8 +1,8 @@
11 var Dnsd = require("dnsd");
22 var Client = require("ssb-client");
33 var Pull = require("pull-stream");
4-var Paramap = require("pull-paramap");
4 +var Ansuz = require("ansuz");
55
66 var Config;
77 try {
88 Config = require("./config.js");
@@ -12,9 +12,11 @@
1212 }
1313
1414 var log = {
1515 req: function (req) {
16 + if (!Config.verbose) { return; }
1617 var q = req.question[0];
18 + console.log();
1719 console.log({
1820 name: q.name,
1921 type: q.type,
2022 class: q.class,
@@ -22,15 +24,15 @@
2224 },
2325 };
2426
2527 var answer = function (sbot, req, res) {
26- console.log();
2728 log.req(req);
2829
2930 var q = req.question;
3031
32 + // TODO validate queries more carefully
3133 if (!q.length) {
32- console.log("invalid question");
34 + console.error("invalid question");
3335 res.end();
3436 }
3537
3638 var name = q[0].name;
@@ -38,18 +40,16 @@
3840
3941 Pull(sbot.messagesByType({
4042 type: 'ssb-dns',
4143 }),
42- Paramap(function getAvatar(msg, cb) {
43- cb(null, msg);
44 + Pull.map(function (msg) {
45 + return Ansuz.find(msg, ['value', 'content', 'record']);
4446 }),
45- Pull.drain(function printMessage(msg) {
46- var record = msg.value.content.record;
47-
47 + Pull.filter(function (record) { return record; }),
48 + Pull.find(function printMessage(record) {
4849 if (typeof(record) !== 'object') { return; }
49-
5050 if (name && type &&
51- record.name === name &&
51 + record.name === name.toLowerCase() &&
5252 record.type === type &&
5353 record.value) {
5454 console.log("%s (%s) => %s", name, record.type, record.value);
5555
@@ -58,12 +58,14 @@
5858 res.answer.push({
5959 name: record.name,
6060 type: record.type,
6161 data: record.value,
62- ttl: 500,
62 + ttl: 500, // short ttl
6363 });
64- res.end()
64 + return true;
6565 }
66 + }, function () {
67 + res.end();
6668 }));
6769 };
6870
6971 var createServer = function (sbot, port, host, cb) {
publish.jsView
@@ -35,9 +35,9 @@
3535 };
3636
3737 var makeRecord = function (name, type, value, _class) {
3838 return {
39- name: name,
39 + name: name.toLowerCase(), // domain names must be lowercase
4040 type: type,
4141 value: value,
4242 class: _class || 'IN',
4343 };

Built with git-ssb-web