BitTorrent Protocol with Java - Bitfield after a successful handshake

After successfully sending and receiving handshakes from several peers, the next step in the BitTorrent message chain is a bitfield message .

The bitfield message is as follows: the top line explains the byte size of the protocol segments:

<4-bytes><1-byte><x-bytes>
<nrOfBits><identifier><bits>

The problem is that almost all peers seem to send bitfield messages that are different from the above view! Messages tend to look like this:

size: 332, [0, 0, 0, 112, 5, 127, -1, -1, -1, -1, -5, -1, -1, -1, -1, -1, -17...]

The first problem is that most of the messages I receive have bytes in length:

 [0, 0, 0, 112]

332 , 80 .

, -1 - .

, , .

+4
1

№ 1:

TCP, , , , . . . , 332 , , . -- ( , ). [0,0,0,112], 4 + 1 + 111 (4 , 111 ). . 116 .

: uTP, UTorrent UDP, , UDP.

№ 2:

, , , java ( ). -128 127, , ( ), java . , - 8 ( 11111111), -1, 11111111 -1 . ( - Integer.toHexString(myByte & 0xff)).

: , , Java BitTorrent. , , , , , .

+4

Source: https://habr.com/ru/post/1568611/


All Articles