root / dotorg / v6 / html / beps / bep_0005.html

Revision 10540, 24.8 kB (checked in by dave, 11 months ago)

postprocessing script that replaces date and last-modified with values from subversion.

generated .html files.

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