Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer Store Verification #1350

Open
wants to merge 5 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

Don't download critical pieces before verification

This makes metadata always available before every request, and race
conditions between verification and downloading aren't possible.

Critical pieces are still prioritized for verification.
  • Loading branch information
KayleePop committed Jun 18, 2018
commit 5d1934b03f8848faa2518c0a7b955a153b732039
@@ -605,7 +605,7 @@ Torrent.prototype._verify = function (index, cb) {
var self = this

if (self.destroyed) return cb(new Error('torrent is destroyed'))
if (self._verifying[index] || self.bitfield.get(index) || self._verified[index]) {
if (self._verifying[index] || self._verified[index]) {
// call cb() asynchronously so that parallelLimit() won't block
return process.nextTick(cb, null)
}
@@ -614,8 +614,6 @@ Torrent.prototype._verify = function (index, cb) {

self.store.get(index, function (err, buf) {
if (self.destroyed) return cb(new Error('torrent is destroyed'))
// a critical piece might have been downloaded before this callback
if (self.bitfield.get(index)) return cb(null)

if (err) {
// interpret any error as not having the chunk
@@ -626,8 +624,6 @@ Torrent.prototype._verify = function (index, cb) {

sha1(buf, function (hash) {
if (self.destroyed) return cb(new Error('torrent is destroyed'))
// a critical piece might have been downloaded before this callback
if (self.bitfield.get(index)) return cb(null)

if (hash === self._hashes[index]) {
self._debug('piece from store verified %s', index)
@@ -1494,13 +1490,10 @@ Torrent.prototype._request = function (wire, index, hotswap) {
if (self.bitfield.get(index)) return false

if (!self._verified[index]) {
if (self._critical[index]) {
// if the piece is critical then start its verification immediately
self._verify(index, noop)
} else {
// cancel the request unless the piece is critical
return false
}
// verify critical pieces as soon as possible
if (self._critical[index]) self._verify(index, noop)

return false
}

var maxOutstandingRequests = isWebSeed
@@ -1531,11 +1524,7 @@ Torrent.prototype._request = function (wire, index, hotswap) {
var chunkLength = isWebSeed ? piece.chunkLengthRemaining(reservation) : piece.chunkLength(reservation)

wire.request(index, chunkOffset, chunkLength, function onChunk (err, chunk) {
// A critical piece may have been verified as in the store before the callback
if (self.destroyed || self.bitfield.get(index)) return

// TODO: what is this for?
if (!self.ready) return self.once('ready', function () { onChunk(err, chunk) })
if (self.destroyed) return

if (r[i] === wire) r[i] = null

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.