Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up`torrent.rescanFiles()` should detect missing pieces that were initially verified #1695
Comments
This comment has been minimized.
This comment has been minimized.
|
@jhiesey Do you have thoughts about this? |
This comment has been minimized.
This comment has been minimized.
|
The original reason for adding I agree that the naming is somewhat confusing, and it would better match expectations and be more useful if it also handled detecting data that went missing from the datastore. Should I see about implementing that? |
This comment has been minimized.
This comment has been minimized.
Only if you're interested. I still don't fully understand the root cause of the issue and haven't had time to dig in, and I want to understand more about what's involved to fix this before we commit to fixing it. |
This comment has been minimized.
This comment has been minimized.
|
For some context, I am proactively deleting chunks from indexedDB for reasons (business logic, avoid async function deletePieces(torrentId, pieceIndexes = []) {
// Stop active torrent
await new Promise(resolve => torrentClient.remove(torrentId, resolve))
// Deletes specified pieces of this torrent from indexedDB
await deletePiecesFromStore(torrentId, pieceIndexes)
// Re-add torrent to verify pieces
torrentClient.add(torrentId)
}This approach is wasteful, it destroys all state and connections. What I'd like to be able to do is this: async function deletePieces(torrentId, pieceIndexes = []) {
// Deletes specified pieces of this torrent from indexedDB
await deletePiecesFromStore(torrentId, pieceIndexes)
const torrent = torrentClient.get(torrentId)
torrent.rescanFiles()
}A detected missing piece should only be refetched if it was selected with OPTIONAL: Taking this further, we could add a new torrent method that deletes pieces and handles updating internal state ( async function deletePieces(torrentId, pieceIndexes = []) {
const torrent = torrentClient.get(torrentId)
for (const index of pieceIndexes) {
torrent.deletePiece(index)
}
} |
Related: #1650
What version of WebTorrent?
v0.107.0 (latest)
What did you expect to happen?
torrent.rescanFiles()(and by association_verifyPieces) should detect pieces that were previously verified but now missing, and rerequest them.What actually happened?
torrent.rescanFiles()doesn't do that.If a piece was verified on torrent initialization, then deleted, then
rescanFiles()is called, webtorrent should detect the missing piece and fetch it. After all, thats the point of verifying pieces, right?Currently, once a piece is verified, it stays verified even if
store.get(index)inside_verifyPieces()returns a missing chunk error. This is because state that tracks pieces (torrent.bitfield,torrent.pieces,torrent._hashes,torrent._reservations) doesn't react to changes in the underlying storage. I believe Webtorrent should be robust enough to handle unreliable storage, such as indexedDB, where a user or script can delete pieces at will.At a high level, once
_verifyPieces()is called, the torrent should be aware of what pieces are actually verified and react accordingly.