root / dotorg / v3 / html / metadata_extension.rst

Revision 9921, 4.0 kB (checked in by arvid, 13 months ago)

added drafts for metadata extension and extension protocol

Line 
1metadata extension
2==================
3
4The purpose of this extension is to allow clients to join a swarm and
5complete a download without the need of downloading a .torrent file
6first. This extension instead allows clients to download the metadata
7from peers. It makes it possible to support *magnet links*, a link
8on a web page only containing enough information to join the swarm
9(the info hash).
10
11metadata
12--------
13
14This extension only transfers the info-dictionary part of the .torrent
15file. This part can be validated by the info-hash. In this document, that
16part of the .torrent file is referred to as *the metadata*.
17
18The metadata is plit up in 16kiB pieces. The pieces are indexed starting
19from 0 for the first 16kiB of metadata.
20
21extension header
22----------------
23
24The metadata extension uses the `extension protocol`_ to advertize its
25existence. It adds the "ut_metadata" entry to the "m" dictionary in the
26extension header hand-shake message. This identifies the message code
27used for this message. It also adds "metadata_size" to the handshake
28message (not the "m" dictionary) specifying an integer value of the
29number of bytes of the metadata.
30
31.. _`extension protocol`: extension_protocol.html
32
33Example extension handshake message::
34
35{'m': {'ut_metadata', 3}, 'metadata_size': 31235}
36
37
38extension message
39-----------------
40
41The extension messages are bencoded. There are 3 different kinds of messages:
42
430. request
441. data
452. reject
46
47The bencoded messages have a key "msg_type" which value is an integer
48corresponding to the type of message. They also have a key "piece", which
49indicates which part of the metadata this message refers to.
50
51request
52~~~~~~~
53
54The ``request`` message does not have any additional keys in the dictionary.
55The response to this message, from a peer supporting the extension, is either
56a ``reject`` or a ``data`` message. The response MUST have the same ``piece``
57as the request did.
58
59A peer MUST verify that any piece it sends passes the info-hash verification.
60i.e. until the peer has the entire metadata, it cannot run SHA-1 to verify that
61it yields the same hash as the info-hash. Peers that do not have the entire
62metadata MUST respond with a ``reject`` message to any metadata request.
63
64Example::
65
66        {'msg_type': 0, 'piece': 0}
67        d8:msg_typei0e5:piecei0ee
68
69That request message requests the first metadata piece.
70
71data
72~~~~
73
74The ``data`` message adds another entry to the dictionary, "total_size". This
75key has the same semantics as the "metadata_size" in the extension header. This
76is an integer.
77
78The metadata piece is appended to the bencoded dictionary, it is not a part of
79the dictionary, but it is a part of the message (the length prefix MUST include it).
80
81If the piece is the last piece of the metadata, it may be less than 16kiB. If it
82is not the last piece of the metadata, it MUST be 16kiB.
83
84Example::
85
86        {'msg_type': 1, 'piece': 0, 'total_size': 3425}
87        d8:msg_typei1e5:piecei0e10:total_sizei34256eexxxxxxxx...
88
89The ``x`` represents binary data (the metadata).
90
91reject
92~~~~~~
93
94The ``reject`` message does not have any additional keys in its message.
95It SHOULD be interpreted as the peer does not have the piece of metadata
96that was requested.
97
98Clients MAY implement flood protection by rejecting ``request`` messages
99after a certain number of them have been served. Typically the number of
100pieces of metadata times a factor.
101
102Example::
103
104        {'msg_type': 2, 'piece': 0}
105        d8:msg_typei1e5:piecei0ee
106
107magnet URI format
108-----------------
109
110The magnet URI format is::
111
112        magnet:?xt=urn:btih:<info-hash>&dn=<name>&tr=<tracker-url>
113
114<info-hash>
115        Is the info-hash encoded as base32.
116
117``xt`` is the only mandatory parameter. ``dn`` is the display name that may be
118used by the client to display while waiting for metadata. ``tr`` is a tracker
119url, if there is one. If there are multiple trackers, multiple ``tr`` entries
120may be included.
121
122Both ``dn`` and ``tr`` are optional.
123
124If no tracker is specified, the client SHOULD use the DHT to acquire peers.
125
126authors
127-------
128
129| `Greg Hazel`__
130| `Arvid Norberg`__
131
132.. __: mailto:greg@bittorrent.com
133.. __: mailto:arvid@bittorrent.com
Note: See TracBrowser for help on using the browser.