git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 93c8acc3bef1de08c2824be1d2c5d39c33ec499d

tweak persistent-gossip to favour pubs that you are friends with, increase perm to 3

Matt McKegg committed on 11/2/2016, 9:25:50 PM
Parent: 9744d260b89e1e2afac37b36c0973c99040adefd

Files changed

lib/persistent-gossip/schedule.jschanged
server-process.jschanged
lib/persistent-gossip/schedule.jsView
@@ -145,9 +145,9 @@
145145 connecting = false
146146 var ts = Date.now()
147147 var peers = gossip.peers()
148148
149- var connected = peers.filter(isConnect).length
149+ var connected = peers.filter(and(isConnect, not(isLocal))).length
150150
151151 connect(peers, ts, 'longterm', exports.isLongterm, {
152152 quota: 3, factor: 10e3, max: 10*min, groupMin: 5e3,
153153 disable: !conf('global', true)
@@ -157,13 +157,14 @@
157157 quota: 3, factor: 2e3, max: 10*min, groupMin: 1e3,
158158 disable: !conf('local', true)
159159 })
160160
161- if(connected === 0)
161+ if(connected < 3) {
162162 connect(peers, ts, 'attempt', exports.isUnattempted, {
163163 min: 0, quota: 1, factor: 0, max: 0, groupMin: 0,
164164 disable: !conf('global', true)
165165 })
166+ }
166167
167168 //quota, groupMin, min, factor, max
168169 connect(peers, ts, 'retry', exports.isInactive, {
169170 min: 0,
server-process.jsView
@@ -24,6 +24,24 @@
2424 }
2525 ssbConfig.manifest = context.sbot.getManifest()
2626 serveBlobs(context)
2727 fs.writeFileSync(Path.join(ssbConfig.path, 'manifest.json'), JSON.stringify(ssbConfig.manifest))
28+ connectToFriendlyPubs(context.sbot)
2829 electron.ipcRenderer.send('server-started', ssbConfig)
2930 }
31+
32+function connectToFriendlyPubs (sbot) {
33+ sbot.gossip.peers((err, peers) => {
34+ if (err) return console.log(err)
35+ sbot.friends.all((err, friends) => {
36+ if (err) return console.log(err)
37+ console.log('Attempting to connect to friendly pubs...')
38+ peers.filter((p) => p.state !== 'connected' && isFriends(friends, sbot.id, p.key)).forEach((peer) => {
39+ sbot.gossip.connect(peer, () => {})
40+ })
41+ })
42+ })
43+}
44+
45+function isFriends (friends, a, b) {
46+ return friends[a] && friends[b] && friends[a][b] && friends[b][a]
47+}

Built with git-ssb-web