git ssb

2+

mixmix / ticktack



Commit f80524e4e4d9ee8b39654228746a0afe58778971

add a reconnector which keeps topping your up with peer connections D:

mix irving committed on 6/1/2018, 12:18:58 AM
Parent: 3627ef5bb2d0af90d48c88e2897c15df3cd2dd11

Files changed

ftu/manageProgress.jschanged
ftu/manageProgress.jsView
@@ -29,8 +29,9 @@
2929 sbot.gossip.peers((err, peers) => {
3030 if (err) return console.error(err)
3131
3232 connectToPeers({ sbot, peers, state })
33+ reconnectToPeers({ sbot, peers, state, period: 7000 })
3334 })
3435 })
3536 }
3637
@@ -50,8 +51,25 @@
5051 }
5152 })
5253 }
5354
55+function reconnectToPeers ({ sbot, peers, state, period }) {
56+ sbot.status((err, data) => {
57+ if (err) return setTimeout(() => reconnectToPeers({ sbot, peers, period, state }), period)
58+
59+ if (data.gossip.length < 5) {
60+ peers
61+ .sort((a, b) => Math.random() > 0.5 ? -1 : 1)
62+ .slice(0, 5)
63+ .forEach(p => sbot.gossip.connect(p, console.log))
64+ }
65+
66+ if (resolve(state.importComplete)) return
67+
68+ setTimeout(() => reconnectToPeers({ sbot, peers, period, state }), period)
69+ })
70+}
71+
5472 function watchCurrentSequence ({ sbot, state }) {
5573 var sink = pull.drain((msg) => {
5674 let seq = get(msg, 'value.sequence', false)
5775 if (seq) state.mySequence.current.set(seq)
@@ -72,12 +90,12 @@
7290 const feedId = sbot.id
7391 sbot.ebt.peerStatus(feedId, (err, data) => {
7492 if (err) return setTimeout(() => watchLatestSequence({ sbot, period, state }), period)
7593
76- cache = data = Object.assign({}, cache, data)
94+ Object.assign(cache, data.peers)
7795 const currentLatest = resolve(state.mySequence.latest)
7896
79- const remoteSeqs = map(data.peers, (val) => val.seq)
97+ const remoteSeqs = map(cache, (val) => val.seq)
8098 .filter(s => s >= currentLatest) // only keep remote seq that confirm or update backup seq
8199 .sort((a, b) => a > b ? -1 : 1) // order them
82100
83101 console.log('mySequence.latest', resolve(state.mySequence.latest), remoteSeqs)
@@ -150,8 +168,7 @@
150168
151169 // console.log(peerId, currentLatest, remoteSeq)
152170 // })
153171 // })
154-
155172 }
156173
157174 module.exports = manageProgress

Built with git-ssb-web