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