git ssb

10+

Matt McKegg / patchwork



Commit 4e87fb7f772146e90bc4f79a30bed7079d748a46

remove local peers from gossip list when they go offline (instead of continuously trying to reconnect)

Matt McKegg committed on 11/5/2016, 7:56:50 AM
Parent: 9612ad288ce92ed027371e3b3e1c005116464264

Files changed

lib/local-with-list.jschanged
lib/persistent-gossip/index.jschanged
lib/local-with-list.jsView
@@ -20,16 +20,18 @@
2020 },
2121 init: function (sbot, config) {
2222 var local = broadcast(config.port)
2323 var lastSeen = {}
24 + var addrs = {}
2425 var localKeys = new Set()
2526
2627 setInterval(function () {
2728 Object.keys(lastSeen).forEach((key) => {
2829 if (Date.now() - lastSeen[key] < 10e3) {
2930 localKeys.add(key)
3031 } else {
3132 localKeys.delete(key)
33 + sbot.gossip.delete(addrs[key])
3234 delete lastSeen[key]
3335 }
3436 })
3537 }, 5e3)
@@ -38,8 +40,9 @@
3840 if (buf.loopback) return
3941 var data = buf.toString()
4042 var peer = ref.parseAddress(data)
4143 if (peer) {
44 + addrs[peer.key] = peer
4245 lastSeen[peer.key] = Date.now()
4346 sbot.gossip.add(data, 'local')
4447 }
4548 })
lib/persistent-gossip/index.jsView
@@ -150,8 +150,15 @@
150150 f.announcers ++
151151
152152 return f
153153 }, 'string|object', 'string?'),
154 + delete: function (addr) {
155 + var peer = gossip.get(addr)
156 + var index = peers.indexOf(peer)
157 + if (~index) {
158 + peers.splice(index, 1)
159 + }
160 + },
154161 ping: function (opts) {
155162 var timeout = config.timers && config.timers.ping || 5*60e3
156163 //between 10 seconds and 30 minutes, default 5 min
157164 timeout = Math.max(10e3, Math.min(timeout, 30*60e3))

Built with git-ssb-web