de2f3e66b3f557f274cb9862fc7a58513b69fb0b
[quix0rs-apt-p2p.git] / docs / abstract / abstract.tex
1 \documentclass[conference]{IEEEtran}
2
3 \usepackage[noadjust]{cite}
4
5 \usepackage[dvips]{graphicx}
6
7 \usepackage{url}
8 \usepackage[cmex10]{amsmath}
9 \interdisplaylinepenalty=2500
10 \usepackage{threeparttable}
11 \usepackage{multirow}
12
13 \begin{document}
14
15 \title{Using Altruistic Peers to Help With Free Web Downloads}
16 \author{\IEEEauthorblockN{Cameron Dale}
17 \IEEEauthorblockA{School of Computing Science\\
18 Simon Fraser University\\
19 Burnaby, British Columbia, Canada\\
20 Email: camerond@cs.sfu.ca}
21 \and
22 \IEEEauthorblockN{Jiangchuan Liu}
23 \IEEEauthorblockA{School of Computing Science\\
24 Simon Fraser University\\
25 Burnaby, British Columbia, Canada\\
26 Email: jcliu@cs.sfu.ca}}
27
28 \maketitle
29
30 \begin{abstract}
31 A large amount of free content is available over the Internet from
32 many different distributors. Most of this content uses the traditional
33 client-server model to handle requests from users. However, there is an
34 opportunity to use peer-to-peer techniques to reduce the cost of
35 much of this distribution, especially due to the altruistic nature
36 of many of these users. We present a general technique for
37 satisfying the needs of this P2P distribution, which is applicable
38 to many of these distributors systems. Our method makes use of a DHT
39 for storing the location of peers, using the cryptographic hash of
40 the file as a key. We then go further and implement a solution for
41 the distribution of Debian software packages.
42
43 There are a large number of free content distributors using
44 package distribution systems over the Internet to distribute content
45 to their users. These distributors have developed many different
46 methods for this distribution, but they almost exclusively use a client-server
47 model to satisfy user requests. The popularity and number of users
48 results in a large number of requests, which usually requires a
49 network of mirrors to handle. Due to the free nature of this
50 content, many users are willing and able to contribute upload
51 bandwidth to this distribution, but have no current way to do this.
52
53 We present a new peer-to-peer distribution model to meet these
54 demands. It is based on many previous implementations of successful
55 peer-to-peer protocols, especially distributed hash tables (DHT) and
56 BitTorrent. The model relies on the pre-existence of cryptographic
57 hashes of the content, which should uniquely identify it for a
58 request from other peers. If the peer-to-peer download fails, then
59 the original request to the server is used as a fallback to prevent
60 any dissatisfaction from users. The peer can then share this new
61 content with others through the P2P system.
62
63 First, we examine the opportunity that is available for many of
64 these free content distributors. We present an overview of a system
65 that would efficiently satisfy the demands of a large number of
66 users, and should significantly reduce the currently substantial
67 bandwidth requirements of hosting this content. We then present an
68 example implementation based on the Debian package distribution
69 system. This implementation will be used by a large number of users,
70 and serves as an example for other free content distributors of the
71 opportunity that can be met with such a system.
72
73 There are many peer-to-peer implementations available today, but
74 none is very well suited to this specific problem.
75
76 Many distributors make their content available in some form using
77 BitTorrent \cite{COHEN03}, e.g. for the distribution of CD
78 images. This is not an ideal situation though, as it requires the
79 peers to download large amounts of content that they are not
80 interested in, and prevents them from updating to new content
81 without downloading another image containing a lot of the same
82 content they already have. There have also been other attempted
83 implementations, usually based on some form of BitTorrent, to
84 address this problem. Unfortunately, BitTorrent is not ideally
85 suited to an application such as this one, for the following
86 reasons:
87 \begin{itemize}
88  \item The packages are too small and there are too many to create
89        individual torrents for each one.
90  \item All the packages together are too large to track efficiently
91        as a single torrent.
92  \item BitTorrent's piece sizes are bigger than many of the
93        packages, which wastes bandwidth downloading parts of other
94        packages.
95  \item A small number of the packages can be updated every day,
96        requiring a new torrent and splitting the
97        download population (even though peers in the new torrent
98        share 99\% of the files in common with peers in the old
99        torrent).
100  \item Incentives to share (upload) are no longer needed, as the
101        content is freely available for anyone to download without
102        sharing (seeds are also not needed).
103 \end{itemize}
104
105 Some other implementations have used BitTorrent almost unmodified,
106 while others have only looked at using DHTs to replace the tracker
107 in a BitTorrent system. apt-torrent \cite{apttorrent} creates
108 torrents for some of the larger content available, but it ignores
109 the smaller content, which is often the most popular.
110 DebTorrent \cite{debtorrent} makes widespread modifications to a
111 traditional BitTorrent client, but also requires some changes to the
112 distribution system to support it, and separates peers into groups
113 based on their interest which limits the effectiveness of the
114 sharing. Kenosis \cite{kenosis} is a P2P Remote Procedure Call
115 client also based on the Kademlia DHT, but it is meant as a P2P
116 primitive system on which other tools can be built, and so it has no
117 file sharing functionality at all. Many have used a DHT as a drop-in
118 replacement for the tracker in a BitTorrent system
119 \cite{bittorrent-dht, azureus-dht}, but such systems only use the
120 DHT to find peers for the same torrent, so the file sharing uses
121 traditional BitTorrent and so is not ideal for the reasons listed
122 above.
123
124 There are a large number of groups using the Internet to distribute
125 their free content. This content is usually available from a free
126 download site, which usually requires a network of mirrors to
127 support the large number of requests. This content almost always
128 supports some kind of file verification, usually cryptographic
129 hashes, to verify the completed downloads accuracy or authenticity.
130
131 Most Linux distributions use a software package management system
132 that fetches packages to be installed from a network of mirrors. The
133 Debian project \cite{debian} (and other Debian-based distributions)
134 uses the \texttt{apt} program, which downloads Debian packages in
135 the \texttt{.deb} format from one of many mirrors. The program will
136 first download index files that contain a listing of which packages
137 are available, as well as important information such as their size,
138 location, and a hash of their content. Red Hat's Fedora project
139 \cite{fedora} (and other RPM-based distributions) use the
140 \texttt{yum} program to obtain RPMs, and Gentoo \cite{gentoo} uses
141 \texttt{portage} in a similar way.
142
143 Other software vendors also use a similar system. CPAN \cite{cpan}
144 distributes files containing software packages for the PERL
145 programming language, using SOAP RPC requests to find and download
146 files. Cygwin \cite{cygwin} provides many of the
147 standard Unix/Linux tools in a Windows environment, using a
148 package management tool that requests packages from websites. There
149 are two software distribution systems for Mac OSX, fink and
150 MacPorts, that also retrieve packages in this way.
151
152 Also, some systems use direct web downloads, but with a hash
153 verification file also available for download next to the desired
154 file. These hash files usually have the same file name, but with an
155 added extension identifying the hash used (e.g. \texttt{.md5} for
156 the MD5 hash).
157
158 Finally, there are other programs that use cryptographic hashing to
159 identify files. Git is a version control system in which all files,
160 commits, and tags, are identified by their SHA1 hash. These hashes
161 are used to verify the origin of these items, but are also used when
162 clients update their local files with new remote information.
163
164 The important things to note for each of the systems mentioned
165 is that they all have the following in
166 common:
167 \begin{itemize}
168  \item The content is avaliable for anyone to freely download.
169  \item The content is divided into distinct units (packages), each of which contains
170        a small independent part of all the content.
171  \item Users are typically not interested in downloading all of the content
172        available.
173  \item Hashes of the content and its size are available before the
174        download is attempted.
175  \item Requests for the content are sent by a tool, not directly by
176        the user (though the tool is responding to requests from the user).
177 \end{itemize}
178
179 We also expect that there are a number of users of these systems
180 that are motivated by altruism to want to help out with this
181 distribution. This is common in these systems due to the free nature
182 of the content being delivered, which encourages some to want to
183 help out in some way. A number of the systems are also used by
184 groups that are staffed mostly, or sometimes completely, by
185 volunteers. This also encourages users to want to \emph{give back}
186 to the volunteer community that has created the content they are
187 using.
188
189 Although at first it might seem that a single all-reaching solution
190 is possible for this situation, there are some differences in each
191 system that require independent solutions. The systems all use
192 different tools for their distribution, so any implementation would
193 have to be specific to the tool it is to integrate with. In
194 particular, how to obtain requests from the tool or user, and how to
195 find a hash that corresponds to the file being requested, is very
196 specific to each system.
197
198 Also, there may be no benefit in creating a single large solution to
199 integrate all these problems. For one, though they sometimes
200 distribute nearly identical content (e.g. the same software
201 available in multiple Linux distributions), it is not exactly
202 identical and has usually been tailored to the system. The small
203 differences will change the hash of the files, and so
204 will make it impossible to distribute similar content
205 across systems. And, although peer-to-peer systems scale very well
206 with the number of peers in the system, there is some overhead
207 involved, so having a much larger system of peers would mean that
208 requests could take longer to complete.
209
210 The situation presents a clear
211 opportunity to use some form of peer-to-peer file-sharing protocol.
212 This sparse interest in a large number of packages, and constant
213 updating, is well suited to the functionality provided by a
214 Distributed Hash Table (DHT). DHTs require unique keys to store and
215 retrieve strings of data, for which the cryptographic hashes used by
216 these package management systems are perfect for. The stored and
217 retrieved strings can then be pointers to the peers that have the
218 content package that hashes to that key. A downloading peer can
219 lookup the package hash in the DHT and, if it is found,
220 download the file from those peers and verify the content. If the
221 package hash can not be found in the DHT, the peer will fallback to
222 downloading from the original content location (i.e. the network of
223 mirrors), and once complete will add a new entry to the DHT
224 indicating that it has the content.
225
226 There are several ways to implement the desired P2P functionality
227 into the existing package management software. The functionality can
228 be directly integrated into the software, though this can be
229 difficult as the DHT should be running at all times, both for
230 efficient lookups and to support uploading of already downloaded
231 content, whereas the tools typically only run until the download request is complete.
232 Many of the package management software implementations use
233 HTTP requests to download the files, which makes it possible to
234 implement the P2P aspect as a standard HTTP caching proxy, which
235 will get uncached requests first from the P2P system, and then
236 fallback to the normal HTTP request from a server. For methods that
237 don't use HTTP requests, other types of proxies may also be
238 possible.
239
240 Downloading a file efficiently from a number of peers is where
241 BitTorrent shines as a peer-to-peer application. Its method of
242 breaking up larger files into sub-pieces, each with its own hash,
243 makes it very easy to parallelize the downloading process and
244 maximize the download speed. For very small packages (i.e. less than
245 the sub-piece size), this parallel downloading is not necessary, or
246 even desirable. However, this method can still be used in
247 conjunction with the DHT, for the larger packages that are
248 available.
249
250 Since the package management system only stores a hash of the entire
251 content, and not of sub-pieces of that content, we will need to be
252 able to store and retrieve these sub-piece hashes using the P2P protocol.
253 In addition to storing the file download location in the DHT (which would still
254 be used for small files), a peer will store a \emph{torrent string}
255 containing the peer's hashes of the sub-pieces of the larger
256 files. These piece hashes could be compared ahead of time to
257 determine which peers have the same piece hashes (they all should),
258 and then used during the download to verify the downloaded pieces.
259
260 For very large files (5 or more pieces), the torrent strings
261 are too long to store in the DHT (a single UDP packet should be less
262 than 1472 bytes to avoid fragmentation). Instead, the peers will
263 store the torrent string for large files separately in the DHT, and
264 only contain a reference to it in their stored value for the hash of
265 the file. The reference would be a hash of the torrent string. If
266 the torrent string is short enough to store in the DHT (i.e. less
267 than 1472 bytes, or 70 pieces for the SHA1 hash), then a
268 lookup of that hash in the DHT would give the torrent-like string.
269 Otherwise, a request to the peer for the hash (using the same
270 method as file downloads), should return the torrent string.
271
272 % This can cause a problem with hash checking the returned data, as
273 % hashes for the pieces are not known. Any file that fails a hash
274 % check should be downloaded again, with each piece being downloaded
275 % from different peers than it was previously. The peers are shifted
276 % by 1, so that if a peers previously downloaded piece i, it now
277 % downloads piece i+1, and the first piece is downloaded by the
278 % previous downloader of the last piece, or preferably a previously
279 % unused peer. As each piece is downloaded the running hash of the
280 % file should be checked to determine the place at which the file
281 % differs from the previous download.
282
283 % If the hash check then passes, then the peer who originally provided
284 % the bad piece can be assessed blame for the error. Otherwise, the
285 % peer who originally provided the piece is probably at fault, since
286 % he is now providing a later piece. This doesn't work if the
287 % differing piece is the first piece, in which case it is downloaded
288 % from a 3rd peer, with consensus revealing the misbehaving peer.
289
290 A sample implementation has been created that functions as described
291 previously. This software, called
292 \texttt{apt-p2p}, interacts with the \texttt{apt} tool found in most
293 Debian-based Linux distributions. Apt uses SHA1 hashes to
294 verify most downloaded files, including the large index files that
295 contain the hashes of the individual packages. We chose this
296 distribution system as it is familiar to us, and there are
297 interesting statistics available for analyzing the popularity of the
298 software packages \cite{popcon}.
299
300 Since all requests from apt are in the form of HTTP downloads from a
301 server, the implementation takes the form of a caching HTTP proxy.
302 Making a standard apt implementation use the proxy is then as simple
303 as prepending the proxy location and port to the front of the mirror
304 name (i.e. ``localhost:9977/mirrorname.debian.org/\ldots'').
305
306 The DHT is based on Khashmir \cite{khashmir}, which is an implementation of the
307 Kademlia DHT \cite{kademlia} using methods familiar to BitTorrent
308 developers. It is the same DHT used by most of the existing
309 BitTorrent clients to implement trackerless operation. The
310 communication is all handled by UDP messages, and RPC requests are
311 bencoded in the same way as torrent files. Khashmir uses the high-level
312 Twisted event-driven networking engine \cite{twisted}, so Twisted is also used for
313 all other networking needs.
314
315 The torrent strings stored in the DHT are all bencoded dictionaries
316 containing similar information to what is in a torrent file. This
317 includes the piece size used, the length of the piece hash, and of
318 course the hashes of all the sub-pieces of the content.
319
320 Downloading is accomplished by sending simple HTTP requests to the
321 peer's identified (by lookups in the DHT) to have the desired file.
322 The HTTP server used for the proxy also doubles as the server
323 listening for requests for downloads from other peers. All peers
324 support HTTP/1.1, both in the server and the client, which allows
325 for pipelining of multiple requests to a peer, and the requesting of
326 smaller pieces of a large file using the Range request header.
327
328 Looking at the package size of the 22,298 packages
329 available in Debian in January 2008. We can see that most of the
330 packages are quite small, and so most will therefore not require
331 sub-piece information to download. We have chosen a piece
332 size of 512 kB, which means that 17,515 (78\%) of the packages will
333 not require this information. There are 3054 packages that will
334 require 2 to 4 pieces, for which the torrent string can be stored
335 directly with the package hash in the DHT. There are 1667 packages
336 that will require a separate lookup in the DHT for the longer
337 torrent string as they require 5 to 70 pieces. Finally, there are
338 only 62 packages that require more than 70 pieces, and so will
339 require a separate request to a peer for the torrent string.
340
341 Though functional and useful, the current implementation is not
342 complete, and is missing some of the downloading details necessary.
343 It operates as a caching HTTP proxy, serving
344 requests from apt and other peers. Index files are identified by the
345 current implementation, and parsed to find the hashes of files for later DHT
346 lookups if they are requested. Files are downloaded from
347 peers, and those not available in peers are downloaded directly
348 from the mirror. Any downloaded files are hash checked to verify
349 them, and then added to the DHT.
350
351 Finally, once deployed the system needs to be analyzed to determine
352 its effectiveness at meeting the goals of this project. The analysis
353 will consist of measuring, over time:
354 \begin{itemize}
355  \item The number of peers using the system.
356  \item The amount of downloaded data by peers from other peers.
357  \item The amount of downloaded data by peers from mirrors/servers.
358  \item The bandwidth used to maintain the DHT.
359 \end{itemize}
360
361 We have designed a generally applicable peer-to-peer content
362 distribution model to be used by many of the free content
363 distributors operating today. It makes use of already existing
364 features of most package management systems, to create a
365 peer-to-peer distribution that should substantially reduce the costs
366 of hosting the content.
367
368 We have also implemented our design in software to be used in
369 conjuction with Debian-based distribution of Linux software
370 packages. It will soon be in use by many users of the Debian
371 project's distribution, and so serves as an example of the
372 possibilities that exist.
373
374 \end{abstract}
375
376 \bibliographystyle{IEEEtran}
377 \bibliography{./IEEEabrv,./all}
378
379 \end{document}