From 4222a53369e420ab98e7c61adab3de56d0cefff6 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Fri, 9 Feb 2018 09:09:06 +0300 Subject: [PATCH 1/4] fix: cleanup DHT tables cache on torrent removal Fix bug on second adding of same torrent --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 65dd70c4..732e445c 100644 --- a/index.js +++ b/index.js @@ -389,6 +389,10 @@ WebTorrent.prototype._remove = function (torrentId, cb) { var torrent = this.get(torrentId) if (!torrent) return this.torrents.splice(this.torrents.indexOf(torrent), 1) + // clear hash entity in cache to be able use pears search again + if (this.dht) { + this.dht._tables.remove(torrent.infoHash) + } torrent.destroy(cb) } From eee6b15f180baf6774d46cfadcc71cd6e7393bb6 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Tue, 25 Sep 2018 13:41:01 +0300 Subject: [PATCH 2/4] fix opening some files after download finished --- lib/torrent.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/torrent.js b/lib/torrent.js index 6d53ee9c..5df1dc40 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1603,9 +1603,29 @@ Torrent.prototype._checkDone = function () { if (!done) break } if (!self.done && done) { + const done = () => { self.done = true - self._debug('torrent done: ' + self.infoHash) - self.emit('done') + self._debug('torrent done: ' + self.infoHash) + self.emit('done') + } + // flush files to be able to open after download finish + if(self._store === FSChunkStore) + { + let tasks = self.store.store.files.map(function (file) { + return function (cb) { + file.open(function (err, file) { + // an open error is okay because that means the file is not open + if (err) return cb(null) + file.close(cb) + }) + } + }) + parallel(tasks, done) + } + else + { + done() + } } self._gcSelections() From dd0d0568e342ff2be6ab38c506df6dd64c2b2a2e Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Tue, 25 Sep 2018 15:52:01 +0300 Subject: [PATCH 3/4] fix continue downloading after reopening store files --- lib/torrent.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/torrent.js b/lib/torrent.js index 5df1dc40..7ecff340 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -31,6 +31,8 @@ var uniq = require('uniq') var utMetadata = require('ut_metadata') var utPex = require('ut_pex') // browser exclude var parseRange = require('parse-numeric-range') +var thunky = require('thunky') +var raf = require('random-access-file') var File = require('./file') var Peer = require('./peer') @@ -1602,21 +1604,24 @@ Torrent.prototype._checkDone = function () { } if (!done) break } - if (!self.done && done) { + if (done) { const done = () => { - self.done = true + self.done = true self._debug('torrent done: ' + self.infoHash) self.emit('done') } // flush files to be able to open after download finish if(self._store === FSChunkStore) { - let tasks = self.store.store.files.map(function (file) { + let tasks = self.store.store.files.map(function (storeFile) { return function (cb) { - file.open(function (err, file) { + storeFile.open(function (err, file) { // an open error is okay because that means the file is not open if (err) return cb(null) - file.close(cb) + file.close(() => { + storeFile.open = thunky((cb) => cb(null, raf(storeFile.path))) + cb() + }) }) } }) From e3a348f3ae8ef444d9642fb74d4e888a14048768 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sun, 9 Dec 2018 14:17:27 +0300 Subject: [PATCH 4/4] update discovery --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e514ac45..f1ce6b94 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "stream-to-blob": "^1.0.0", "stream-to-blob-url": "^2.1.0", "stream-with-known-length-to-buffer": "^1.0.0", - "torrent-discovery": "^8.3.1", + "torrent-discovery": "^9.1.1", "torrent-piece": "^1.1.0", "uniq": "^1.0.1", "unordered-array-remove": "^1.0.2",