Show
Ignore:
Timestamp:
02/04/08 16:10:30 (2 years ago)
Author:
dave
Message:

Change revision number to automatically updated $Revision$ in all .rst files.
Change last-modified date to automatically updated $Date$ in all .rst files.
Add "Local Variables" to the end of all .rst files.
Fix BEP numbers.
Make header formatting in all .rst files conform to PEP-style rst formatting requirements.

Remove some HTML markup from the bep_0003.rst, the BitTorrent? protocol standard.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dotorg/trunk_fixed/html/beps/bep_0005.rst

    r10522 r10528  
    1 BEP: 4 
     1BEP: 5 
    22Title: DHT Protocol 
    3 Version: 2 
    4 Last-Modified: 11-Jan-2008 
     3Version: $Revision$ 
     4Last-Modified: $Date$ 
    55Author:  Andrew Loewenstern <drue@bittorrent.com> 
    6 Status:  Accepted 
     6Status:  Draft 
    77Type:    Standards Track 
    88Created: 31-Jan-2008 
     
    1111BitTorrent uses a "distributed sloppy hash table" (DHT) for storing 
    1212peer contact information for "trackerless" torrents. In effect, each 
    13 peer becomes a tracker. The protocol is based on Kademila[Kademlia]_ and is 
     13peer becomes a tracker. The protocol is based on Kademila [#Kademlia]_ and is 
    1414implemented over UDP. 
    1515 
     
    2323using the BitTorrent protocol. 
    2424 
     25 
    2526Overview 
    26 -------- 
     27======== 
    2728 
    2829Each node has a globally unique identifier known as the "node ID." 
    29 Node IDs are chosen at random from the same 160-bit space as BitTorrent 
    30 infohashes [#entropy]_.  A "distance metric" is used to compare two node IDs or a node  
    31 ID and an infohash for "closeness." Nodes must maintain a routing table 
    32 containing the contact information for a small number of other nodes. 
    33 The routing table becomes more detailed as IDs get closer to the node's 
    34 own ID. Nodes know about many other nodes in the DHT that have IDs that 
    35 are "close" to their own but have only a handful of contacts with IDs 
    36 that are very far away from their own. 
     30Node IDs are chosen at random from the same 160-bit space as 
     31BitTorrent infohashes [#entropy]_.  A "distance metric" is used to 
     32compare two node IDs or a node ID and an infohash for "closeness." 
     33Nodes must maintain a routing table containing the contact information 
     34for a small number of other nodes.  The routing table becomes more 
     35detailed as IDs get closer to the node's own ID. Nodes know about many 
     36other nodes in the DHT that have IDs that are "close" to their own but 
     37have only a handful of contacts with IDs that are very far away from 
     38their own. 
    3739 
    3840In Kademlia, the distance metric is XOR and the result is interpreted 
     
    7072 
    7173Routing Table 
    72 ------------- 
     74============= 
    7375 
    7476Every node maintains a routing table of known good nodes. The nodes in 
     
    137139 
    138140BitTorrent Protocol Extension 
    139 ----------------------------- 
     141============================= 
    140142 
    141143The BitTorrent protocol has been extended to exchange node UDP port 
     
    159161 
    160162Torrent File Extensions 
    161 ----------------------- 
     163======================= 
    162164 
    163165A trackerless torrent dictionary does not have an "announce" key. 
     
    177179 
    178180KRPC Protocol 
    179 ------------- 
     181============= 
    180182 
    181183The KRPC protocol is a simple RPC mechanism consisting of bencoded 
     
    198200 
    199201Contact Encoding 
    200   Contact information for peers is encoded as a 6-byte string. Also 
    201   known as "Compact IP-address/port info" the 4-byte IP address is in 
    202   network byte order with the 2 byte port in network byte order 
    203   concatenated onto the end. 
    204  
    205   Contact information for nodes is encoded as a 26-byte string. 
    206   Also known as "Compact node info" the 20-byte Node ID in network byte 
    207   order has the compact IP-address/port info concatenated to the end. 
     202---------------- 
     203 
     204Contact information for peers is encoded as a 6-byte string. Also 
     205known as "Compact IP-address/port info" the 4-byte IP address is in 
     206network byte order with the 2 byte port in network byte order 
     207concatenated onto the end. 
     208   
     209Contact information for nodes is encoded as a 26-byte string. 
     210Also known as "Compact node info" the 20-byte Node ID in network byte 
     211order has the compact IP-address/port info concatenated to the end. 
    208212 
    209213Queries 
    210   Queries, or KRPC message dictionaries with a "y" value of "q", 
    211   contain two additional keys; "q" and "a". Key "q" has a string value 
    212   containing the method name of the query. Key "a" has a dictionary value 
    213   containing named arguments to the query. 
     214------- 
     215 
     216Queries, or KRPC message dictionaries with a "y" value of "q", 
     217contain two additional keys; "q" and "a". Key "q" has a string value 
     218containing the method name of the query. Key "a" has a dictionary value 
     219containing named arguments to the query. 
    214220 
    215221Responses 
    216   Responses, or KRPC message dictionaries with a "y" value of "r", 
    217   contain one additional key "r". The value of "r" is a dictionary 
    218   containing named return values. Response messages are sent upon 
    219   successful completion of a query. 
     222--------- 
     223 
     224Responses, or KRPC message dictionaries with a "y" value of "r", 
     225contain one additional key "r". The value of "r" is a dictionary 
     226containing named return values. Response messages are sent upon 
     227successful completion of a query. 
    220228 
    221229Errors 
    222   Errors, or KRPC message dictionaries with a "y" value of "e", 
    223   contain one additional key "e". The value of "e" is a list. The first 
    224   element is an integer representing the error code. The second element 
    225   is a string containing the error message. Errors are sent when a query 
    226   cannot be fulfilled. The following table describes the possible error 
    227   codes: 
     230------ 
     231 
     232Errors, or KRPC message dictionaries with a "y" value of "e", 
     233contain one additional key "e". The value of "e" is a list. The first 
     234element is an integer representing the error code. The second element 
     235is a string containing the error message. Errors are sent when a query 
     236cannot be fulfilled. The following table describes the possible error 
     237codes: 
    228238 
    229239+----------+------------------------------------------+ 
     
    249259   
    250260DHT Queries 
    251 ----------- 
     261=========== 
    252262 
    253263All queries have an "id" key and value containing the node ID of the 
     
    256266 
    257267ping 
    258   The most basic query is a ping. "q" = "ping" A ping query has a 
    259   single argument, "id" the value is a 20-byte string containing the 
    260   senders node ID in network byte order. The appropriate response to a 
    261   ping has a single key "id" containing the node ID of the responding 
    262   node. 
     268---- 
     269 
     270The most basic query is a ping. "q" = "ping" A ping query has a 
     271single argument, "id" the value is a 20-byte string containing the 
     272senders node ID in network byte order. The appropriate response to a 
     273ping has a single key "id" containing the node ID of the responding 
     274node. 
    263275 
    264276:: 
     
    283295 
    284296find_node 
    285   Find node is used to find the contact information for a node given 
    286   its ID. "q" == "find_node" A find_node query has two arguments, "id" 
    287   containing the node ID of the querying node, and "target" containing 
    288   the ID of the node sought by the queryer. When a node receives a 
    289   find_node query, it should respond with a key "nodes" and value of a 
    290   string containing the compact node info for the target node or the K 
    291   (8) closest good nodes in its own routing table. 
     297--------- 
     298 
     299Find node is used to find the contact information for a node given 
     300its ID. "q" == "find_node" A find_node query has two arguments, "id" 
     301containing the node ID of the querying node, and "target" containing 
     302the ID of the node sought by the queryer. When a node receives a 
     303find_node query, it should respond with a key "nodes" and value of a 
     304string containing the compact node info for the target node or the K 
     305(8) closest good nodes in its own routing table. 
    292306 
    293307:: 
     
    312326 
    313327get_peers 
    314   Get peers associated with a torrent infohash. "q" = "get_peers" A 
    315   get_peers query has two arguments, "id" containing the node ID of the 
    316   querying node, and "info_hash" containing the infohash of the torrent. 
    317   If the queried node has peers for the infohash, they are returned in a 
    318   key "values" as a list of strings. Each string containing "compact" format 
    319   peer information for a single peer. If the queried node has no 
    320   peers for the infohash, a key "nodes" is returned containing the K 
    321   nodes in the queried nodes routing table closest to the infohash 
    322   supplied in the query. In either case a "token" key is also included in 
    323   the return value. The token value is a required argument for a future 
    324   announce_peer query. The token value should be a short binary string. 
     328--------- 
     329 
     330Get peers associated with a torrent infohash. "q" = "get_peers" A 
     331get_peers query has two arguments, "id" containing the node ID of the 
     332querying node, and "info_hash" containing the infohash of the torrent. 
     333If the queried node has peers for the infohash, they are returned in a 
     334key "values" as a list of strings. Each string containing "compact" format 
     335peer information for a single peer. If the queried node has no 
     336peers for the infohash, a key "nodes" is returned containing the K 
     337nodes in the queried nodes routing table closest to the infohash 
     338supplied in the query. In either case a "token" key is also included in 
     339the return value. The token value is a required argument for a future 
     340announce_peer query. The token value should be a short binary string. 
    325341 
    326342:: 
     
    353369 
    354370announce_peer 
    355   Announce that the peer, controlling the querying node, is downloading 
    356   a torrent on a port. announce_peer has four arguments: "id" containing the node ID of the 
    357   querying node, "info_hash" containing the infohash of the torrent, 
    358   "port" containing the port as an integer, and the "token" received in 
    359   response to a previous get_peers query. The queried node must verify 
    360   that the token was previously sent to the same IP address as the 
    361   querying node. Then the queried node should store the IP address of the 
    362   querying node and the supplied port number under the infohash in its 
    363   store of peer contact information. 
     371------------- 
     372 
     373Announce that the peer, controlling the querying node, is downloading 
     374a torrent on a port. announce_peer has four arguments: "id" containing the node ID of the 
     375querying node, "info_hash" containing the infohash of the torrent, 
     376"port" containing the port as an integer, and the "token" received in 
     377response to a previous get_peers query. The queried node must verify 
     378that the token was previously sent to the same IP address as the 
     379querying node. Then the queried node should store the IP address of the 
     380querying node and the supplied port number under the infohash in its 
     381store of peer contact information. 
    364382 
    365383:: 
     
    383401  bencoded = d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re 
    384402 
    385  
    386 Send questions, comments and corrections to editor@bittorrent.org 
    387  
    388  
    389 .. [Kademlia] Peter Maymounkov, David Mazieres, "`Kademlia: A Peer-to-peer Information System Based on the XOR Metric`_", IPTPS 2002. 
    390  
    391 .. _`Kademlia: A Peer-to-peer Information System Based on the XOR Metric`: http://www.cs.rice.edu/Conferences/IPTPS02/109.pdf 
     403References 
     404========== 
     405 
     406.. [#Kademlia] Peter Maymounkov, David Mazieres, "Kademlia: A Peer-to-peer Information System Based on the XOR Metric", *IPTPS 2002*. http://www.cs.rice.edu/Conferences/IPTPS02/109.pdf 
    392407 
    393408.. [#entropy] Use SHA1 and plenty of entropy to ensure a unique ID. 
    394409 
     410 
     411 
     412.. 
     413   Local Variables: 
     414   mode: indented-text 
     415   indent-tabs-mode: nil 
     416   sentence-end-double-space: t 
     417   fill-column: 70 
     418   coding: utf-8 
     419   End: