git ssb

3+

Dominic / ssb-blobs



Commit 1441dc6aaf4517378c3ba5640cf67739944c68a2

Clean up aborted createWants stream

Otherwise, a createWants stream only gets cleaned up in the sink for the peer's
createWants stream. But for a local RPC connection, we do not call createWants
on the peer, so if the remote calls createWants, we have to clean it up after it
is aborted. Here we do that it in the appropriate place.
cel committed on 7/17/2017, 6:45:20 PM
Parent: c0e9a969c5c0484a867b4ca5508beaeff462f603

Files changed

inject.jschanged
inject.jsView
@@ -30,8 +30,17 @@
3030 for(var k in obj) c++
3131 return c
3232 }
3333
34 +function onAbort(abortCb) {
35 + return function (read) {
36 + return function (abort, cb) {
37 + if (abort) abortCb(abort, cb)
38 + else read(null, cb)
39 + }
40 + }
41 +}
42 +
3443 module.exports = function inject (blobs, set, name, opts) {
3544 opts = opts || {}
3645 //sympathy controls whether you'll replicate
3746 var sympathy = opts.sympathy == null ? 3 : opts.sympathy | 0
@@ -198,12 +207,13 @@
198207 //merge in ids we are pushing.
199208 var w = clone(want)
200209 for(var k in push) w[k] = -1
201210 streams[id].push(w)
202-
203- return streams[id]
204211 }
205- return streams[id]
212 + return pull(streams[id], onAbort(function (err, cb) {
213 + streams[id] = false
214 + cb(err)
215 + }))
206216 }
207217
208218 function wantSink (peer) {
209219 createWantStream(peer.id) //set streams[peer.id]

Built with git-ssb-web