root / dotorg / trunk / html / beps / bep_0005.html

Revision 11040, 25.0 kB (checked in by dave, 8 weeks ago)

All HTML docs now reference the new SVN server running at bittorrent.org

Line 
1<?xml version="1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
7<title></title>
8<link rel="stylesheet" href="../css/bep.css" type="text/css" />
9</head>
10<body>
11<div class="document">
12
13<div id="upper" class="clear">
14<div id="wrap">
15<div id="header">
16<h1><a href="../index.html">BitTorrent<span>.org</span></a></h1>
17</div>
18<div id="nav">
19<ul>
20<li><a href="../index.html">Home</a></li>
21<li><a href="../introduction.html">For Users</a></li>
22<li><a href="bep_0000.html"><span>For Developers</span></a></li>
23<!-- <li><a href="./blog">Blog</a></li> -->
24<li><a href="http://forum.bittorrent.org"> Forums </li>
25<li><a href="../donate.html">Donate!</a></li>
26</ul>
27</div> <!-- nav -->
28<!-- ### Begin Content ### -->
29<div id="second">
30
31
32
33<table class="rfc2822 docutils field-list" frame="void" rules="none">
34<col class="field-name" />
35<col class="field-body" />
36<tbody valign="top">
37<tr class="field"><th class="field-name">BEP:</th><td class="field-body">5</td>
38</tr>
39<tr class="field"><th class="field-name">Title:</th><td class="field-body">DHT Protocol</td>
40</tr>
41<tr class="field"><th class="field-name">Version:</th><td class="field-body">11031</td>
42</tr>
43<tr class="field"><th class="field-name">Last-Modified:</th><td class="field-body"><a class="reference external" href="http://svn.bittorrent.org/trac/browser/dotorg/trunk/html/beps/bep_0005.rst">2008-02-28 16:43:58 -0800 (Thu, 28 Feb 2008)</a></td>
44</tr>
45<tr class="field"><th class="field-name">Author:</th><td class="field-body">Andrew Loewenstern &lt;drue&#32;&#97;t&#32;bittorrent.com&gt;</td>
46</tr>
47<tr class="field"><th class="field-name">Status:</th><td class="field-body">Draft</td>
48</tr>
49<tr class="field"><th class="field-name">Type:</th><td class="field-body">Standards Track</td>
50</tr>
51<tr class="field"><th class="field-name">Created:</th><td class="field-body">31-Jan-2008</td>
52</tr>
53<tr class="field"><th class="field-name">Post-History:</th><td class="field-body"></td>
54</tr>
55</tbody>
56</table>
57<hr />
58<div class="contents topic" id="contents">
59<p class="topic-title first">Contents</p>
60<ul class="simple">
61<li><a class="reference internal" href="#overview" id="id3">Overview</a></li>
62<li><a class="reference internal" href="#routing-table" id="id4">Routing Table</a></li>
63<li><a class="reference internal" href="#bittorrent-protocol-extension" id="id5">BitTorrent Protocol Extension</a></li>
64<li><a class="reference internal" href="#torrent-file-extensions" id="id6">Torrent File Extensions</a></li>
65<li><a class="reference internal" href="#krpc-protocol" id="id7">KRPC Protocol</a><ul>
66<li><a class="reference internal" href="#contact-encoding" id="id8">Contact Encoding</a></li>
67<li><a class="reference internal" href="#queries" id="id9">Queries</a></li>
68<li><a class="reference internal" href="#responses" id="id10">Responses</a></li>
69<li><a class="reference internal" href="#errors" id="id11">Errors</a></li>
70</ul>
71</li>
72<li><a class="reference internal" href="#dht-queries" id="id12">DHT Queries</a><ul>
73<li><a class="reference internal" href="#ping" id="id13">ping</a></li>
74<li><a class="reference internal" href="#find-node" id="id14">find_node</a></li>
75<li><a class="reference internal" href="#get-peers" id="id15">get_peers</a></li>
76<li><a class="reference internal" href="#announce-peer" id="id16">announce_peer</a></li>
77</ul>
78</li>
79<li><a class="reference internal" href="#references" id="id17">References</a></li>
80<li><a class="reference internal" href="#copyright" id="id18">Copyright</a></li>
81</ul>
82</div>
83<p>BitTorrent uses a &quot;distributed sloppy hash table&quot; (DHT) for storing
84peer contact information for &quot;trackerless&quot; torrents. In effect, each
85peer becomes a tracker. The protocol is based on Kademila <a class="footnote-reference" href="#kademlia" id="id1">[1]</a> and is
86implemented over UDP.</p>
87<p>Please note the terminology used in this document to avoid
88confusion. A &quot;peer&quot; is a client/server listening on a TCP port that
89implements the BitTorrent protocol. A &quot;node&quot; is a client/server
90listening on a UDP port implementing the distributed hash table
91protocol. The DHT is composed of nodes and stores the location of
92peers. BitTorrent clients include a DHT node, which is used to contact
93other nodes in the DHT to get the location of peers to download from
94using the BitTorrent protocol.</p>
95<div class="section" id="overview">
96<h1>Overview</h1>
97<p>Each node has a globally unique identifier known as the &quot;node ID.&quot;
98Node IDs are chosen at random from the same 160-bit space as
99BitTorrent infohashes <a class="footnote-reference" href="#entropy" id="id2">[2]</a>.  A &quot;distance metric&quot; is used to
100compare two node IDs or a node ID and an infohash for &quot;closeness.&quot;
101Nodes must maintain a routing table containing the contact information
102for a small number of other nodes.  The routing table becomes more
103detailed as IDs get closer to the node's own ID. Nodes know about many
104other nodes in the DHT that have IDs that are &quot;close&quot; to their own but
105have only a handful of contacts with IDs that are very far away from
106their own.</p>
107<p>In Kademlia, the distance metric is XOR and the result is interpreted
108as an unsigned integer. <tt class="docutils literal"><span class="pre">distance(A,B)</span> <span class="pre">=</span> <span class="pre">|A</span> <span class="pre">xor</span> <span class="pre">B|</span></tt> Smaller values
109are closer.</p>
110<p>When a node wants to find peers for a torrent, it uses the distance
111metric to compare the infohash of the torrent with the IDs of the
112nodes in its own routing table. It then contacts the nodes it knows
113about with IDs closest to the infohash and asks them for the contact
114information of peers currently downloading the torrent. If a contacted
115node knows about peers for the torrent, the peer contact information
116is returned with the response. Otherwise, the contacted node must
117respond with the contact information of the nodes in its routing table
118that are closest to the infohash of the torrent. The original node
119iteratively queries nodes that are closer to the target infohash until
120it cannot find any closer nodes. After the search is exhausted, the
121client then inserts the peer contact information for itself onto the
122responding nodes with IDs closest to the infohash of the torrent.</p>
123<p>The return value for a query for peers includes an opaque value known
124as the &quot;token.&quot; For a node to announce that its controlling peer is
125downloading a torrent, it must present the token received from the
126same queried node in a recent query for peers. When a node attempts to
127&quot;announce&quot; a torrent, the queried node checks the token against the
128querying node's IP address. This is to prevent malicious hosts from
129signing up other hosts for torrents. Since the token is merely
130returned by the querying node to the same node it received the token
131from, the implementation is not defined. Tokens must be accepted for a
132reasonable amount of time after they have been distributed. The
133BitTorrent implementation uses the SHA1 hash of the IP address
134concatenated onto a secret that changes every five minutes and tokens
135up to ten minutes old are accepted.</p>
136</div>
137<div class="section" id="routing-table">
138<h1>Routing Table</h1>
139<p>Every node maintains a routing table of known good nodes. The nodes in
140the routing table are used as starting points for queries in the
141DHT. Nodes from the routing table are returned in response to queries
142from other nodes.</p>
143<p>Not all nodes that we learn about are equal. Some are &quot;good&quot; and some
144are not. Many nodes using the DHT are able to send queries and receive
145responses, but are not able to respond to queries from other nodes. It
146is important that each node's routing table must contain only known
147good nodes. A good node is a node has responded to one of our queries
148within the last 15 minutes. A node is also good if it has ever
149responded to one of our queries and has sent us a query within the
150last 15 minutes. After 15 minutes of inactivity, a node becomes
151questionable. Nodes become bad when they fail to respond to multiple
152queries in a row. Nodes that we know are good are given priority over
153nodes with unknown status.</p>
154<p>The routing table covers the entire node ID space from 0 to
1552<sup>160</sup>.  The routing table is subdivided into &quot;buckets&quot; that
156each cover a portion of the space. An empty table has one bucket with
157an ID space range of min=0, max=2<sup>160</sup>. When a node with ID
158&quot;N&quot; is inserted into the table, it is placed within the bucket that
159has min &amp;lt;= N &amp;lt; max. An empty table has only one bucket so any
160node must fit within it. Each bucket can only hold K nodes, currently
161eight, before becoming &quot;full.&quot; When a bucket is full of known good
162nodes, no more nodes may be added unless our own node ID falls within
163the range of the bucket. In that case, the bucket is replaced by two
164new buckets each with half the range of the old bucket and the nodes
165from the old bucket are distributed among the two new ones. For a new
166table with only one bucket, the full bucket is always split into two
167new buckets covering the ranges 0..2<sup>159</sup> and
1682<sup>159</sup>..2<sup>160</sup>.</p>
169<p>When the bucket is full of good nodes, the new node is simply
170discarded. If any nodes in the bucket are known to have become bad,
171then one is replaced by the new node. If there are any questionable
172nodes in the bucket have not been seen in the last 15 minutes, the
173least recently seen node is pinged. If the pinged node responds then
174the next least recently seen questionable node is pinged until one
175fails to respond or all of the nodes in the bucket are known to be
176good. If a node in the bucket fails to respond to a ping, it is
177suggested to try once more before discarding the node and replacing it
178with a new good node. In this way, the table fills with stable long
179running nodes.</p>
180<p>Each bucket should maintain a &quot;last changed&quot; property to
181indicate how &quot;fresh&quot; the contents are. When a node in a bucket is
182pinged and it responds, or a node is added to a bucket, or a node in a
183bucket is replaced with another node, the bucket's last changed
184property should be updated. Buckets that have not been changed in 15
185minutes should be &quot;refreshed.&quot; This is done by picking a random ID in
186the range of the bucket and performing a find_nodes search on it. Nodes
187that are able to receive queries from other nodes usually do not need
188to refresh buckets often. Nodes that are not able to receive queries
189from other nodes usually will need to refresh all buckets periodically
190to ensure there are good nodes in their table when the DHT is needed.</p>
191<p>Upon inserting the first node into its routing table and when starting
192up thereafter, the node should attempt to find the closest nodes in
193the DHT to itself. It does this by issuing find_node messages to
194closer and closer nodes until it cannot find any closer. The routing
195table should be saved between invocations of the client software.</p>
196</div>
197<div class="section" id="bittorrent-protocol-extension">
198<h1>BitTorrent Protocol Extension</h1>
199<p>The BitTorrent protocol has been extended to exchange node UDP port
200numbers between peers that are introduced by a tracker. In this way,
201clients can get their routing tables seeded automatically through the
202download of regular torrents. Newly installed clients who attempt to
203download a trackerless torrent on the first try will not have any
204nodes in their routing table and will need the contacts included in
205the torrent file.</p>
206<p>Peers supporting the DHT set the last bit of the 8-byte reserved flags
207exchanged in the BitTorrent protocol handshake. Peer receiving a
208handshake indicating the remote peer supports the DHT should send a
209PORT message. It begins with byte 0x09 and has a two byte payload
210containing the UDP port of the DHT node in network byte order.  Peers
211that receive this message should attempt to ping the node on the
212received port and IP address of the remote peer. If a response to the
213ping is recieved, the node should attempt to insert the new contact
214information into their routing table according to the usual rules.</p>
215</div>
216<div class="section" id="torrent-file-extensions">
217<h1>Torrent File Extensions</h1>
218<p>A trackerless torrent dictionary does not have an &quot;announce&quot; key.
219Instead, a trackerless torrent has a &quot;nodes&quot; key. This key should be
220set to the K closest nodes in the torrent generating client's routing
221table. Alternatively, the key could be set to a known good node such
222as one operated by the person generating the torrent. Please do not
223automatically add &quot;router.bittorrent.com&quot; to torrent files or
224automatically add this node to clients routing tables.</p>
225<pre class="literal-block">
226nodes = [[&quot;&lt;host&gt;&quot;, &lt;port&gt;], [&quot;&lt;host&gt;&quot;, &lt;port&gt;], ...]
227nodes = [[&quot;127.0.0.1&quot;, 6881], [&quot;your.router.node&quot;, 4804]]
228</pre>
229</div>
230<div class="section" id="krpc-protocol">
231<h1>KRPC Protocol</h1>
232<p>The KRPC protocol is a simple RPC mechanism consisting of bencoded
233dictionaries sent over UDP. A single query packet is sent out and a
234single packet is sent in response. There is no retry. There are three
235message types: query, response, and error. For the DHT protocol, there
236are four queries: ping, find_node, get_peers, and announce_peer.</p>
237<p>A KRPC message is a single dictionary with two keys common to
238every message and additional keys depending on the type of message.
239Every message has a key &quot;t&quot; with a string value representing a transaction
240ID. This transaction ID is generated by the querying node and is echoed
241in the response, so responses may be correlated with multiple queries
242to the same node. The transaction ID should be encoded as a short string
243of binary numbers, typically 2 characters are enough as they cover 2^16
244outstanding queries. The other key contained in every KRPC message is &quot;y&quot;
245with a single character value describing the type of message. The value
246of the &quot;y&quot; key is one of &quot;q&quot; for query, &quot;r&quot; for response, or &quot;e&quot; for
247error.</p>
248<div class="section" id="contact-encoding">
249<h2>Contact Encoding</h2>
250<p>Contact information for peers is encoded as a 6-byte string. Also
251known as &quot;Compact IP-address/port info&quot; the 4-byte IP address is in
252network byte order with the 2 byte port in network byte order
253concatenated onto the end.</p>
254<p>Contact information for nodes is encoded as a 26-byte string.
255Also known as &quot;Compact node info&quot; the 20-byte Node ID in network byte
256order has the compact IP-address/port info concatenated to the end.</p>
257</div>
258<div class="section" id="queries">
259<h2>Queries</h2>
260<p>Queries, or KRPC message dictionaries with a &quot;y&quot; value of &quot;q&quot;,
261contain two additional keys; &quot;q&quot; and &quot;a&quot;. Key &quot;q&quot; has a string value
262containing the method name of the query. Key &quot;a&quot; has a dictionary value
263containing named arguments to the query.</p>
264</div>
265<div class="section" id="responses">
266<h2>Responses</h2>
267<p>Responses, or KRPC message dictionaries with a &quot;y&quot; value of &quot;r&quot;,
268contain one additional key &quot;r&quot;. The value of &quot;r&quot; is a dictionary
269containing named return values. Response messages are sent upon
270successful completion of a query.</p>
271</div>
272<div class="section" id="errors">
273<h2>Errors</h2>
274<p>Errors, or KRPC message dictionaries with a &quot;y&quot; value of &quot;e&quot;,
275contain one additional key &quot;e&quot;. The value of &quot;e&quot; is a list. The first
276element is an integer representing the error code. The second element
277is a string containing the error message. Errors are sent when a query
278cannot be fulfilled. The following table describes the possible error
279codes:</p>
280<table border="1" class="docutils">
281<colgroup>
282<col width="19%" />
283<col width="81%" />
284</colgroup>
285<tbody valign="top">
286<tr><td>Code</td>
287<td>Description</td>
288</tr>
289<tr><td>201</td>
290<td>Generic Error</td>
291</tr>
292<tr><td>202</td>
293<td>Server Error</td>
294</tr>
295<tr><td>203</td>
296<td>Protocol Error, such as a malformed
297packet, invalid arguments, or bad token</td>
298</tr>
299<tr><td>204</td>
300<td>Method Unknown</td>
301</tr>
302</tbody>
303</table>
304<p>Example Error Packets:</p>
305<pre class="literal-block">
306generic error = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;e&quot;, &quot;e&quot;:[201, &quot;A Generic Error Ocurred&quot;]}
307bencoded = d1:eli201e23:A Generic Error Ocurrede1:t2:aa1:y1:ee
308</pre>
309</div>
310</div>
311<div class="section" id="dht-queries">
312<h1>DHT Queries</h1>
313<p>All queries have an &quot;id&quot; key and value containing the node ID of the
314querying node. All responses have an &quot;id&quot; key and value containing the
315node ID of the responding node.</p>
316<div class="section" id="ping">
317<h2>ping</h2>
318<p>The most basic query is a ping. &quot;q&quot; = &quot;ping&quot; A ping query has a
319single argument, &quot;id&quot; the value is a 20-byte string containing the
320senders node ID in network byte order. The appropriate response to a
321ping has a single key &quot;id&quot; containing the node ID of the responding
322node.</p>
323<pre class="literal-block">
324arguments:  {&quot;id&quot;&amp;nbsp;: &quot;&lt;querying nodes id&gt;&quot;}
325
326response: {&quot;id&quot;&amp;nbsp;: &quot;&lt;queried nodes id&gt;&quot;}
327</pre>
328<p>Example Packets</p>
329<pre class="literal-block">
330ping Query = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;q&quot;, &quot;q&quot;:&quot;ping&quot;, &quot;a&quot;:{&quot;id&quot;:&quot;abcdefghij0123456789&quot;}}
331bencoded = d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe
332</pre>
333<pre class="literal-block">
334Response = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;r&quot;, &quot;r&quot;: {&quot;id&quot;:&quot;mnopqrstuvwxyz123456&quot;}}
335bencoded = d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re
336</pre>
337</div>
338<div class="section" id="find-node">
339<h2>find_node</h2>
340<p>Find node is used to find the contact information for a node given
341its ID. &quot;q&quot; == &quot;find_node&quot; A find_node query has two arguments, &quot;id&quot;
342containing the node ID of the querying node, and &quot;target&quot; containing
343the ID of the node sought by the queryer. When a node receives a
344find_node query, it should respond with a key &quot;nodes&quot; and value of a
345string containing the compact node info for the target node or the K
346(8) closest good nodes in its own routing table.</p>
347<pre class="literal-block">
348arguments:  {&quot;id&quot;&amp;nbsp;: &quot;&lt;querying nodes id&gt;&quot;, &quot;target&quot;&amp;nbsp;: &quot;&lt;id of target node&gt;&quot;}
349
350response: {&quot;id&quot;&amp;nbsp;: &quot;&lt;queried nodes id&gt;&quot;, &quot;nodes&quot;&amp;nbsp;: &quot;&lt;compact node info&gt;&quot;}
351</pre>
352<p>Example Packets</p>
353<pre class="literal-block">
354find_node Query = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;q&quot;, &quot;q&quot;:&quot;find_node&quot;, &quot;a&quot;: {&quot;id&quot;:&quot;abcdefghij0123456789&quot;, &quot;target&quot;:&quot;mnopqrstuvwxyz123456&quot;}}
355bencoded = d1:ad2:id20:abcdefghij01234567896:target20:mnopqrstuvwxyz123456e1:q9:find_node1:t2:aa1:y1:qe
356</pre>
357<pre class="literal-block">
358Response = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;r&quot;, &quot;r&quot;: {&quot;id&quot;:&quot;0123456789abcdefghij&quot;, &quot;nodes&quot;: &quot;def456...&quot;}}
359bencoded = d1:rd2:id20:0123456789abcdefghij5:nodes9:def456...e1:t2:aa1:y1:re
360</pre>
361</div>
362<div class="section" id="get-peers">
363<h2>get_peers</h2>
364<p>Get peers associated with a torrent infohash. &quot;q&quot; = &quot;get_peers&quot; A
365get_peers query has two arguments, &quot;id&quot; containing the node ID of the
366querying node, and &quot;info_hash&quot; containing the infohash of the torrent.
367If the queried node has peers for the infohash, they are returned in a
368key &quot;values&quot; as a list of strings. Each string containing &quot;compact&quot; format
369peer information for a single peer. If the queried node has no
370peers for the infohash, a key &quot;nodes&quot; is returned containing the K
371nodes in the queried nodes routing table closest to the infohash
372supplied in the query. In either case a &quot;token&quot; key is also included in
373the return value. The token value is a required argument for a future
374announce_peer query. The token value should be a short binary string.</p>
375<pre class="literal-block">
376arguments:  {&quot;id&quot;&amp;nbsp;: &quot;&lt;querying nodes id&gt;&quot;, &quot;info_hash&quot;&amp;nbsp;: &quot;&lt;20-byte infohash of target torrent&gt;&quot;}
377
378response: {&quot;id&quot;&amp;nbsp;: &quot;&lt;queried nodes id&gt;&quot;, &quot;token&quot;&amp;nbsp;:&quot;&lt;opaque write token&gt;&quot;, &quot;values&quot;&amp;nbsp;: [&quot;&lt;peer 1 info string&gt;&quot;, &quot;&lt;peer 2 info string&gt;&quot;]}
379
380or: {&quot;id&quot;&amp;nbsp;: &quot;&lt;queried nodes id&gt;&quot;, &quot;token&quot;&amp;nbsp;:&quot;&lt;opaque write token&gt;&quot;, &quot;nodes&quot;&amp;nbsp;: &quot;&lt;compact node info&gt;&quot;}
381</pre>
382<p>Example Packets:</p>
383<pre class="literal-block">
384get_peers Query = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;q&quot;, &quot;q&quot;:&quot;get_peers&quot;, &quot;a&quot;: {&quot;id&quot;:&quot;abcdefghij0123456789&quot;, &quot;info_hash&quot;:&quot;mnopqrstuvwxyz123456&quot;}}
385bencoded = d1:ad2:id20:abcdefghij01234567899:info_hash20:mnopqrstuvwxyz123456e1:q9:get_peers1:t2:aa1:y1:qe
386</pre>
387<pre class="literal-block">
388Response with peers = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;r&quot;, &quot;r&quot;: {&quot;id&quot;:&quot;abcdefghij0123456789&quot;, &quot;token&quot;:&quot;aoeusnth&quot;, &quot;values&quot;: [&quot;axje.u&quot;, &quot;idhtnm&quot;]}}
389bencoded = d1:rd2:id20:abcdefghij01234567895:token8:aoeusnth6:valuesl6:axje.u6:idhtnmee1:t2:aa1:y1:re
390</pre>
391<pre class="literal-block">
392Response with closest nodes = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;r&quot;, &quot;r&quot;: {&quot;id&quot;:&quot;abcdefghij0123456789&quot;, &quot;token&quot;:&quot;aoeusnth&quot;, &quot;nodes&quot;: &quot;def456...&quot;}}
393bencoded = d1:rd2:id20:abcdefghij01234567895:nodes9:def456...5:token8:aoeusnthe1:t2:aa1:y1:re
394</pre>
395</div>
396<div class="section" id="announce-peer">
397<h2>announce_peer</h2>
398<p>Announce that the peer, controlling the querying node, is downloading
399a torrent on a port. announce_peer has four arguments: &quot;id&quot; containing the node ID of the
400querying node, &quot;info_hash&quot; containing the infohash of the torrent,
401&quot;port&quot; containing the port as an integer, and the &quot;token&quot; received in
402response to a previous get_peers query. The queried node must verify
403that the token was previously sent to the same IP address as the
404querying node. Then the queried node should store the IP address of the
405querying node and the supplied port number under the infohash in its
406store of peer contact information.</p>
407<pre class="literal-block">
408arguments:  {&quot;id&quot; : &quot;&lt;querying nodes id&gt;&quot;, &quot;info_hash&quot; : &quot;&lt;20-byte infohash of target torrent&gt;&quot;, &quot;port&quot; : &lt;port number&gt;, &quot;token&quot; : &quot;&lt;opaque token&gt;&quot;}
409
410response: {&quot;id&quot; : &quot;&lt;queried nodes id&gt;&quot;}
411</pre>
412<p>Example Packets:</p>
413<pre class="literal-block">
414announce_peers Query = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;q&quot;, &quot;q&quot;:&quot;announce_peer&quot;, &quot;a&quot;: {&quot;id&quot;:&quot;abcdefghij0123456789&quot;, &quot;info_hash&quot;:&quot;mnopqrstuvwxyz123456&quot;, &quot;port&quot;: 6881, &quot;token&quot;: &quot;aoeusnth&quot;}}
415bencoded = d1:ad2:id20:abcdefghij01234567899:info_hash20:&lt;br /&gt;
416mnopqrstuvwxyz1234564:porti6881e5:token8:aoeusnthe1:q13:announce_peer1:t2:aa1:y1:qe
417</pre>
418<pre class="literal-block">
419Response = {&quot;t&quot;:&quot;aa&quot;, &quot;y&quot;:&quot;r&quot;, &quot;r&quot;: {&quot;id&quot;:&quot;mnopqrstuvwxyz123456&quot;}}
420bencoded = d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re
421</pre>
422</div>
423</div>
424<div class="section" id="references">
425<h1>References</h1>
426<table class="docutils footnote" frame="void" id="kademlia" rules="none">
427<colgroup><col class="label" /><col /></colgroup>
428<tbody valign="top">
429<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Peter Maymounkov, David Mazieres, &quot;Kademlia: A Peer-to-peer Information System Based on the XOR Metric&quot;, <em>IPTPS 2002</em>. <a class="reference external" href="http://www.cs.rice.edu/Conferences/IPTPS02/109.pdf">http://www.cs.rice.edu/Conferences/IPTPS02/109.pdf</a></td></tr>
430</tbody>
431</table>
432<table class="docutils footnote" frame="void" id="entropy" rules="none">
433<colgroup><col class="label" /><col /></colgroup>
434<tbody valign="top">
435<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>Use SHA1 and plenty of entropy to ensure a unique ID.</td></tr>
436</tbody>
437</table>
438</div>
439<div class="section" id="copyright">
440<h1>Copyright</h1>
441<p>This document has been placed in the public domain.</p>
442<!-- Local Variables:
443mode: indented-text
444indent-tabs-mode: nil
445sentence-end-double-