Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-01-05 08:48:23 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-01-05 08:56:05 +0300
commitffcd84f07bd161ac424e682a683b09d376eff331 (patch)
tree0005a1023cf720e98373b22aba57faa0800871f7 /lib
parent5ab99cc2c2de446f3ddc39e47a20d5ca01ba99e5 (diff)
client.seed: skip piece verification for performance
For https://github.com/feross/webtorrent/issues/235
Diffstat (limited to 'lib')
-rw-r--r--lib/storage.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/storage.js b/lib/storage.js
index df87305..2964f2f 100644
--- a/lib/storage.js
+++ b/lib/storage.js
@@ -28,14 +28,16 @@ inherits(Piece, EventEmitter)
* @param {number} index piece index
* @param {string} hash sha1 hash (hex) for this piece
* @param {Buffer|number} buffer backing buffer for this piece or length of piece if the backing buffer is lazy
+ * @param {boolean=} noVerify skip piece verification (used when seeding a new file)
*/
-function Piece (index, hash, buffer) {
+function Piece (index, hash, buffer, noVerify) {
var self = this
EventEmitter.call(self)
if (!debug.enabled) self.setMaxListeners(0)
self.index = index
self.hash = hash
+ self.noVerify = !!noVerify
if (typeof buffer === 'number') {
// alloc buffer lazily
@@ -130,7 +132,7 @@ Piece.prototype.verify = function (buffer) {
return
}
- self.verified = (sha1(buffer) === self.hash)
+ self.verified = self.noVerify || (sha1(buffer) === self.hash)
if (self.verified) {
self.emit('done')
} else {
@@ -333,7 +335,7 @@ function Storage (parsedTorrent, opts) {
// otherwise, the piece's buffer will be lazily created on demand
var buffer = (self.buffer ? self.buffer.slice(start, end) : end - start)
- var piece = new Piece(index, hash, buffer)
+ var piece = new Piece(index, hash, buffer, !!opts.noVerify)
piece.on('done', self._onPieceDone.bind(self, piece))
return piece
})