performHandshake

Perform the BitTorrent handshake: write our 68-byte handshake, then read and validate the peer's. Ports write_handshake() (the send) and the read_info_hash / read_peer_id arms of on_receive (the receive + validation), collapsed into one suspending exchange.

We always send first regardless of which side dialed. For an outgoing connection libtorrent sends in the constructor; for incoming it sends after reading the info-hash (if (!is_outgoing()) write_handshake()). Sending first unconditionally is wire-equivalent for the plain (non-encrypted) protocol and lets the peer validate our info-hash in parallel.

Validation mirrors the C++: the decoded protocol string must be "BitTorrent protocol" (Handshake.decode enforces this), the info-hash must equal infoHash, and a torrent with an all-zero info-hash is rejected (the associated_info_hash().is_all_zeros() guard).

Return

the validated remote handshake (peer-id + reserved capability bytes).

Throws

if the peer is not speaking BitTorrent, the info-hash does not match, or our own info-hash is all zeros.