root / dotorg / trunk / html / beps / bep_0022.html

Revision 11137, 17.9 kB (checked in by dave, 8 days ago)

generated html

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">22</td>
38</tr>
39<tr class="field"><th class="field-name">Title:</th><td class="field-body">BitTorrent Local Tracker Discovery Protocol</td>
40</tr>
41<tr class="field"><th class="field-name">Version:</th><td class="field-body">11136</td>
42</tr>
43<tr class="field"><th class="field-name">Last-Modified:</th><td class="field-body"><a class="reference external" href="http://bittorrent.org/trac/browser/dotorg/trunk/html/beps/bep_0022.rst">2008-08-12 22:10:10 -0700 (Tue, 12 Aug 2008)</a></td>
44</tr>
45<tr class="field"><th class="field-name">Author:</th><td class="field-body">David Harrison &lt;dave&#32;&#97;t&#32;bittorrent.com&gt;, Stanislav Shalunov &lt;shalunov&#32;&#97;t&#32;bittorrent.com&gt;, Greg Hazel &lt;greg&#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">Content-Type:</th><td class="field-body"><a class="reference external" href="http://www.bittorrent.org/beps/bep-0012">text/x-rst</a></td>
52</tr>
53<tr class="field"><th class="field-name">Created:</th><td class="field-body">12-May-2008</td>
54</tr>
55<tr class="field"><th class="field-name">Post-History:</th><td class="field-body"></td>
56</tr>
57</tbody>
58</table>
59<hr />
60<div class="contents topic" id="contents">
61<p class="topic-title first">Contents</p>
62<ul class="simple">
63<li><a class="reference internal" href="#motivation" id="id10">Motivation</a></li>
64<li><a class="reference internal" href="#the-discovery-mechanism" id="id11">The Discovery Mechanism</a></li>
65<li><a class="reference internal" href="#iterative-queries" id="id12">Iterative Queries</a></li>
66<li><a class="reference internal" href="#network-address-translators" id="id13">Network Address Translators</a></li>
67<li><a class="reference internal" href="#example" id="id14">Example</a></li>
68<li><a class="reference internal" href="#references" id="id15">References</a></li>
69<li><a class="reference internal" href="#copyright" id="id16">Copyright</a></li>
70</ul>
71</div>
72<div class="section" id="motivation">
73<h1>Motivation</h1>
74<p>Some Internet Service Providers (ISPs) may wish to localize traffic
75to reduce transit costs, reduce internal traffic, and improve user
76experience by speeding up downloads.</p>
77<p>With this extension, BitTorrent clients are able to discover a tracker
78nearby on the network, and via this tracker discover nearby caches or
79peers.  A cache may simply be a fast peer in the middle of the network. It
80might also have substantial disk space. The client communicates with a
81cache using the normal BitTorrent protocol.</p>
82<p>When a cache is present, the user benefits from having a high capacity
83peer from which the user's client downloads and to which it can
84delegate seeding.  When a cache inside the user's ISP network seeds on
85behalf of the client, it frees upstream capacity in the user's access
86network benefiting the user and those that share the access network.
87When subsequent peers transfer from their ISP's cache, the ISP
88experiences less transit traffic.</p>
89<p>The scope of this BEP is limited to the local tracker discovery
90process.  Extensions to the BitTorrent protocol suite to delegate
91seeding or improve cache performance are beyond the scope of this BEP.</p>
92<p>The key words &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL
93NOT&quot;, &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;&quot;MAY&quot;, and
94&quot;OPTIONAL&quot; in this document are to be interpreted as described in
95IETF <a class="reference external" href="http://www.faqs.org/rfcs/rfc2119.html">RFC 2119</a> <a class="footnote-reference" href="#rfc-2119" id="id1">[5]</a>.</p>
96<p>Client implementation of local tracker discovery is OPTIONAL.  Clients
97MUST NOT announce private torrents to a local tracker.  It is
98RECOMMENDED that clients provide a user option for turning off local
99tracker discovery.  Local tracker discovery MAY be off by default.
100Clients MAY automatically turn off caching if the performance benefit
101is not obvious.  Determining obviousness is beyond the scope of this
102BEP.</p>
103</div>
104<div class="section" id="the-discovery-mechanism">
105<h1>The Discovery Mechanism</h1>
106<p>To find the tracker for its ISP, a BitTorrent client performs a reverse
107DNS lookup on its external IP address and then obtains the BitTorrent
108SRV resource record associated with the host's domain name.  For
109example, a host with address 69.107.0.14 obtains the PTR record at</p>
110<pre class="literal-block">
11114.0.107.69.in-addr.arpa
112</pre>
113<p>The client's host IP address may not match the host's IP address as
114seen outside the client's private network.  We address this in Section
115<a class="reference internal" href="#network-address-translators">Network Address Translators</a>.</p>
116<p>The PTR resource record returned for this example contains domain name</p>
117<pre class="literal-block">
118adsl-69-107-0-14.dsl.pltn13.pacbell.net
119</pre>
120<p>The client then looks up the SRV records at</p>
121<pre class="literal-block">
122_bittorrent-tracker._tcp.adsl-69-107-0-14.dsl.pltn13.pacbell.net
123</pre>
124<p>If no SRV record is found, one or more subsequent queries take place as
125described in <a class="reference internal" href="#iterative-queries">Iterative Queries</a>.</p>
126<p>The target field in each returned SRV resource record contains the
127domain name of a tracker and the port on which the tracker runs.  This
128tracker is called a <em>local tracker</em>, but the protocol to talk to this
129tracker is no different from the standard BitTorrent tracker protocol
130described in <a class="footnote-reference" href="#bep-3" id="id2">[1]</a>.</p>
131<p>When the BitTorrent client joins a swarm it announces to one or more
132of the trackers referenced in the .torrent file and announces to the
133local tracker.  The local tracker returns peers which may be caches or
134other peers that announced the same file to the local tracker.</p>
135<p>A client MAY treat nearby peers or caches preferentially.</p>
136<p>Reverse DNS lookups are described in <a class="reference external" href="http://www.faqs.org/rfcs/rfc1034.html">RFC 1034</a> <a class="footnote-reference" href="#rfc-1034" id="id3">[4]</a>.
137The SRV resource record type is described in <a class="reference external" href="http://www.faqs.org/rfcs/rfc2782.html">RFC 2782</a> <a class="footnote-reference" href="#rfc-2782" id="id4">[6]</a>.</p>
138</div>
139<div class="section" id="iterative-queries">
140<h1>Iterative Queries</h1>
141<p>The domain name returned from the reverse DNS lookup is specific to
142the querying host.  In the naive implementation in DNS, there would be
143one SRV resource record for every querying host.  This would work but
144is burdensome.  A natural, seemingly less burdensome, but incorrect
145solution is to use a wildcard of the form:</p>
146<pre class="literal-block">
147*.pacbell.net
148</pre>
149<p>If wildcards are implemented according to the algorithm in section
1504.3.2 in <a class="footnote-reference" href="#rfc-1034" id="id5">[4]</a> then all subdomains of pacbell.net that do not
151have an exact label match will match the wildcard.  Thus unless there
152is an exact match then queries for</p>
153<pre class="literal-block">
154_bittorrent-tracker._tcp.adsl-69-107-0-14.dsl.pltn13.pacbell.net
155</pre>
156<p>and</p>
157<pre class="literal-block">
158_jabber._tcp.pacbell.net
159</pre>
160<p>both match *.pacbell.net and all SRV resource records with owner
161*.pacbell.net would be returned with the name set to the name in the
162query.  Thus it would be impossible to disambiguate Jabber from
163BitTorrent SRV records without further information.  This behavior is
164implemented with BIND 9.4.1.</p>
165<p>Another natural but incorrect solution is to specify domain names of
166the type</p>
167<pre class="literal-block">
168_bittorrent-tracker._tcp.*.pacbell.net
169</pre>
170<p>Section 4.3.3 in <a class="footnote-reference" href="#rfc-1034" id="id6">[4]</a> specifies that wildcards only appear as
171the first label in a domain name.  This restriction was lifted in
172<a class="footnote-reference" href="#rfc-4592" id="id7">[7]</a>, but not with semantics applicable to our use case.  An
173asterisk not at the beginning of a domain name is not treated like a
174wildcard.  Only a lookup for the exact domain name</p>
175<pre class="literal-block">
176_bittorrent-tracker._tcp.*.pacbell.net
177</pre>
178<p>matches.</p>
179<p>We propose an alternative that avoids wildcards and allows
180suborganizations to override SRV records provided by parent
181organizations: the peer starts by querying using its fully-qualified
182domain name returned from the reverse DNS lookup, and if this fails
183then it queries again after removing the most specific (leftmost)
184label in the domain name.  For example, if no SRV records are returned
185when querying for</p>
186<pre class="literal-block">
187_bittorrent-tracker._tcp.adsl-69-107-0-14.dsl.pltn13.pacbell.net
188</pre>
189<p>then the client queries for</p>
190<pre class="literal-block">
191_bittorrent-tracker._tcp.dsl.pltn13.pacbell.net
192</pre>
193<p>and then</p>
194<pre class="literal-block">
195_bittorrent-tracker._tcp.pltn13.pacbell.net
196</pre>
197<p>The search removes one label at a time terminating when one or more
198resource records are found or before querying the root domain or
199top-level domains that are not ccTLDs, e.g., .com, .org, .net. We
200avoid querying the root or top-level domains given the low likelihood
201that caches would be defined globally, and thus clients would
202unnecessarily burden the root domain name servers with queries
203generating negative results. We considered stopping before querying
204country-level domains, but a country providing public infrastructure
205might choose to provide caches.</p>
206</div>
207<div class="section" id="network-address-translators">
208<h1>Network Address Translators</h1>
209<p>Many hosts on the Internet sit in private networks that connect to the
210Internet via a Network Address Translator (NAT).  Such hosts may have
211an IP address allocated from one of the private IP address ranges
212defined by IANA, e.g., ranges with prefixes 10/8, 172.16/12, and
213192.168/16.  When communicating with hosts outside the private
214network, the NAT translates the private IP to a globally-routable IP
215address.  This globally-routable address is the host's <em>external IP
216address</em>.</p>
217<p>The BitTorrent client must use its host's external IP address.  A
218BitTorrent client MAY obtain its host's external IP either from the
219<em>external ip</em> key returned from a tracker implementing BEP 24
220<a class="footnote-reference" href="#bep-24" id="id8">[3]</a> or from peers implementing the <em>yourip</em> extension defined
221for the <em>Extension Protocol</em> proposed in <a class="footnote-reference" href="#bep-10" id="id9">[2]</a>.</p>
222</div>
223<div class="section" id="example">
224<h1>Example</h1>
225<p>In our example, we use AT&amp;T's PacBell network.  AT&amp;T could implement
226tracker discovery by adding the following lines to the zone file for
227pacbell.net,</p>
228<pre class="literal-block">
229; name                                ttl  cls rr  pri weight port target
230_bittorrent-tracker._tcp.pacbell.net. 600  IN  SRV 5   0      6969 tracker
231</pre>
232<p>Now when a client performs tracker discovery, it performs three DNS
233queries removing labels before reaching the domain name pacbell.net,
234at which point the SRV record is returned and the client queries
235tracker.pacbell.net to obtain the domain names of caches.</p>
236<p>In Python, the local tracker's port and domain can be obtained using
237PyDNS using the following code:</p>
238<pre class="literal-block">
239import DNS
240
241tlds = [&quot;com&quot;, &quot;net&quot;, &quot;org&quot;]  # add more TLDs here.
242
243name = DNS.revlookup( &quot;69.107.0.14&quot; )
244names = name.split('.')
245while names and names[0] not in tlds:
246   name = &quot;_bittorrent-tracker._tcp.&quot; + &quot;.&quot;.join(names)
247   req = DNS.Request( name=name, qtype=&quot;SRV&quot;, protocol=&quot;udp&quot;)
248   response = req.req()
249   if response.answers:
250      break
251   del names[0]
252
253print &quot;response=&quot;, response.show()
254</pre>
255<p>which might generate output like</p>
256<pre class="literal-block">
257response= ; &lt;&lt;&gt;&gt; PDG.py 1.0 &lt;&lt;&gt;&gt; _bittorrent._tcp.pacbell.net SRV
258;; options: recurs
259;; got answer:
260;; -&gt;&gt;HEADER&lt;&lt;- opcode 0, status NOERROR, id 0
261;; flags: qr aa rd ra; Ques: 1, Ans: 1, Auth: 2, Addit: 3
262;; QUESTIONS:
263;;      _bittorrent-tracker._tcp.pacbell.net, type = SRV, class = IN
264
265;; ANSWERS:
266_bittorrent-tracker._tcp.pacbell.net    600    SRV     (5, 0, 6969, 'cache.pacbell.net')
267
268;; AUTHORITY RECORDS:
269pacbell.net             86400   NS      ns1.pbi.net
270pacbell.net             86400   NS      ns2.pbi.net
271
272;; ADDITIONAL RECORDS:
273cache.pacbell.net       86400   A       69.107.0.1
274ns1.pacbell.net         86400   A       206.13.28.11
275ns2.pacbell.net         86400   A       206.13.29.11
276
277;; Total query time: 0 msec
278;; To SERVER: localhost
279;; WHEN: Mon May 19 16:00:12 2008
280</pre>
281<p>The answer above is fictional since AT&amp;T does not at this time
282implement SRV records for BitTorrent trackers.</p>
283<p>In Microsoft Windows, the port and domain name of the server can be
284obtained using WinDNS (Dnsapi.lib) using DnsQuery().  In Unix, the
285relevant call is res_query() from libresolv.</p>
286</div>
287<div class="section" id="references">
288<h1>References</h1>
289<table class="docutils footnote" frame="void" id="bep-3" rules="none">
290<colgroup><col class="label" /><col /></colgroup>
291<tbody valign="top">
292<tr><td class="label"><a class="fn-backref" href="#id2">[1]</a></td><td>BEP_0003. The BitTorrent Protocol Specification, Cohen.
293<a class="reference external" href="http://www.bittorrent.org/beps/bep_0003.html">http://www.bittorrent.org/beps/bep_0003.html</a></td></tr>
294</tbody>
295</table>
296<table class="docutils footnote" frame="void" id="bep-10" rules="none">
297<colgroup><col class="label" /><col /></colgroup>
298<tbody valign="top">
299<tr><td class="label"><a class="fn-backref" href="#id9">[2]</a></td><td>BEP_0010.  Extension Protocol. Norberg, Strigeus, Hazel.
300<a class="reference external" href="http://www.bittorrent.org/beps/bep_0010.html">http://www.bittorrent.org/beps/bep_0010.html</a></td></tr>
301</tbody>
302</table>
303<table class="docutils footnote" frame="void" id="bep-24" rules="none">
304<colgroup><col class="label" /><col /></colgroup>
305<tbody valign="top">
306<tr><td class="label"><a class="fn-backref" href="#id8">[3]</a></td><td>BEP_0024.  Tracker Returns External IP.  Harrison.
307<a class="reference external" href="http://www.bittorrent.org/beps/bep_0024.html">http://www.bittorrent.org/beps/bep_0024.html</a></td></tr>
308</tbody>
309</table>
310<table class="docutils footnote" frame="void" id="rfc-1034" rules="none">
311<colgroup><col class="label" /><col /></colgroup>
312<tbody valign="top">
313<tr><td class="label">[4]</td><td><em>(<a class="fn-backref" href="#id3">1</a>, <a class="fn-backref" href="#id5">2</a>, <a class="fn-backref" href="#id6">3</a>)</em> <a class="reference external" href="http://www.faqs.org/rfcs/rfc1034.html">RFC-1034</a>.  DOMAIN NAMES - CONCEPTS AND FACILITIES. Mockapetris,
314November 1987. <a class="reference external" href="http://tools.ietf.org/html/rfc1034">http://tools.ietf.org/html/rfc1034</a></td></tr>
315</tbody>
316</table>
317<table class="docutils footnote" frame="void" id="rfc-2119" rules="none">
318<colgroup><col class="label" /><col /></colgroup>
319<tbody valign="top">
320<tr><td class="label"><a class="fn-backref" href="#id1">[5]</a></td><td><a class="reference external" href="http://www.faqs.org/rfcs/rfc2119.html">RFC-2119</a>. <a class="reference external" href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a></td></tr>
321</tbody>
322</table>
323<table class="docutils footnote" frame="void" id="rfc-2782" rules="none">
324<colgroup><col class="label" /><col /></colgroup>
325<tbody valign="top">
326<tr><td class="label"><a class="fn-backref" href="#id4">[6]</a></td><td><a class="reference external" href="http://www.faqs.org/rfcs/rfc2782.html">RFC-2782</a>.  A DNS RR for specifying the location of services (DNS
327SRV). Gulbrandsen, Vixie, Esibov. February 2000.
328<a class="reference external" href="http://tools.ietf.org/html/rfc2782">http://tools.ietf.org/html/rfc2782</a></td></tr>
329</tbody>
330</table>
331<table class="docutils footnote" frame="void" id="rfc-4592" rules="none">
332<colgroup><col class="label" /><col /></colgroup>
333<tbody valign="top">
334<tr><td class="label"><a class="fn-backref" href="#id7">[7]</a></td><td><a class="reference external" href="http://www.faqs.org/rfcs/rfc4592.html">RFC-4592</a>. The Role of Wildcards in the Domain Name
335System. Lewis.  <a class="reference external" href="http://www.faqs.org/rfcs/rfc4592.html">http://www.faqs.org/rfcs/rfc4592.html</a></td></tr>
336</tbody>
337</table>
338</div>
339<div class="section" id="copyright">
340<h1>Copyright</h1>
341<p>This document has been placed in the public domain.</p>
342<!-- Local Variables:
343mode: indented-text
344indent-tabs-mode: nil
345sentence-end-double-space: t
346fill-column: 70
347coding: utf-8
348End: -->
349</div>
350
351
352</div>
353        <div id="footer">
354<hr/>
355</div>
356
357</div>
358</body>
359</html>
Note: See TracBrowser for help on using the browser.