DownloadingPiece

class DownloadingPiece(val index: Int, val blocks: Array<BlockInfo>)

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).

Constructors

Link copied to clipboard
constructor(index: Int, blocks: Array<BlockInfo>)

Properties

Link copied to clipboard

Per-block info; blocks.size == blocksInPiece(index).

Link copied to clipboard

Number of blocks in BlockState.FINISHED.

Link copied to clipboard

Set while there is an outstanding hash job for this piece (v2 torrents).

Link copied to clipboard
val index: Int

The piece index this entry describes.

Link copied to clipboard

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.

Link copied to clipboard

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.

Link copied to clipboard

Number of blocks in BlockState.REQUESTED.

Link copied to clipboard

Number of blocks in BlockState.WRITING.