Files: 90dfad001a91b412a745a9cad0dccf4a3ef49dc2 / plugins / gossip / init.js
1065 bytesRaw
1 | var isArray = Array.isArray |
2 | var pull = require('pull-stream') |
3 | var ref = require('ssb-ref') |
4 | |
5 | module.exports = function (gossip, config, server) { |
6 | if (config.offline) return void console.log("Running in offline mode: gossip disabled") |
7 | |
8 | // populate peertable with configured seeds (mainly used in testing) |
9 | var seeds = config.seeds |
10 | |
11 | ;(isArray(seeds) ? seeds : [seeds]).filter(Boolean) |
12 | .forEach(function (addr) { gossip.add(addr, 'seed') }) |
13 | |
14 | // populate peertable with pub announcements on the feed (allow this to be disabled via config) |
15 | if(!config.gossip || (config.gossip.autoPopulate !== false && config.gossip.pub !== false)) |
16 | pull( |
17 | server.messagesByType({ |
18 | type: 'pub', live: true, keys: false |
19 | }), |
20 | pull.drain(function (msg) { |
21 | if(msg.sync) return |
22 | if(!msg.content.address) return |
23 | if(ref.isAddress(msg.content.address)) |
24 | gossip.add(msg.content.address, 'pub') |
25 | }, function () { |
26 | console.warn('[gossip] warning: this can happen if the database closes', arguments) |
27 | }) |
28 | ) |
29 | } |
30 |
Built with git-ssb-web