parsing BEP9(ut_metadata) data message

347 Views Asked by At

BEP9(ut_metadata) data message has a total_size field and I'm having trouble seeing what it means.

The message is in this format:

<4-byte length prefix><20><1-byte extended msg id><bencode part><piece data>

I'm confused about two things:

  1. Does length-prefix include <piece data> part?
  2. What does total_size field in bencode_part specify?

It looks to me like we don't need total_size, unless I'm misunderstanding something.

Here is currently how I'm parsing it:

  • Length prefix includes <piece data> so I know exactly how big this message is. I'm reading that many bytes.
  • After parsing <bencode_part>, I'm just consuming rest of the bytes and consider this the data.

Can anyone help me understanding this format?

Thanks.

1

There are 1 best solutions below

5
the8472 On BEST ANSWER
  1. yes
  2. the total length of the info section of the .torrent file. The metadata may be transferred in multiple chunks if they are too big for a single message.