Changeset 10528 for dotorg/trunk_fixed/html/beps/bep_0003.rst
- Timestamp:
- 02/04/08 16:10:30 (22 months ago)
- Files:
-
- 1 modified
-
dotorg/trunk_fixed/html/beps/bep_0003.rst (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dotorg/trunk_fixed/html/beps/bep_0003.rst
r10524 r10528 1 BEP: 21 BEP: 3 2 2 Title: The BitTorrent Protocol Specification 3 Version: 24 Last-Modified: 11-Jan-20083 Version: $Revision$ 4 Last-Modified: $Date$ 5 5 Author: Bram Cohen <bram@bittorrent.com> 6 6 Status: Final … … 52 52 ------------------------------- 53 53 54 - Strings are length-prefixed base ten followed by a colon and the string. For example <code>4:spam</code>corresponds to 'spam'.54 - Strings are length-prefixed base ten followed by a colon and the string. For example ``4:spam`` corresponds to 'spam'. 55 55 56 56 - Integers are represented by an 'i' followed by the number in base 10 57 followed by an 'e'. For example <code>i3e</code>corresponds to 3 and58 <code>i-3e </code>corresponds to -3. Integers have no size59 limitation. <code>i-0e</code>is invalid. All encodings with a leading60 zero, such as <code>i03e</code>, are invalid, other than61 <code>i0e</code>, which of course corresponds to 0.57 followed by an 'e'. For example ``i3e`` corresponds to 3 and 58 ``i-3e`` corresponds to -3. Integers have no size 59 limitation. ``i-0e`` is invalid. All encodings with a leading 60 zero, such as ``i03e``, are invalid, other than 61 ``i0e``, which of course corresponds to 0. 62 62 63 63 - Lists are encoded as an 'l' followed by their elements (also 64 bencoded) followed by an 'e'. For example <code>l4:spam4:eggse</code>64 bencoded) followed by an 'e'. For example ``l4:spam4:eggse`` 65 65 corresponds to ['spam', 'eggs']. 66 66 67 67 - Dictionaries are encoded as a 'd' followed by a list of alternating 68 68 keys and their corresponding values followed by an 'e'. For example, 69 <code>d3:cow3:moo4:spam4:eggse</code>corresponds to {'cow': 'moo',70 'spam': 'eggs'} and <code>d4:spaml1:a1:bee</code>corresponds to69 ``d3:cow3:moo4:spam4:eggse`` corresponds to {'cow': 'moo', 70 'spam': 'eggs'} and ``d4:spaml1:a1:bee`` corresponds to 71 71 {'spam': ['a', 'b']}. Keys must be strings and appear in sorted order 72 72 (sorted as raw strings, not alphanumerics). … … 82 82 This maps to a dictionary, with keys described below. 83 83 84 The <code>name</code>key maps to a string which is the suggested name84 The ``name`` key maps to a string which is the suggested name 85 85 to save the file (or directory) as. It is purely advisory. 86 86 87 <code>piece length</code>maps to the number of bytes in each piece87 ``piece length`` maps to the number of bytes in each piece 88 88 the file is split into. For the purposes of transfer, files are 89 89 split into fixed-size pieces which are all the same length except for 90 possibly the last one which may be truncated. <code>piece91 length </code>is almost always a power of two, most commonly 2 18 =90 possibly the last one which may be truncated. ``piece 91 length`` is almost always a power of two, most commonly 2 18 = 92 92 256 K (BitTorrent prior to version 3.2 uses 2 20 = 1 M as 93 93 default). 94 94 95 <code>pieces</code>maps to a string whose length is a multiple of95 ``pieces`` maps to a string whose length is a multiple of 96 96 20. It is to be subdivided into strings of length 20, each of which is 97 97 the SHA1 hash of the piece at the corresponding index. 98 98 99 There is also a key <code>length</code> or a key <code>files</code>,100 but not both or neither. If <code>length</code>is present then the99 There is also a key ``length`` or a key ``files``, 100 but not both or neither. If ``length`` is present then the 101 101 download represents a single file, otherwise it represents a set of 102 102 files which go in a directory structure. 103 103 104 In the single file case, <code>length</code>maps to the length of104 In the single file case, ``length`` maps to the length of 105 105 the file in bytes. 106 106 … … 108 108 only having a single file by concatenating the files in the order they 109 109 appear in the files list. The files list is the value 110 <code>files</code>maps to, and is a list of dictionaries containing110 ``files`` maps to, and is a list of dictionaries containing 111 111 the following keys: 112 112 113 <code>length</code>- The length of the file, in bytes.114 115 <code>path</code>- A list of strings corresponding to subdirectory113 ``length`` - The length of the file, in bytes. 114 115 ``path`` - A list of strings corresponding to subdirectory 116 116 names, the last of which is the actual file name (a zero length list 117 117 is an error case). … … 157 157 158 158 event 159 This is an optional key which maps to <code>started</code>,160 <code>completed</code>, or <code>stopped</code>(or161 <code>empty</code>, which is the same as not being present). If not159 This is an optional key which maps to ``started``, 160 ``completed``, or ``stopped`` (or 161 ``empty``, which is the same as not being present). If not 162 162 present, this is one of the announcements done at regular 163 intervals. An announcement using <code>started</code>is sent when a164 download first begins, and one using <code>completed</code>is sent165 when the download is complete. No <code>completed</code>is sent if163 intervals. An announcement using ``started`` is sent when a 164 download first begins, and one using ``completed`` is sent 165 when the download is complete. No ``completed`` is sent if 166 166 the file was complete when started. Downloaders send an announcement 167 using <code>stopped</code>when they cease downloading.167 using ``stopped`` when they cease downloading. 168 168 169 169 Tracker responses are bencoded dictionaries. If a tracker response 170 has a key <code>failure reason</code>, then that maps to a human170 has a key ``failure reason``, then that maps to a human 171 171 readable string which explains why the query failed, and no other keys 172 are required. Otherwise, it must have two keys: <code>interval</code>,172 are required. Otherwise, it must have two keys: ``interval``, 173 173 which maps to the number of seconds the downloader should wait between 174 regular rerequests, and <code>peers</code>. <code>peers</code>maps to175 a list of dictionaries corresponding to <code>peers</code>, each of176 which contains the keys <code>peer id</code>, <code>ip</code>, and177 <code>port</code>, which map to the peer's self-selected ID, IP174 regular rerequests, and ``peers``. ``peers`` maps to 175 a list of dictionaries corresponding to ``peers``, each of 176 which contains the keys ``peer id``, ``ip``, and 177 ``port``, which map to the peer's self-selected ID, IP 178 178 address or dns name as a string, and port number, respectively. Note 179 179 that downloaders may rerequest on nonscheduled times if an event … … 234 234 Next comes the 20 byte sha1 hash of the bencoded form of the info 235 235 value from the metainfo file. (This is the same value which is 236 announced as <code>info_hash</code>to the tracker, only here it's raw236 announced as ``info_hash`` to the tracker, only here it's raw 237 237 instead of quoted here). If both sides don't send the same value, they 238 238 sever the connection. The one possible exception is if a downloader … … 341 341 are three times as likely to start as the current optimistic unchoke 342 342 as anywhere else in the rotation. 343 343 344 .. 345 Local Variables: 346 mode: indented-text 347 indent-tabs-mode: nil 348 sentence-end-double-space: t 349 fill-column: 70 350 coding: utf-8 351 End: 352