git ssb

15+

ansuz / dnssb



Commit 69705109becfed7b3713e4f3da60f26ac286bed6

assume the record is json, not a string

ansuz committed on 10/31/2016, 2:56:02 PM
Parent: 43596ee016af3e2c1709e0734c63755a47e1f3d6

Files changed

index.jschanged
index.jsView
@@ -2,28 +2,14 @@
22 var Client = require("ssb-client");
33 var Pull = require("pull-stream");
44 var Paramap = require("pull-paramap");
55
6-
7-
8-
9-
10-
11-
12-
13-
146 var Config;
157 try {
168 Config = require("./config.js");
179 } catch (err) {
1810 console.error("\nCouldn't find './config.js'. Using defaults");
19- Config = {
20- port: 53053,
21- host: '127.0.0.1',
22- ready: function () {
23- console.log('Server running at %s:%s', Config.host, Config.port);
24- },
25- };
11 + Config = require("./config.dist.js");
2612 }
2713
2814 var log = {
2915 req: function (req) {
@@ -56,22 +42,24 @@
5642 Paramap(function getAvatar(msg, cb) {
5743 cb(null, msg);
5844 }),
5945 Pull.drain(function printMessage(msg) {
60- var text = msg.value.content.text;
46 + var record = msg.value.content.record;
6147
62- var result;
63- try {
64- result = JSON.parse(text);
65- } catch (err) {
66- throw new Error("Invalid record!");
67- }
68- if (name && type && result.name === name && result.type === type && result.value) {
69- console.log("%s (%s) => %s", name, result.type, result.value);
48 + if (typeof(record) !== 'object') { return; }
49 +
50 + if (name && type &&
51 + record.name === name &&
52 + record.type === type &&
53 + record.value) {
54 + console.log("%s (%s) => %s", name, record.type, record.value);
55 +
56 + // returns the first matching record found
57 + // TODO support multiple returned values
7058 res.answer.push({
71- name: result.name,
72- type: result.type,
73- data: result.value,
59 + name: record.name,
60 + type: record.type,
61 + data: record.value,
7462 ttl: 500,
7563 });
7664 res.end()
7765 }
@@ -88,9 +76,7 @@
8876 if (err) {
8977 console.error(err);
9078 return void process.exit(1);
9179 }
92- var port = 53053;
93- var host = '127.0.0.1';
9480 createServer(sbot, Config.port, Config.host, Config.ready);
9581 });
9682

Built with git-ssb-web