Handshake
The fixed BitTorrent peer-protocol handshake. This is the pure-Kotlin port of bt_peer_connection::write_handshake() (src/bt_peer_connection.cpp) and the receive-side parsing in bt_peer_connection::on_receive/recv_handshake.
Defined by BEP-3. The wire layout is exactly 68 bytes:
<pstrlen=19><pstr="BitTorrent protocol"><8 reserved bytes><20-byte info_hash><20-byte peer_id>
1 + 19 + 8 + 20 + 20 = 68The 8 reserved bytes carry capability flags negotiated by ANDing the two peers' reserved blocks. libtorrent sets, in write_handshake():
reserved[7] |= 0x01: DHT support (BEP-5),reserved[7] |= 0x04: Fast extension (BEP-6),reserved[5] |= 0x10: Extension protocol (BEP-10),reserved[7] |= 0x10: v2 upgrade (BEP-52), set only for a v1 peer in a hybrid torrent to advertise willingness to upgrade to the v2 protocol.
(reserved[7] is the last byte; reserved[5] is the 6th byte / index 5.)
Constructors
Properties
True if the peer set the DHT bit (reserved[7] & 0x01, BEP-5).
True if the peer set the extension-protocol bit (reserved[5] & 0x10, BEP-10).
True if the peer set the Fast-extension bit (reserved[7] & 0x04, BEP-6).
True if the peer set the v2-upgrade bit (reserved[7] & 0x10, BEP-52). For a v1 connection this signals the peer is willing to upgrade to the BitTorrent v2 protocol on a hybrid torrent.