git ssb

4+

Dominic / scuttlebot



Commit 9ecdaa61ebef5d6e4b5382fbe17b02a236cddaee

handle quota special cases: do not use attempt strategy unless there are no connections, do not connect to legacy peers if there are long term peers around, and disconnect from peers which are not good longterm peers after 10 seconds

Dominic Tarr committed on 10/29/2016, 4:03:33 PM
Parent: 867f184e28b0576b60a784b3c631a6f016430d04

Files changed

plugins/gossip/schedule.jschanged
plugins/gossip/schedule.jsView
@@ -115,21 +115,19 @@
115115 }
116116
117117 function connect (peers, ts, name, filter, opts) {
118118 var connected = peers.filter(isConnect).filter(filter)
119- .filter(function (peer) {
120- return peer.stateChange + 10e3 < ts
121- })
122119
120 + //disconnect if over quota
123121 if(connected.length > opts.quota) {
124122 return earliest(connected, connected.length - opts.quota)
125123 .forEach(function (peer) {
126124 gossip.disconnect(peer)
127125 })
128126 }
129127
128 + //will return [] if the quota is full
130129 var selected = select(peers, ts, and(filter, isOnline), opts)
131-
132130 selected
133131 .forEach(function (peer) {
134132 gossip.connect(peer)
135133 })
@@ -144,24 +142,10 @@
144142 connecting = false
145143 var ts = Date.now()
146144 var peers = gossip.peers()
147145
148- connect(peers, ts, 'attempt', exports.isUnattempted, {
149- min: 0, quota: 10, factor: 0, max: 0, groupMin: 0,
150- disable: !conf('global', true)
151- })
146 + var connected = peers.filter(isConnect).length
152147
153- //quota, groupMin, min, factor, max
154- connect(peers, ts, 'retry', exports.isInactive, {
155- min: 0,
156- quota: 3, factor: 5*60e3, max: 3*60*60e3, groupMin: 5*50e3
157- })
158-
159- connect(peers, ts, 'legacy', exports.isLegacy, {
160- quota: 3, factor: 5*min, max: 3*hour, groupMin: 5*min,
161- disable: !conf('global', true)
162- })
163-
164148 connect(peers, ts, 'longterm', exports.isLongterm, {
165149 quota: 3, factor: 10e3, max: 10*min, groupMin: 5e3,
166150 disable: !conf('global', true)
167151 })
@@ -170,8 +154,36 @@
170154 quota: 3, factor: 2e3, max: 10*min, groupMin: 1e3,
171155 disable: !conf('local', true)
172156 })
173157
158 + if(connected === 0)
159 + connect(peers, ts, 'attempt', exports.isUnattempted, {
160 + min: 0, quota: 1, factor: 0, max: 0, groupMin: 0,
161 + disable: !conf('global', true)
162 + })
163 +
164 + //quota, groupMin, min, factor, max
165 + connect(peers, ts, 'retry', exports.isInactive, {
166 + min: 0,
167 + quota: 3, factor: 5*60e3, max: 3*60*60e3, groupMin: 5*50e3
168 + })
169 +
170 + var longterm = peers.filter(isConnect).filter(exports.isLongterm).length
171 +
172 + connect(peers, ts, 'legacy', exports.isLegacy, {
173 + quota: 3 - longterm,
174 + factor: 5*min, max: 3*hour, groupMin: 5*min,
175 + disable: !conf('global', true)
176 + })
177 +
178 + peers.filter(isConnect).forEach(function (e) {
179 + if((!exports.isLongterm(e) || e.state === 'connecting') && e.stateChange + 10e3 < ts) {
180 + console.log('disconnect', exports.isLongterm(e), e.state, e.stateChange - ts)
181 + gossip.disconnect(e)
182 + }
183 +
184 + })
185 +
174186 }, 100*Math.random())
175187
176188 }
177189
@@ -197,15 +209,4 @@
197209 exports.isLocal = isLocal
198210 exports.isConnectedOrConnecting = isConnect
199211 exports.select = select
200212
201-
202-
203-
204-
205-
206-
207-
208-
209-
210-
211-

Built with git-ssb-web