Skip to content

Commit aa0def9

Browse files
committed
consistently use id as var name for blob id
1 parent 4a037b5 commit aa0def9

1 file changed

Lines changed: 32 additions & 37 deletions

File tree

inject.js

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ module.exports = function inject (blobs, set, name, opts) {
6767
var available = {}, streams = {}
6868
var send = {}, timer
6969

70-
function queue (hash, hops) {
70+
function queue (id, hops) {
7171
if(hops < 0)
72-
want[hash] = hops
72+
want[id] = hops
7373
else
74-
delete want[hash]
74+
delete want[id]
7575

76-
send[hash] = hops
76+
send[id] = hops
7777
var _send = send;
7878
send = {}
7979
notify(_send)
@@ -256,36 +256,36 @@ module.exports = function inject (blobs, set, name, opts) {
256256
var self
257257
return self = {
258258
//id: name,
259-
has: function (hash, cb) {
260-
hash = toBlobId(hash)
259+
has: function (id, cb) {
260+
id = toBlobId(id)
261261

262-
if(isArray(hash)) {
263-
for(var i = 0; i < hash.length; i++)
264-
if(!isBlobId(hash[i]))
265-
return cb(new Error('invalid hash:'+hash[i]))
262+
if(isArray(id)) {
263+
for(var i = 0; i < id.length; i++)
264+
if(!isBlobId(id[i]))
265+
return cb(new Error('invalid id:'+id[i]))
266266
}
267-
else if(!isBlobId(hash))
268-
return cb(new Error('invalid hash:'+hash))
267+
else if(!isBlobId(id))
268+
return cb(new Error('invalid id:'+id))
269269

270270
if(!legacy) {
271-
blobs.has.call(this, hash, cb)
271+
blobs.has.call(this, id, cb)
272272
}
273273
else {
274274
//LEGACY LEGACY LEGACY
275275
if(this === self || !this || this === global) { // a local call
276-
return blobs.has.call(this, hash, cb)
276+
return blobs.has.call(this, id, cb)
277277
}
278278
//ELSE, interpret remote calls to has as a WANT request.
279279
//handling this by calling process (which calls size())
280280
//avoids a race condition in the tests.
281281
//(and avoids doubling the number of calls)
282-
var a = Array.isArray(hash) ? hash : [hash]
282+
var a = Array.isArray(id) ? id : [id]
283283
var o = {}
284284
a.forEach(function (h) { o[h] = -1 })
285285
//since this is always "has" process will never use the second arg.
286286
process(o, null, function (err, res) {
287287
var a = []; for(var k in o) a.push(res[k] > 0)
288-
cb(null, Array.isArray(hash) ? a : a[0])
288+
cb(null, Array.isArray(id) ? a : a[0])
289289
})
290290
//LEGACY LEGACY LEGACY
291291
}
@@ -305,31 +305,32 @@ module.exports = function inject (blobs, set, name, opts) {
305305
})
306306
)
307307
},
308-
want: function (hash, cb) {
309-
hash = toBlobId(hash)
310-
if(!isBlobId(hash))
311-
return cb(new Error('invalid hash:'+hash))
308+
want: function (id, cb) {
309+
id = toBlobId(id)
310+
if(!isBlobId(id))
311+
return cb(new Error('invalid id:'+id))
312312
//always broadcast wants immediately, because of race condition
313313
//between has and adding a blob (needed to pass test/async.js)
314-
if(blobs.isEmptyHash(hash)) return cb(null, true)
315-
var id = isAvailable(hash)
314+
if(blobs.isEmptyHash(id)) return cb(null, true)
316315

317-
if(waiting[hash])
318-
waiting[hash].push(cb)
316+
var peerId = isAvailable(id)
317+
318+
if(waiting[id])
319+
waiting[id].push(cb)
319320
else {
320-
waiting[hash] = [cb]
321-
blobs.size(hash, function (err, size) {
321+
waiting[id] = [cb]
322+
blobs.size(id, function (err, size) {
322323
if(size != null) {
323-
while(waiting[hash].length)
324-
waiting[hash].shift()(null, true)
325-
delete waiting[hash]
324+
while(waiting[id].length)
325+
waiting[id].shift()(null, true)
326+
delete waiting[id]
326327
}
327328
})
328329
}
329330

330-
if(!id && waiting[hash]) queue(hash, -1)
331+
if(!peerId && waiting[id]) queue(id, -1)
331332

332-
if(id) return get(id, hash)
333+
if(peerId) return get(peerId, id)
333334
},
334335
push: function (id, cb) {
335336
id = toBlobId(id)
@@ -360,9 +361,3 @@ module.exports = function inject (blobs, set, name, opts) {
360361
}
361362
}
362363

363-
364-
365-
366-
367-
368-

0 commit comments

Comments
 (0)