Having successfully sent and received handshakes from multiple peers, the next step in the BitTorrent message chain is the bitfield message.
The bitfield message looks like below, where the top line explainins the byte-size of the protocol segments:
<4-bytes><1-byte><x-bytes>
<nrOfBits><identifier><bits>
The problem I have is that nearly all peers seem to be sending bitfield messages that differ from the above representation! The 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 the majority of the messages I receive have length bytes:
[0, 0, 0, 112]
even though the received message in this case contains 332 bytes in total, while at some other instances the message may only be 80 bytes or so.
The second problem is that the bits usually are repeating -1 or some other strange negative value..
I don't think this can be attributed to low-level encoding problems on my side however, since other messages works fine..