UtMetadata
BEP-9 "Extension for Peers to Send Metadata Files" (ut_metadata). This is the pure message codec, ported from libtorrent's ut_metadata.cpp (src/ut_metadata.cpp, ut_metadata_peer_plugin::write_metadata_packet and on_extended).
The metadata that this protocol exchanges is the bencoded info dictionary of a torrent (the same bytes whose SHA-1 is the v1 info-hash). It is sliced into 16 KiB pieces and pulled from peers a piece at a time.
Wire format
An ut_metadata message is the payload of a BEP-10 extended message (id 20) carried under the extension id the remote peer advertised for ut_metadata in its extension handshake. That payload is:
<bencode dict>[<raw 16 KiB metadata piece>]The bencode dict always has:
msg_type: 0 = request, 1 = data, 2 = rejectpiece: the 0-based 16 KiB piece index
and, for a data message, also:
total_size: the total length in bytes of the whole metadata (info) blob.
For a data message the raw bytes of that one piece are appended after the bencode dict (this is why a plain bdecode of the buffer stops at the end of the dict, because the trailing bytes are the payload). libtorrent recovers them with body.subspan(msg.data_section().size()), i.e. everything past the bencoded dict; parse does the same using BdecodeNode.dataSection.
This class is the codec only. The request scheduling and rate limiting that the C++ peer plugin adds lives elsewhere. MetadataTransfer is the small reassembly + verification helper.
Types
Properties
Functions
Encode a reject (dont_have) message: d8:msg_typei2e5:piecei<n>ee.
Encode a request message: d8:msg_typei0e5:piecei<n>ee.
Parse a ut_metadata message payload (the body of the extended message, not including the 4-byte length / id-20 / extended-id wire framing).
Number of 16 KiB pieces needed to carry a metadata blob of totalSize bytes.