ExtensionHandshake

The BEP-10 extension-protocol handshake: the bencoded dict exchanged as extended message id 0 right after the BitTorrent handshake (when the extension reserved bit is set). Port of libtorrent's bt_peer_connection::write_extensions / parse_extensions.

The m dict maps extension names → the message id the sender wants the peer to use when sending it that extension. So when we receive a peer's handshake, m["ut_metadata"] is the id WE must put on extended messages we send them; the ids in build are the ones we ask them to use toward us.

Types

Link copied to clipboard
data class Parsed(val utMetadataId: Int?, val utPexId: Int?, val metadataSize: Long?, val clientVersion: String?)

A peer's parsed handshake: the ids to use toward them + the metadata size they reported.

Properties

Link copied to clipboard
const val HANDSHAKE_ID: Int = 0

extended message id reserved for the handshake itself.

Link copied to clipboard
const val UT_METADATA_ID: Int = 1

Ids we advertise for peers to use when sending these extensions to us.

Link copied to clipboard
const val UT_PEX_ID: Int = 2

Functions

Link copied to clipboard
fun build(metadataSize: Long? = null, clientVersion: String = "KiteTorrent", listenPort: Int? = null, supportUtPex: Boolean = true): ByteArray

Build our handshake payload. metadataSize is included only when we know the info size.

Link copied to clipboard