buildHashRequest

Builds the PeerMessage.HashRequest needed to obtain the piece-layer hashes for the file that owns piece, or null when no request is warranted (needHashes is false, or a request for this file is already outstanding). On success the file is marked as having an outstanding request until onHashes or onHashReject is called for it.

The request covers the file's entire piece layer (index = 0, length = numPieces of the file rounded up to a power of two), anchored to the file root with the right number of proofLayers. This is libtorrent's standard piece-layer request shape.

Wire fields (mirroring libtorrent's hash_request):

  • piecesRoot: the file's 32-byte v2 root (identifies the file on the wire),

  • baseLayer: number of tree layers between the block leaves and the piece layer (log2(blocksPerPiece)), i.e. the piece layer expressed as a base,

  • index: offset within the piece layer (0 means the whole layer),

  • length: count of piece-layer hashes requested,

  • proofLayers: uncle hashes needed to fold up to the root.