TorrentInfo

A parsed .torrent file. This is the pure-Kotlin counterpart of libtorrent's torrent_info (torrent_info.cpp). Built from the bencoded bytes of a torrent, it exposes the metadata a client needs: the name, the file list, piece geometry, the trackers, and the info-hash or hashes.

The info-hash is SHA-1(info-dict) for v1 (BEP 3) and SHA-256(info-dict) for v2 (BEP 52); a hybrid torrent has both. Because BdecodeNode.dataSection returns the exact bytes the info dictionary was parsed from, the hash is computed over the original bytes and is byte-for-byte identical to every other client's.

v1 (and the v1 side of hybrid torrents) is fully parsed. Pure-v2 file trees are parsed for their file list and per-file merkle roots. This class does not fold the piece layers back to each file's root, so it accepts a .torrent whose piece layers disagree with its file tree.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The announce tiers (BEP-12), preserved: each inner list is one tier, tried in order. This is the same backing data as trackers; exposed under the libtorrent-aligned name to make the tier structure explicit and to discourage flattening at parse time.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Creation time as a Unix timestamp (seconds), or null.

Link copied to clipboard

DHT bootstrap nodes (nodes): host/port pairs.

Link copied to clipboard
Link copied to clipboard

The exact bytes of the info dictionary. This is the info-hash preimage, and what ut_metadata serves to magnet peers.

Link copied to clipboard

v1 info-hash (SHA-1 of the info dict), or null for a pure-v2 torrent.

Link copied to clipboard

v2 info-hash (SHA-256 of the info dict), or null for a v1-only torrent.

Link copied to clipboard
Link copied to clipboard

True if the torrent is marked private (no DHT/PEX).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Bencode meta version (2 for v2/hybrid, 1 for classic v1).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The files and piece geometry.

Link copied to clipboard
Link copied to clipboard

Tracker tiers (BEP 12 announce-list); each inner list is a tier.

Link copied to clipboard

BEP 19 web seeds (url-list).

Functions

Link copied to clipboard

A flat list of every tracker URL across all tiers (back-compat convenience).

Link copied to clipboard

The canonical info-hash hex for display/lookups: the v2 hash when present (it's the stronger identity), otherwise the v1 hash.

Link copied to clipboard

For a v2 / hybrid torrent, checks the BEP-52 layout invariant that every file (except the last) begins on a piece boundary. Pad files in a hybrid v1 list, and the v2 file tree's natural per-file trees, are supposed to enforce this. Returns true for v1-only torrents (the invariant does not apply) and for an empty/degenerate layout.

Link copied to clipboard
fun pieceHashV1(index: Int): Sha1Hash?

The v1 SHA-1 hash for piece index, sliced from the pieces blob.

Link copied to clipboard
fun pieceHashV2(index: Int): Sha256Hash?

The v2 piece hash: the merkle root of piece index's 16 KiB block leaves. This is the verification target for a v2 download. It comes from the piece layers, except for a file that fits in a single piece, where the file's own merkle root is the piece hash.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

The 20-byte info-hash used on the wire (the BitTorrent handshake / peer routing): the v1 hash when present, otherwise the v2 SHA-256 truncated to 20 bytes, exactly as libtorrent forms the handshake hash for a v2-only torrent.