root / dotorg / trunk / html / beps / bep_0009.rst

Revision 11056, 4.7 kB (checked in by greg, 7 days ago)

hex encoded info-hash

Line 
1BEP: 9
2Title: Extension for Peers to Send Metadata Files
3Version: $Revision$
4Last-Modified: $Date$
5Author:  Greg Hazel <greg@bittorrent.com>, Arvid Norberg <arvid@bittorrent.com>
6Status:  Draft
7Type:    Standards Track
8Created: 31-Jan-2008
9Post-History:
10
11The purpose of this extension is to allow clients to join a swarm and
12complete a download without the need of downloading a .torrent file
13first. This extension instead allows clients to download the metadata
14from peers. It makes it possible to support *magnet links*, a link
15on a web page only containing enough information to join the swarm
16(the info hash).
17
18metadata
19========
20
21This extension only transfers the info-dictionary part of the .torrent
22file. This part can be validated by the info-hash. In this document, that
23part of the .torrent file is referred to as *the metadata*.
24
25The metadata is handled in blocks of 16KiB (16384 Bytes). The metadata blocks
26are indexed starting at 0. All blocks are 16KiB except the last block which may
27be smaller.
28
29extension header
30================
31
32The metadata extension uses the extension protocol (specified in `BEP 0010`_
33) to advertize its existence. It adds the "ut_metadata" entry to the "m"
34dictionary in the extension header hand-shake message. This identifies the
35message code used for this message. It also adds "metadata_size" to the
36handshake message (not the "m" dictionary) specifying an integer value of the
37number of bytes of the metadata.
38
39Example extension handshake message::
40
41{'m': {'ut_metadata', 3}, 'metadata_size': 31235}
42
43
44extension message
45=================
46
47The extension messages are bencoded. There are 3 different kinds of messages:
48
490. request
501. data
512. reject
52
53The bencoded messages have a key "msg_type" which value is an integer
54corresponding to the type of message. They also have a key "piece", which
55indicates which part of the metadata this message refers to.
56
57request
58-------
59
60The ``request`` message does not have any additional keys in the dictionary.
61The response to this message, from a peer supporting the extension, is either
62a ``reject`` or a ``data`` message. The response MUST have the same ``piece``
63as the request did.
64
65A peer MUST verify that any piece it sends passes the info-hash verification.
66i.e. until the peer has the entire metadata, it cannot run SHA-1 to verify that
67it yields the same hash as the info-hash. Peers that do not have the entire
68metadata MUST respond with a ``reject`` message to any metadata request.
69
70Example::
71
72        {'msg_type': 0, 'piece': 0}
73        d8:msg_typei0e5:piecei0ee
74
75That request message requests the first metadata piece.
76
77data
78----
79
80The ``data`` message adds another entry to the dictionary, "total_size". This
81key has the same semantics as the "metadata_size" in the extension header. This
82is an integer.
83
84The metadata piece is appended to the bencoded dictionary, it is not a part of
85the dictionary, but it is a part of the message (the length prefix MUST include it).
86
87If the piece is the last piece of the metadata, it may be less than 16kiB. If it
88is not the last piece of the metadata, it MUST be 16kiB.
89
90Example::
91
92        {'msg_type': 1, 'piece': 0, 'total_size': 3425}
93        d8:msg_typei1e5:piecei0e10:total_sizei34256eexxxxxxxx...
94
95The ``x`` represents binary data (the metadata).
96
97reject
98------
99
100The ``reject`` message does not have any additional keys in its message.
101It SHOULD be interpreted as the peer does not have the piece of metadata
102that was requested.
103
104Clients MAY implement flood protection by rejecting ``request`` messages
105after a certain number of them have been served. Typically the number of
106pieces of metadata times a factor.
107
108Example::
109
110        {'msg_type': 2, 'piece': 0}
111        d8:msg_typei1e5:piecei0ee
112
113magnet URI format
114=================
115
116The magnet URI format is::
117
118        magnet:?xt=urn:btih:<info-hash>&dn=<name>&tr=<tracker-url>
119
120<info-hash>
121        Is the info-hash hex encoded, for a total of 40 characters. For
122        compatability with existing links in the wild, clients should also
123        support the 32 character `base32`_ encoded info-hash.
124
125``xt`` is the only mandatory parameter. ``dn`` is the display name that may be
126used by the client to display while waiting for metadata. ``tr`` is a tracker
127url, if there is one. If there are multiple trackers, multiple ``tr`` entries
128may be included.
129
130Both ``dn`` and ``tr`` are optional.
131
132If no tracker is specified, the client SHOULD use the DHT (`BEP 0005`_) to acquire peers.
133
134References
135==========
136
137.. _`base32`: http://www.ietf.org/rfc/rfc3548.txt
138.. _`BEP 0010`: http://www.bittorrent.org/beps/bep_0010.html
139.. _`BEP 0005`: http://www.bittorrent.org/beps/bep_0005.html
140
141
142Copyright
143=========
144
145This document has been placed in the public domain.
146
147
148..
149   Local Variables:
150   mode: indented-text
151   indent-tabs-mode: nil
152   sentence-end-double-space: t
153   fill-column: 70
154   coding: utf-8
155   End:
Note: See TracBrowser for help on using the browser.