I write BitTorrent client and right now I'm dealing with bitfield messages. The bitfield message looks like below:
<len=0001+X><id=5><bitfield>
The problem is that the len is always the same while the actual length of message is always different. Here's my python code:
message = self.recv(4096)
print(len(message)) #prints different numbers every time
current_msg_len = struct.unpack('!I', message[:4])[0]
print(current_msg_len) #always prints the same number
I am using TCP and I know that I can get incomplete message, but after handshake and bitfield there are no any messages coming in. An example of the received message:
[0, 0, 0, 95, 5, 255, 255, 255, 255, 254, 254, 255, 239, 255, 255, 255, 255, 255, 255, 255, 255, 247, 253, 255]