git ssb

15+

ansuz / dnssb



Tree: 8b277e861c3c9b30cb3e985a8b7fd3bdad237398

Files: 8b277e861c3c9b30cb3e985a8b7fd3bdad237398 / lib / query.js

956 bytesRaw
1var Pull = require("pull-stream");
2var KVSet = require("kvset");
3var Query = module.exports = {};
4
5Query.branches = function (name, type, _class, cb) {
6 var Client = require("ssb-client");
7
8 Client(function (err, sbot) {
9 if (err) return cb(err);
10
11 var set = new KVSet()
12 Pull(sbot.messagesByType({
13 type: 'ssb-dns',
14 }),
15 Pull.filter(function (msg) {
16 var c = msg.value.content;
17 var record = c && c.record;
18 return record
19 && record.name === name
20 && record.type === type
21 && (!_class || _class === (record.class || 'IN'));
22 }),
23 Pull.drain(function (msg) {
24 var c = msg.value.content;
25 if (c.branch) set.remove(c.branch);
26 set.add(msg.key);
27 }, function (err) {
28 if (err) return cb(err);
29 cb(null, Object.keys(set.heads));
30 }));
31 });
32};
33

Built with git-ssb-web