I am studying the file transfer using bittorrent protocol and is interested to know whether the piece index
associated with each piece has any significance in the rearrangement of the pieces. Howe is this piece index
assigned? Also is their some other way apart from using the hash value in .torrent
file to rearrange the pieces?
Significance of piece index in bittorrent file transfer?
994 Views Asked by Jackzz At
1
The relevant meta information
The metadata of a torrent includes sufficient information to reassemble and verify the data the torrent describes regardless of the order the data arrives. The full definition can be found here, and for your question there are some important parts.
and
and
and finally
The result
Taken all together. There is an assumption that the underlying data that a .torrent describes is in order from piece 0 to piece NumPieces. All of the pieces will be exactly the same length, expect for possibly the last one and thus the piece_index X piece_size will give the offset in bytes from the beginning to where that piece fits in the data. Multiple files are treated as if they're all concatenated together. Each piece hash is located at piece_index X 20 bytes from the beginning of pieces. Now since pieces is located in the info section, if you rearrange the pieces by changing their index, this will change the SHA1 hash of the info section and thus the infoHash, which changes the torrent. This is by design so the authenticity of the data is can be validated. Practically speaking, it would be impossible to forge or accidentally reassemble pieces in the wrong order because the infoHash is the final check that pieces is correct and pieces is the check that the data is correct.