anacrolix / torrent

Full-featured BitTorrent client package and utilities
Mozilla Public License 2.0
5.39k stars 615 forks source link

fix: torrent file real time completed bytes #852

Closed monkeyWie closed 11 months ago

monkeyWie commented 11 months ago

fixed https://github.com/anacrolix/torrent/issues/851.

anacrolix commented 11 months ago

Thanks for the contribution. This really needs some tests. I'm also not sure about allocating a roaring bitmap to perform this. Are we sure there's not just a simple error in the existing function?

anacrolix commented 11 months ago

I've had time to think about this carefully. This is a pretty good solution. On the boundary pieces, it is actually possible to figure out if dirty chunks belong to the file or not. I see that you don't do this, but you do apply a limit to ensure that the dirty chunk attribution doesn't exceed the amount of the file that is inside the boundary piece. It would take me quite a while to patch it up to handle the chunk attribution to be 100% correct, so I will merge this as you have it, and accept or add the last mile if it comes up again.

I do note the existing tests don't do any special dirty chunk treatment, it would be nice to augment the tests a bit to handle this too.