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 AMParent: 9612ad288ce92ed027371e3b3e1c005116464264
Files changed
lib/local-with-list.js | changed |
lib/persistent-gossip/index.js | changed |
lib/local-with-list.js | ||
---|---|---|
@@ -20,16 +20,18 @@ | ||
20 | 20 | }, |
21 | 21 | init: function (sbot, config) { |
22 | 22 | var local = broadcast(config.port) |
23 | 23 | var lastSeen = {} |
24 | + var addrs = {} | |
24 | 25 | var localKeys = new Set() |
25 | 26 | |
26 | 27 | setInterval(function () { |
27 | 28 | Object.keys(lastSeen).forEach((key) => { |
28 | 29 | if (Date.now() - lastSeen[key] < 10e3) { |
29 | 30 | localKeys.add(key) |
30 | 31 | } else { |
31 | 32 | localKeys.delete(key) |
33 | + sbot.gossip.delete(addrs[key]) | |
32 | 34 | delete lastSeen[key] |
33 | 35 | } |
34 | 36 | }) |
35 | 37 | }, 5e3) |
@@ -38,8 +40,9 @@ | ||
38 | 40 | if (buf.loopback) return |
39 | 41 | var data = buf.toString() |
40 | 42 | var peer = ref.parseAddress(data) |
41 | 43 | if (peer) { |
44 | + addrs[peer.key] = peer | |
42 | 45 | lastSeen[peer.key] = Date.now() |
43 | 46 | sbot.gossip.add(data, 'local') |
44 | 47 | } |
45 | 48 | }) |
lib/persistent-gossip/index.js | ||
---|---|---|
@@ -150,8 +150,15 @@ | ||
150 | 150 | f.announcers ++ |
151 | 151 | |
152 | 152 | return f |
153 | 153 | }, '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 | + }, | |
154 | 161 | ping: function (opts) { |
155 | 162 | var timeout = config.timers && config.timers.ping || 5*60e3 |
156 | 163 | //between 10 seconds and 30 minutes, default 5 min |
157 | 164 | timeout = Math.max(10e3, Math.min(timeout, 30*60e3)) |
Built with git-ssb-web