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 PMParent: 867f184e28b0576b60a784b3c631a6f016430d04
Files changed
plugins/gossip/schedule.js | changed |
plugins/gossip/schedule.js | ||
---|---|---|
@@ -115,21 +115,19 @@ | ||
115 | 115 … | } |
116 | 116 … | |
117 | 117 … | function connect (peers, ts, name, filter, opts) { |
118 | 118 … | var connected = peers.filter(isConnect).filter(filter) |
119 | - .filter(function (peer) { | |
120 | - return peer.stateChange + 10e3 < ts | |
121 | - }) | |
122 | 119 … | |
120 … | + //disconnect if over quota | |
123 | 121 … | if(connected.length > opts.quota) { |
124 | 122 … | return earliest(connected, connected.length - opts.quota) |
125 | 123 … | .forEach(function (peer) { |
126 | 124 … | gossip.disconnect(peer) |
127 | 125 … | }) |
128 | 126 … | } |
129 | 127 … | |
128 … | + //will return [] if the quota is full | |
130 | 129 … | var selected = select(peers, ts, and(filter, isOnline), opts) |
131 | - | |
132 | 130 … | selected |
133 | 131 … | .forEach(function (peer) { |
134 | 132 … | gossip.connect(peer) |
135 | 133 … | }) |
@@ -144,24 +142,10 @@ | ||
144 | 142 … | connecting = false |
145 | 143 … | var ts = Date.now() |
146 | 144 … | var peers = gossip.peers() |
147 | 145 … | |
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 | |
152 | 147 … | |
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 | - | |
164 | 148 … | connect(peers, ts, 'longterm', exports.isLongterm, { |
165 | 149 … | quota: 3, factor: 10e3, max: 10*min, groupMin: 5e3, |
166 | 150 … | disable: !conf('global', true) |
167 | 151 … | }) |
@@ -170,8 +154,36 @@ | ||
170 | 154 … | quota: 3, factor: 2e3, max: 10*min, groupMin: 1e3, |
171 | 155 … | disable: !conf('local', true) |
172 | 156 … | }) |
173 | 157 … | |
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 … | + | |
174 | 186 … | }, 100*Math.random()) |
175 | 187 … | |
176 | 188 … | } |
177 | 189 … | |
@@ -197,15 +209,4 @@ | ||
197 | 209 … | exports.isLocal = isLocal |
198 | 210 … | exports.isConnectedOrConnecting = isConnect |
199 | 211 … | exports.select = select |
200 | 212 … | |
201 | - | |
202 | - | |
203 | - | |
204 | - | |
205 | - | |
206 | - | |
207 | - | |
208 | - | |
209 | - | |
210 | - | |
211 | - |
Built with git-ssb-web