git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 2b1901f924e308bd0de810bbd4e8d894d91c2160

fix prioritize friend gossip

Matt McKegg committed on 10/18/2017, 2:20:34 PM
Parent: 76bc25fbc6edd50d2de53f58f3033960b0b32a34

Files changed

sbot/index.jschanged
sbot/index.jsView
@@ -5,8 +5,9 @@
55 var Progress = require('./progress')
66 var Search = require('./search')
77 var RecentFeeds = require('./recent-feeds')
88 var LiveBacklinks = require('./live-backlinks')
9+var pull = require('pull-stream')
910
1011 exports.name = 'patchwork'
1112 exports.version = require('../package.json').version
1213 exports.manifest = {
@@ -36,8 +37,30 @@
3637 var roots = Roots(ssb, config)
3738 var search = Search(ssb, config)
3839 var recentFeeds = RecentFeeds(ssb, config)
3940
41+ pull(
42+ ssb.friends.createFriendStream({live: false}),
43+ pull.drain(() => {}, () => {
44+ // don't assign peer friends until friends have loaded
45+ ssb.friends.hops({start: ssb.id, hops: 2}, function (_, following) {
46+ ssb.gossip.peers().forEach(function (peer) {
47+ if (following[peer.key]) {
48+ // we follow them, or follow someone that follows them!
49+ ssb.gossip.add(peer, 'friends')
50+ } else {
51+ ssb.friends.hops({start: peer.key, hops: 2}, function (_, result) {
52+ if (result && result[ssb.id]) {
53+ // they follow us, or someone that follows us!
54+ ssb.gossip.add(peer, 'friends')
55+ }
56+ })
57+ }
58+ })
59+ })
60+ })
61+ )
62+
4063 return {
4164 heartbeat: Heartbeat(ssb, config),
4265 channels: channels.stream,
4366 subscriptions: subscriptions.stream,

Built with git-ssb-web