Files: 3eb1b173c39d9c87c4c84a786a93eb2059417ac2 / lib / gossip-with-slow-rollout / init.js
959 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 | |
7 | // populate peertable with configured seeds (mainly used in testing) |
8 | var seeds = config.seeds |
9 | |
10 | ;(isArray(seeds) ? seeds : [seeds]).filter(Boolean) |
11 | .forEach(function (addr) { gossip.add(addr, 'seed') }) |
12 | |
13 | // populate peertable with pub announcements on the feed |
14 | pull( |
15 | server.messagesByType({ |
16 | type: 'pub', live: true, keys: false |
17 | }), |
18 | pull.drain(function (msg) { |
19 | if (!msg.content.address) return |
20 | if (ref.isAddress(msg.content.address)) { |
21 | // PATCH: only self will be connected to immediately, others will roll out slowly |
22 | gossip.add(msg.content.address, msg.author === server.id ? 'self' : 'pub') |
23 | } |
24 | }) |
25 | ) |
26 | |
27 | // populate peertable with announcements on the LAN multicast |
28 | server.on('local', function (_peer) { |
29 | gossip.add(_peer, 'local') |
30 | }) |
31 | |
32 | } |
33 |
Built with git-ssb-web