DownloadingPiece
Tracks block allocations for a single piece that is currently being downloaded. This is the port of piece_picker::downloading_piece.
libtorrent stores the per-block BlockInfo objects in one big flat pool (m_block_info) indexed via info_idx * blocks_per_piece; that's a memory micro-optimization. We keep the (semantically identical) blocks array inline, which is simpler and just as correct.
The finished / writing / requested counters are redundant caches of the states in blocks (kept in sync on every mutation) so the picker can classify the piece's download-queue bucket in O(1).
Properties
Number of blocks in BlockState.FINISHED.
When set, no blocks from this piece may be picked. Used while synchronizing with the disk thread after a hash-failure or write-failure, until PiecePicker.restorePiece clears it.
Set once the piece's hash has been verified. The piece may not be "had" yet because the last block might still be flushing to disk.
Number of blocks in BlockState.REQUESTED.
Number of blocks in BlockState.WRITING.