git ssb

4+

Dominic / scuttlebot



Commit 9f332f5cbf487b256a2b22ded2d6d97e1bb4e8c4

persist peer states, so that we do not need toreconnect to them all every startup!

Dominic Tarr committed on 10/9/2016, 5:24:08 AM
Parent: 287d75f15ff0bc1b3986bc4c64833f09d445cf83

Files changed

plugins/gossip/index.jschanged
plugins/gossip/schedule.jschanged
plugins/gossip/index.jsView
@@ -138,9 +138,9 @@
138138 if(!f) {
139139 // new peer
140140 addr.source = source
141141 addr.announcers = 1
142- addr.duration = null
142 + addr.duration = addr.duration || null
143143 peers.push(addr)
144144 notify({ type: 'discover', peer: addr, source: source || 'manual' })
145145 return addr
146146 }
@@ -203,10 +203,11 @@
203203 //track whether we have successfully connected.
204204 //or how many failures there have been.
205205 var since = peer.stateChange
206206 peer.stateChange = Date.now()
207- if(peer.state === 'connected') //may be "disconnecting"
208- peer.duration = stats(peer.duration, peer.stateChange - since)
207 +// if(peer.state === 'connected') //may be "disconnecting"
208 + peer.duration = stats(peer.duration, peer.stateChange - since)
209 +// console.log(peer.duration)
209210 peer.state = undefined
210211 notify({ type: 'disconnect', peer: peer })
211212 server.emit('log:info', ['SBOT', rpc.id, 'disconnect'])
212213 })
@@ -223,19 +224,26 @@
223224 var p = gossip.add(v, 'stored')
224225 })
225226 })
226227
227- setInterval(function () {
228- if(deepEqual(peers, last)) return
228 + var int = setInterval(function () {
229229 var copy = JSON.parse(JSON.stringify(peers))
230230 copy.forEach(function (e) {
231231 delete e.state
232232 })
233 + if(deepEqual(copy, last)) return
234 + last = copy
235 + console.log("WRITE GOSSIP STATE")
233236 stateFile.set(copy, console.log.bind(console))
234237 }, 10*1000)
235238
239 + if(int.unref) int.unref()
240 +
236241 return gossip
237242 }
238243 }
239244
240245
241246
247 +
248 +
249 +
plugins/gossip/schedule.jsView
@@ -127,8 +127,9 @@
127127 })
128128 }
129129
130130 var selected = select(peers, ts, and(filter, isOnline), opts)
131 +
131132 selected
132133 .forEach(function (peer) {
133134 gossip.connect(peer)
134135 })
@@ -203,4 +204,8 @@
203204
204205
205206
206207
208 +
209 +
210 +
211 +

Built with git-ssb-web