ssbc / ssb-server

The gossip and replication server for Secure Scuttlebutt - a distributed social network
1.69k stars 164 forks source link

Blobs.want() calls back with false if there's any waiting period #309

Closed pfrazee closed 8 years ago

pfrazee commented 8 years ago

If you call blobs.want() on a blob, and it's not available, the callback will be queued, and then will be called when the blob is downloaded. (This is correct.) However, the callback is not given a true for the has parameter.

Example usage from patchwork's blob server:

sbot.blobs.want(hash, function(err, has) {
  if (!has) return respond(res, 404, 'File not found')
  //...
  respondSource(res, sbot.blobs.get(hash), false)
})

If the blob was already present, then has is set to true. I think it also should be set to true if there's a waiting period, for consistency, and in case we ever put a timeout on want (in which case false would be a meaningful result for has).

(This API issue is why Patchwork will show broken image links sometimes. The has comes back false when the download completes, resulting in the 404 response.)

dominictarr commented 8 years ago

oh, great find, awesome, merging.