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

VerifyPieces: Removed Parallel execution to prevent excessive memory consumption... #447

Closed
wants to merge 2 commits into from
Closed
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

Next

Removed Parallel exectuion to prevent exsessive memory consumption an…

…d also to prevent UI/Process to hang when verifying large files.

Also introduced a verifyingPieces flag on Torrent - in order to let consumers of the library detect when files are being verified.
self._onStore() is being invoked before Torrent is verified - so that consumers can poll on the verifyingPieces flag to detect this.
  • Loading branch information
ngjermundshaug committed Sep 28, 2015
commit 947f905bbaba28452ed7cbead381086c80752980
@@ -80,6 +80,7 @@ function Torrent (torrentId, opts) {
self.numBlockedPeers = 0
self.files = null
self.done = false
self.verifyingPieces = false;

self._amInterested = false
self._selections = []
@@ -357,12 +358,12 @@ Torrent.prototype._onMetadata = function (metadata) {

self._onWireWithMetadata(wire)
})

debug('verifying existing torrent data')
parallel(self.pieces.map(function (piece, index) {
return function (cb) {
self.store.get(index, function (err, buf) {
if (err) return cb(null) // ignore error

//verify pieces
var verifyPiece = function (index) {
self.store.get(index, function (err, buf) {
if (!err) {
sha1(buf, function (hash) {
if (hash === self._hashes[index]) {
if (!self.pieces[index]) return
@@ -371,19 +372,26 @@ Torrent.prototype._onMetadata = function (metadata) {
self._reservations[index] = null
self.bitfield.set(index, true)
} else {
debug('piece invalid %s', index)
debug('piece invalid %s', index)
}
cb(null)
})
})
}
}), function (err) {
if (err) return self._onError(err)
debug('done verifying')
self._onStore()
})
}
//Verify next piece?
if (index + 1 < self.pieces.length) {
setImmediate(function () { verifyPiece(index + 1) });
}
else {
self.verifyingPieces = false;
debug('done verifying')
}
})
}
debug('verifying existing torrent data')
self.verifyingPieces = true;
verifyPiece(0);

self.emit('metadata')
self._onStore()
}

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