user3731619
user3731619

Reputation: 71

Torrent handshake response is larger than 68 bytes

I am attempting to create my own Torrent client using the bit torrent protocol. I am currently at the stage where I can get a peer list from a tracker and get the IP and port of a peer.

The problem begins after I send the handshake message to the peer. I've followed the instructions and sent a handshake message of 68 bytes with the hash, a client id etc.

I get a response from the peer that is 370 bytes rather than the expected 68 byte handshake. When I parse the first 68 bytes of the response it resembles a handshake response. It has the same hash, a client id etc. However I don't have a clue what the remaining 302 bytes are. Is this normal?

Is there any documentation that clearly explains this? I am unable to find any information to help with this situation. The bit torrent protocol spec is vague to say the least.

This is the response I receive converted to string

\u0013BitTorrent protocol\0\0\0\0\0\u0010\0\u00051O???6H*\u00118$??U\r*?:?d-UT354S-X?\u001b\u0001???rwQ\t?\0\0\0R\u0005?????????????????????????????????????\u07ff??????????????????????????????????????????\0\0\0\u0005\u0004\0\0\u0002\"\0\0\0\u0005\u0004\0\0\0T\0\0\0\u0005\u0004\0\0\0?\0\0\0\u0005\u0004\0\0\0?\0\0\0\u0005\u0004\0\0\0?\0\0\0\u0005\u0004\0\0\05\0\0\0\u0005\u0004\0\0\0\t\0\0\0\u0005\u0004\0\0\u0001Z\0\0\0\u0005\u0004\0\0\u00025\0\0\0\u0005\u0004\0\0\u0001*\0\0\0\u0005\u0004\0\0\0y\0\0\0\u0005\u0004\0\0\u0001I\0\0\0\u0005\u0004\0\0\u0002G\0\0\0\u0005\u0004\0\0\u0001?\0\0\0\u0005\u0004\0\0\0\u0001\0\0\0\u0005\u0004\0\0\u0002\f\0\0\0\u0005\u0004\0\0\u0001?\0\0\0\u0005\u0004\0\0\0?\0\0\0\u0005\u0004\0\0\0?\0\0\0\u0005\u0004\0\0\u00011\0\0\0\u0005\u0004\0\0\u0001W\0\0\0\u0005\u0004\0\0\0\u0016\0\0\0\u0005\u0004\0\0\0?\0\0\0\u0005\u0004\0\0\u0001?

The first 68 bytes are what I expected, the remaining 302 bytes I have no idea about

Upvotes: 3

Views: 249

Answers (1)

user3731619
user3731619

Reputation: 71

I've now realised what these extra bytes are.

They are a bitfield and multiple have messages! My issues was not realising this information can be sent immediately after the handshake

Upvotes: 4

Related Questions