Commit f80524e4e4d9ee8b39654228746a0afe58778971
add a reconnector which keeps topping your up with peer connections D:
mix irving committed on 6/1/2018, 12:18:58 AMParent: 3627ef5bb2d0af90d48c88e2897c15df3cd2dd11
Files changed
ftu/manageProgress.js | changed |
ftu/manageProgress.js | ||
---|---|---|
@@ -29,8 +29,9 @@ | ||
29 | 29 | sbot.gossip.peers((err, peers) => { |
30 | 30 | if (err) return console.error(err) |
31 | 31 | |
32 | 32 | connectToPeers({ sbot, peers, state }) |
33 | + reconnectToPeers({ sbot, peers, state, period: 7000 }) | |
33 | 34 | }) |
34 | 35 | }) |
35 | 36 | } |
36 | 37 | |
@@ -50,8 +51,25 @@ | ||
50 | 51 | } |
51 | 52 | }) |
52 | 53 | } |
53 | 54 | |
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 | + | |
54 | 72 | function watchCurrentSequence ({ sbot, state }) { |
55 | 73 | var sink = pull.drain((msg) => { |
56 | 74 | let seq = get(msg, 'value.sequence', false) |
57 | 75 | if (seq) state.mySequence.current.set(seq) |
@@ -72,12 +90,12 @@ | ||
72 | 90 | const feedId = sbot.id |
73 | 91 | sbot.ebt.peerStatus(feedId, (err, data) => { |
74 | 92 | if (err) return setTimeout(() => watchLatestSequence({ sbot, period, state }), period) |
75 | 93 | |
76 | - cache = data = Object.assign({}, cache, data) | |
94 | + Object.assign(cache, data.peers) | |
77 | 95 | const currentLatest = resolve(state.mySequence.latest) |
78 | 96 | |
79 | - const remoteSeqs = map(data.peers, (val) => val.seq) | |
97 | + const remoteSeqs = map(cache, (val) => val.seq) | |
80 | 98 | .filter(s => s >= currentLatest) // only keep remote seq that confirm or update backup seq |
81 | 99 | .sort((a, b) => a > b ? -1 : 1) // order them |
82 | 100 | |
83 | 101 | console.log('mySequence.latest', resolve(state.mySequence.latest), remoteSeqs) |
@@ -150,8 +168,7 @@ | ||
150 | 168 | |
151 | 169 | // console.log(peerId, currentLatest, remoteSeq) |
152 | 170 | // }) |
153 | 171 | // }) |
154 | - | |
155 | 172 | } |
156 | 173 | |
157 | 174 | module.exports = manageProgress |
Built with git-ssb-web