Reputation: 3284
I want to cache torrent blocks based on their content hash. In v2 instead of simple block hashes there's a merkle tree, whose exact composition I can't quite comprehend.
I am working with MonoTorrent library, and it has IPieceHashes.GetHash(hashIndex)
function where hashIndex
varies from from 0 to piece count - 1. But there's no similar function to get hash of individual blocks (in case piece consists of multiple blocks).
Upvotes: 0
Views: 105
Reputation: 43125
In v2 the easiest way to obtain them is to download a whole piece instead of a chunk, compute the leaf hashes from the data you have received and then verify the leaf hashes against the piece layers
in the .torrent
metadata file.
Alternatively you can hash request
the leaf hashes while downloading chunks from a peer and verify them against the file root.
Both approaches involve merkle tree verification.
In v1 you're limited to downloading a whole piece and verifying its hash against the pieces
list in the metadata file.
Upvotes: -1