osa1
osa1

Reputation: 7078

BitTorrent protocol: Why am I getting extra data with handshakes?

I'm implementing a BitTorrent client and I'm having trouble handling incoming handshake messages.

Even if I set all the reserved bytes to 0(to indicate that I don't support any extensions), I'm getting a lot of data attached to handshake messages. For example:

[2014-11-21 13:41:30 EET : Rho.PeerComms : WARNING] Extra message: [0,0,0,52,5,255,255,255,255,255,255,255,255,247,255,251,247,238,191,239,253,253,255,247,191,223,239]
[2014-11-21 13:41:33 EET : Rho.PeerComms : WARNING] Extra message: [0,0,0,52,5,255,255,255,127,255,255,254,255,253,255,255,255,255,255,255,253]
[2014-11-21 13:41:37 EET : Rho.PeerComms : WARNING] Extra message: [0,0,0,52,5,255,127,239,255,255,253,255,255,255,255,251,255,255,223,251,95,127,255,255,255,255,127,255,183,255,253,255,251,239,253,252,239,223,247,255,255,255]
[2014-11-21 13:41:37 EET : Rho.PeerComms : WARNING] Extra message: [0,0,0,52,5,254,255,255,247,255,255,255,255,255,255,235,255,255,63,127,255,239,127,255,255,239,255,239,255,223,254,255,255,255,255,255,255,251,251,255,255,127,255,249,255,239,255,191,191,255,255,239,191,255,247,252,0,0,0,5,4,0,0,1,121,0,0,0,5,4,0,0,0,105,0,0,0,5,4,0,0,0,207,0,0,0,5,4,0,0,0,104,0,0,0,5,4,0,0,0,85,0,0,0,5,4,0,0,1,32,0,0,0,5,4,0,0,1,53,0,0,0,5,4,0,0,1,67,0,0,0,5,4,0,0,0,131,0,0,0,5,4,0,0,0,136,0,0,0,5,4,0,0,1,140,0,0,0,5,4,0,0,1,89,0,0,0,5,4,0,0,1,54,0,0,0,5,4,0,0,1,81,0,0,0,5,4,0,0,0,83,0,0,0,5,4,0,0,1,5,0,0,0,5,4,0,0,0,112,0,0,0,5,4,0,0,1,13,0,0,0,5,4,0,0,0,7,0,0,0,5,4,0,0,0,194,0,0,0,5,4,0,0,0,28,0,0,0,5,4,0,0,0,179,0,0,0,5,4,0,0,0,163,0,0,0,5,4,0,0,1,115]
[2014-11-21 13:41:40 EET : Rho.PeerComms : WARNING] Extra message: [0,0,0,52,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252]

Those are data after handshake messages. E.g.: <pstrlen><pstr><reserved><info_hash><peer_id><extra> extra part in this message format.

Any ideas what are those, how should I use them and why am I getting them?

Thanks.

Upvotes: 1

Views: 144

Answers (1)

the8472
the8472

Reputation: 43052

0,0,0,52 4 byte message length

,5 message ID

Specified as "bitfield" in BEP3. I.e. this is part of the core bittorrent protocol and should be expected even without extensions.

The output seems to be inaccurate though since those arrays are of variable lengths despite the indicated size being the same for each line. So it's possible that the bytestream parser does not correctly slice messages based on length.

Upvotes: 1

Related Questions