MetadataExchange

Fetch a torrent's metadata (the info dict) from a peer over BEP-9 (ut_metadata), negotiated via the BEP-10 extension handshake. This is how a download starts from a magnet link, where we have only the info-hash. Port of libtorrent's ut_metadata plugin driving metadata_transfer.

The owning pc must already have completed the BitTorrent handshake with the extension bit set, and must have been created with numPieces = 0, because we do not know the piece count until the metadata arrives. PeerConnection tolerates an unknown-size bitfield in that mode.

Constructors

Link copied to clipboard
constructor(pc: PeerConnection, infoHash: Digest32)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun fetch(timeoutMillis: Long): ByteArray?

Run the exchange and return the raw, verified info-dict bytes (whose SHA-1, or SHA-256 for a v2 hash, equals infoHash), or null if the peer can't/won't provide them within timeoutMillis.