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

Revision 11136, 10.5 KB (checked in by dave, 15 months ago)

further wordsmithing.

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