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

Fix infinite loop bug #1786

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

Add customer verifier

Add custom verifier so reading the entire torrent file(s) is not necessary on startup.
  • Loading branch information
koush committed Jan 2, 2020
commit ebeee83e89bf1e135c4abb7355f1f55a78796256
@@ -117,6 +117,7 @@ class Torrent extends EventEmitter {
// TODO: remove this and expose a hook instead
// optimization: don't recheck every file if it hasn't changed
this._fileModtimes = opts.fileModtimes
this._verifyPiece = opts.verifyPiece

if (torrentId !== null) this._onTorrentId(torrentId)

@@ -566,6 +567,14 @@ class Torrent extends EventEmitter {
parallelLimit(this.pieces.map((piece, index) => cb => {
if (this.destroyed) return cb(new Error('torrent is destroyed'))

if (this._verifyPiece) {
if (this._verifyPiece(index, this._hashes[index], this.infoHash)) {
this._debug('piece verified %s', index)
this._markVerified(index)
}
return process.nextTick(cb, null)
}

this.store.get(index, (err, buf) => {
if (this.destroyed) return cb(new Error('torrent is destroyed'))

@@ -611,6 +620,7 @@ class Torrent extends EventEmitter {
this.pieces[index] = null
this._reservations[index] = null
this.bitfield.set(index, true)
this.emit('verified', index, this._hashes[index])
}

/**
@@ -1527,6 +1537,7 @@ class Torrent extends EventEmitter {
self.pieces[index] = null
self._reservations[index] = null
self.bitfield.set(index, true)
self.emit('verified', index, hash)

self.store.put(index, buf)

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