-
I was reading BEP 3, more specifically the following part:
I know that the metainfo of a torrent contains the hash of every single piece of data in the torrent. In case of a single file torrent, all pieces refer to the same (and only) file, but in case of multiple files some pieces may refer to more than one file. For example, for a torrent with a piece length of 16KiB and two files of sizes 15KiB and 1KiB respectively, you will have only one hash corresponding to both files (as their combined size is exactly one piece length). The same reasoning of course applies with different file sizes, e.g. [1KiB, 15KiB], [1KiB, 1KiB, ..., 1KiB] and so on. This made me curious: suppose I only want to download the second file and therefore skip the first (its priority is set to "don't download"). How would libtorrent perform a check (or re-check) of the first file in such case? Are some special padding files created for this purpose where unwanted data is stored only as a way to correctly calculate the hash of the piece? Is the missing part of the piece re-downloaded (I assume not)? I browsed the code for a bit, but since I am not familiar with the codebase and its abstractions I couldn't find a specific function whose code could easily answer my question, so I thought I might as well ask here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
the short answer is that libtorrent would download both files in order to validate the hash, but the unwanted file would be tucked-away in a part-file. The slightly longer answer is that libtorrent only downloads at piece granularity. The more common case is that the only "unwanted" data that's downloaded is a partial piece at the start and end of the file set to be downloaded. These partial pieces are stored in the part-file. Keeping them around is important to be able to offer them to other peers that also want to download the file you downloaded. They will also need those "unwanted" parts in order to validated the piece hashes. |
Beta Was this translation helpful? Give feedback.
the short answer is that libtorrent would download both files in order to validate the hash, but the unwanted file would be tucked-away in a part-file.
The slightly longer answer is that libtorrent only downloads at piece granularity. The more common case is that the only "unwanted" data that's downloaded is a partial piece at the start and end of the file set to be downloaded. These partial pieces are stored in the part-file. Keeping them around is important to be able to offer them to other peers that also want to download the file you downloaded. They will also need those "unwanted" parts in order to validated the piece hashes.