git ssb

15+

ansuz / dnssb



Commit 8ad8204e536a3463e29d6bb49d043c56cbababfd

implement 'ssb-dns dump'

ansuz committed on 10/31/2016, 7:29:19 PM
Parent: af8938fce74c725d9248c5cea181a9f733679646

Files changed

index.jschanged
lib/index.jschanged
lib/dump.jsadded
index.jsView
@@ -8,14 +8,17 @@
88 if (require.main !== module) { return module.exports = Lib; }
99
1010 var publishHelp = "\tssb-dns publish name type value (class)";
1111 var serverHelp = "\tssb-dns server port host";
12 +var dumpHelp = "\tssb-dns dump";
1213
14 +
1315 var CLI_Help = function () {
1416 [
1517 "try one of:",
1618 serverHelp,
1719 publishHelp,
20 + dumpHelp,
1821 ].forEach(function (m) {
1922 console.log(m);
2023 });
2124 };
@@ -25,8 +28,20 @@
2528 switch (argv[0]) {
2629 case undefined:
2730 CLI_Help();
2831 break;
32 + case 'dump':
33 + (function () {
34 + var count = 0;
35 + Lib.dump.records(function (msg, record) { // each
36 + console.log(JSON.stringify(record, null, 2));
37 + count++;
38 + }, function (sbot) { // done
39 + console.log("Found a total of %s valid ssb-dns records", count);
40 + sbot.close();
41 + });
42 + }());
43 + break;
2944 case 'server':
3045 (function () {
3146 var port = argv[1] || 53053;
3247 var host = argv[2] || '127.0.0.1';
lib/index.jsView
@@ -3,4 +3,5 @@
33 Lib.publish = require("./publish");
44
55 Lib.server = require("./server");
66
7 +Lib.dump = require("./dump");
lib/dump.jsView
@@ -1,0 +1,24 @@
1 +var Pull = require("pull-stream");
2 +var Ansuz = require("ansuz");
3 +var Dump = module.exports = {};
4 +
5 +Dump.records = function (each, done) {
6 + var Client = require("ssb-client");
7 +
8 + Client(function (err, sbot) {
9 + if (err) { return void done(err); }
10 +
11 + Pull(sbot.messagesByType({
12 + type: 'ssb-dns',
13 + }),
14 + Pull.filter(function (msg) {
15 + return typeof(Ansuz.find(msg, ['value', 'content', 'record'])) === 'object';
16 + }),
17 + Pull.map(function (msg) {
18 + each(msg, Ansuz.find(msg, ['value', 'content', 'record']));
19 + }),
20 + Pull.onEnd(function () {
21 + done(sbot);
22 + }));
23 + });
24 +};

Built with git-ssb-web