На странице спецификации протокола BitTorrent
, сказано, что сообщение рукопожатия, должно быть отправлено первым, после подключения. И указано следущяя структура этого сообщения:
Handshake
The handshake is a required message and must be the first message transmitted by the client. It is (49+len(pstr)) bytes long.
handshake: <pstrlen><pstr><reserved><info_hash><peer_id>
pstrlen: string length of , as a single raw byte
pstr: string identifier of the protocol
- reserved: eight (8) reserved bytes. All current implementations use all zeroes. Each bit in these bytes can be used to change the behavior of the protocol. An email from Bram suggests that trailing bits should be used first, so that leading bits may be used to change the meaning of trailing bits.
- info_hash: 20-byte SHA1 hash of the info key in the metainfo file. This is the same info_hash that is transmitted in tracker requests.
- peer_id: 20-byte string used as a unique ID for the client. This is usually the same peer_id that is transmitted in tracker requests (but not always e.g. an anonymity option in Azureus).
Так вот, я подумал что сообщение должно формироваться следущим образом:
const string protocol = "BitTorrent protocol";
string request = $"<{protocol.Length}>" + // <pstrlen>
$"<{protocol}>" + // <pstr>
"< >" + // <reserved>
$"<{torrentFile.GetInfoHash()}>" + // <info_hash>
"<-AZ206088->"; // <peer_id>
Однако это не работает, т.к. при отправке сообщения одному из пиров, он не отвечает, т.е. не шлет в ответ ничего, думаю я не правильно сформировал сообщение рукопожатия.
Как правильно сформировать сообщение?
pstrlen
должен быть передан какsingle raw byte
, а Вы строку пихаете