Comments (5)
Interestingly, if I manually empty out the _selections
array after the torrent is added, then everything works fine.
However, the deselect method doesn't have the same effect.
If I do this:
/** @type {WebTorrent.Torrent} */
const torrent = await new Promise((resolve, reject) => {
// ...
});
torrent._selections.length = 0;
then the progress stays the same. (meaning that if 46% of the torrent was downloaded, then after the script starts, it doesn't download new chunks, unless a stream is opened. So it works as I would expect it to).
However, if I try to deselect everything the correct way (without using internal properties)...
/** @type {WebTorrent.Torrent} */
const torrent = await new Promise((resolve, reject) => {
// ...
});
torrent.deselect(0, torrent.pieces.length - 1, 0)
then it doesn't work.
It's weird... I can use this workaround for now, but I would rather not use internal properties.
I'll comment further details if I find the root cause of this issue.
from webtorrent.
Here's what I've found (these line numbers are all in libs/torrent.js
):
on lines 685-695, in the _markUnverified
method, all unverified pieces are selected (so 1 item per piece is added to _selections
):
_markUnverified (index) {
const len = (index === this.pieces.length - 1)
? this.lastPieceLength
: this.pieceLength
this.pieces[index] = new Piece(len)
this.bitfield.set(index, false)
this.select(index, index, 1)
this.files.forEach(file => {
if (file.done && file.includes(index)) file.done = false
})
}
This is fine, but it's important later.
On lines 1052-1057, in the deselect
method, in the for loop, we're only looking for selection items that are exact matches. I believe this is the culprit:
// current implementation:
deselect (start, end, priority) {
if (this.destroyed) throw new Error('torrent is destroyed')
priority = Number(priority) || 0
this._debug('deselect %s-%s (priority %s)', start, end, priority)
for (let i = 0; i < this._selections.length; ++i) {
const s = this._selections[i]
const isPieceInInterval = s.from >= from && s.to <= to
if (s.from === start && s.to === end && s.priority === priority) {
this._selections.splice(i, 1)
break
}
}
this._updateSelections()
}
Is this intentional? I have a couple of questions about this method:
- Why is the
priority
argument necessary here? Don't we just want to remove the given selections? I don't see why knowing its current priority is necessary. - Why are we only matching exact selections? Wouldn't it make more sense to remove every selection item that falls into the given from-to interval?
I believe this could be the partial cause of the "file.deselect supposedly not working" issue (#164)
from webtorrent.
this was meant to be fixed in #2115, but alex has since abandoned it and noone has picked up the PR, feel free to fix it
from webtorrent.
@ThaUnknown Thanks for pointing me in the right direction.
I opened a draft PR with a solution that I came up with. Could you or any other maintainers/contributers check it out?
I'm mainly looking for feedback on it atm, since I'm a first time contributer, so I'm looking for holes in my implementation.
Your feedback would be greatly appreciated 🙂
from webtorrent.
Related Issues (20)
- [Vite] Build failed: No matching export HOT 6
- How to use webtorrent to implement distributed caching of static resources in Service Worker, so as to improve the access efficiency of static resources
- High availability of servers HOT 1
- uncaught type error: file appendTo is not a function. HOT 2
- Want to ADD CODE_OF_CONDUCT.md file HOT 3
- import doesn't work from typescript project HOT 1
- Web Socket Connection Fails: Video is loading indefinitely without streaming HOT 2
- Error: write ENOTSUP HOT 1
- Create Navbar for small devices HOT 2
- `add` and `remove` are not async safe HOT 6
- no reasonable clean way to get a timeout on add HOT 1
- Use prettier for easier collaboration HOT 3
- Webtorrent does'nt work for torrents other than the example one. HOT 1
- Prioritize subtitle dowload. HOT 1
- The Docs Need to be UPDATE. HOT 1
- Most urls are broken! HOT 1
- All Torrents stop at exactly 2.8 GB HOT 1
- Uncaught Error: Can only pipe to one destination HOT 2
- Extend to allow standard websockets HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webtorrent.