Finalized initial motivation paper.
[quix0rs-apt-p2p.git] / docs / motivation / motivation.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
22 \maketitle
23
24 \begin{abstract}
25 A large amount of free content is available over the Internet from
26 many different distributors. Most of this content uses the traditional
27 client-server model to handle requests from users. However, there is an
28 opportunity to use peer-to-peer techniques to reduce the cost of
29 much of this distribution, especially due to the altruistic nature
30 of many of these users. We present a general technique for
31 satisfying the needs of this P2P distribution, which is applicable
32 to many of these distributors systems. Our method makes use of a DHT
33 for storing the location of peers, using the cryptographic hash of
34 the file as a key. We then go further and implement a solution for
35 the distribution of Debian software packages.
36 \end{abstract}
37
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%  Section  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
39
40 \section{Introduction}
41 \label{intro}
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 %%%%%%%%%%%%%%%%%%%%%%%%%%%  Section  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
74
75 \section{Related Work}
76 \label{related}
77
78 There are many peer-to-peer implementations available today, but
79 none is very well suited to this specific problem.
80
81 Many distributors make their content available in some form using
82 BitTorrent \cite{COHEN03}, e.g. for the distribution of CD
83 images. This is not an ideal situation though, as it requires the
84 peers to download large amounts of content that they are not
85 interested in, and prevents them from updating to new content
86 without downloading another image containing a lot of the same
87 content they already have. There have also been other attempted
88 implementations, usually based on some form of BitTorrent, to
89 address this problem. Unfortunately, BitTorrent is not ideally
90 suited to an application such as this one, for the following
91 reasons:
92 \begin{itemize}
93  \item The packages are too small and there are too many to create
94        individual torrents for each one.
95  \item All the packages together are too large to track efficiently
96        as a single torrent.
97  \item BitTorrent's piece sizes are bigger than many of the
98        packages, which wastes bandwidth downloading parts of other
99        packages.
100  \item A small number of the packages can be updated every day,
101        requiring a new torrent and splitting the
102        download population (even though peers in the new torrent
103        share 99\% of the files in common with peers in the old
104        torrent).
105  \item Incentives to share (upload) are no longer needed, as the
106        content is freely available for anyone to download without
107        sharing (seeds are also not needed).
108 \end{itemize}
109
110 Some other implementations have used BitTorrent almost unmodified,
111 while others have only looked at using DHTs to replace the tracker
112 in a BitTorrent system. apt-torrent \cite{apttorrent} creates
113 torrents for some of the larger content available, but it ignores
114 the smaller content, which is often the most popular.
115 DebTorrent \cite{debtorrent} makes widespread modifications to a
116 traditional BitTorrent client, but also requires some changes to the
117 distribution system to support it, and separates peers into groups
118 based on their interest which limits the effectiveness of the
119 sharing. Kenosis \cite{kenosis} is a P2P Remote Procedure Call
120 client also based on the Kademlia DHT, but it is meant as a P2P
121 primitive system on which other tools can be built, and so it has no
122 file sharing functionality at all. Many have used a DHT as a drop-in
123 replacement for the tracker in a BitTorrent system
124 \cite{bittorrent-dht, azureus-dht}, but such systems only use the
125 DHT to find peers for the same torrent, so the file sharing uses
126 traditional BitTorrent and so is not ideal for the reasons listed
127 above.
128
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%  Section  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131 \section{Situation}
132 \label{situation}
133
134 There are a large number of groups using the Internet to distribute
135 their free content. This content is usually available from a free
136 download site, which usually requires a network of mirrors to
137 support the large number of requests. This content almost always
138 supports some kind of file verification, usually cryptographic
139 hashes, to verify the completed downloads accuracy or authenticity.
140
141 \subsection{Examples}
142 \label{examples}
143
144 Most Linux distributions use a software package management system
145 that fetches packages to be installed from a network of mirrors. The
146 Debian project \cite{debian} (and other Debian-based distributions)
147 uses the \texttt{apt} program, which downloads Debian packages in
148 the \texttt{.deb} format from one of many mirrors. The program will
149 first download index files that contain a listing of which packages
150 are available, as well as important information such as their size,
151 location, and a hash of their content. Red Hat's Fedora project
152 \cite{fedora} (and other RPM-based distributions) use the
153 \texttt{yum} program to obtain RPMs, and Gentoo \cite{gentoo} uses
154 \texttt{portage} in a similar way.
155
156 Other software vendors also use a similar system. CPAN \cite{cpan}
157 distributes files containing software packages for the PERL
158 programming language, using SOAP RPC requests to find and download
159 files. Cygwin \cite{cygwin} provides many of the
160 standard Unix/Linux tools in a Windows environment, using a
161 package management tool that requests packages from websites. There
162 are two software distribution systems for Mac OSX, fink and
163 MacPorts, that also retrieve packages in this way.
164
165 Also, some systems use direct web downloads, but with a hash
166 verification file also available for download next to the desired
167 file. These hash files usually have the same file name, but with an
168 added extension identifying the hash used (e.g. \texttt{.md5} for
169 the MD5 hash).
170
171 Finally, there are other programs that use cryptographic hashing to
172 identify files. Git is a version control system in which all files,
173 commits, and tags, are identified by their SHA1 hash. These hashes
174 are used to verify the origin of these items, but are also used when
175 clients update their local files with new remote information.
176
177 \subsection{Similarities}
178 \label{similarities}
179
180 The important things to note for each of the systems mentioned in
181 section \ref{examples}, is that they all have the following in
182 common:
183 \begin{itemize}
184  \item The content is avaliable for anyone to freely download.
185  \item The content is divided into distinct units (packages), each of which contains
186        a small independent part of all the content.
187  \item Users are typically not interested in downloading all of the content
188        available.
189  \item Hashes of the content and its size are available before the
190        download is attempted.
191  \item Requests for the content are sent by a tool, not directly by
192        the user (though the tool is responding to requests from the user).
193 \end{itemize}
194
195 We also expect that there are a number of users of these systems
196 that are motivated by altruism to want to help out with this
197 distribution. This is common in these systems due to the free nature
198 of the content being delivered, which encourages some to want to
199 help out in some way. A number of the systems are also used by
200 groups that are staffed mostly, or sometimes completely, by
201 volunteers. This also encourages users to want to \emph{give back}
202 to the volunteer community that has created the content they are
203 using.
204
205 \subsection{Differences}
206 \label{differences}
207
208 Although at first it might seem that a single all-reaching solution
209 is possible for this situation, there are some differences in each
210 system that require independent solutions. The systems all use
211 different tools for their distribution, so any implementation would
212 have to be specific to the tool it is to integrate with. In
213 particular, how to obtain requests from the tool or user, and how to
214 find a hash that corresponds to the file being requested, is very
215 specific to each system.
216
217 Also, there may be no benefit in creating a single large solution to
218 integrate all these problems. For one, though they sometimes
219 distribute nearly identical content (e.g. the same software
220 available in multiple Linux distributions), it is not exactly
221 identical and has usually been tailored to the system. The small
222 differences will change the hash of the files, and so
223 will make it impossible to distribute similar content
224 across systems. And, although peer-to-peer systems scale very well
225 with the number of peers in the system, there is some overhead
226 involved, so having a much larger system of peers would mean that
227 requests could take longer to complete.
228
229 %%%%%%%%%%%%%%%%%%%%%%%%%%%  Section  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
230
231 \section{Opportunity}
232 \label{opportunity}
233
234 The situation described in section \ref{situation} presents a clear
235 opportunity to use some form of peer-to-peer file-sharing protocol.
236 This sparse interest in a large number of packages, and constant
237 updating, is well suited to the functionality provided by a
238 Distributed Hash Table (DHT). DHTs require unique keys to store and
239 retrieve strings of data, for which the cryptographic hashes used by
240 these package management systems are perfect for. The stored and
241 retrieved strings can then be pointers to the peers that have the
242 content package that hashes to that key. A downloading peer can
243 lookup the package hash in the DHT and, if it is found,
244 download the file from those peers and verify the content. If the
245 package hash can not be found in the DHT, the peer will fallback to
246 downloading from the original content location (i.e. the network of
247 mirrors), and once complete will add a new entry to the DHT
248 indicating that it has the content.
249
250 \subsection{Implementation Options}
251 \label{imp_options}
252
253 There are several ways to implement the desired P2P functionality
254 into the existing package management software. The functionality can
255 be directly integrated into the software, though this can be
256 difficult as the DHT should be running at all times, both for
257 efficient lookups and to support uploading of already downloaded
258 content, whereas the tools typically only run until the download request is complete.
259 Many of the package management software implementations use
260 HTTP requests to download the files, which makes it possible to
261 implement the P2P aspect as a standard HTTP caching proxy, which
262 will get uncached requests first from the P2P system, and then
263 fallback to the normal HTTP request from a server. For methods that
264 don't use HTTP requests, other types of proxies may also be
265 possible.
266
267 \subsection{Downloading From Peers}
268 \label{downloading}
269
270 Downloading a file efficiently from a number of peers is where
271 BitTorrent shines as a peer-to-peer application. Its method of
272 breaking up larger files into sub-pieces, each with its own hash,
273 makes it very easy to parallelize the downloading process and
274 maximize the download speed. For very small packages (i.e. less than
275 the sub-piece size), this parallel downloading is not necessary, or
276 even desirable. However, this method can still be used in
277 conjunction with the DHT, for the larger packages that are
278 available.
279
280 Since the package management system only stores a hash of the entire
281 content, and not of sub-pieces of that content, we will need to be
282 able to store and retrieve these sub-piece hashes using the P2P protocol.
283 In addition to storing the file download location in the DHT (which would still
284 be used for small files), a peer will store a \emph{torrent string}
285 containing the peer's hashes of the sub-pieces of the larger
286 files. These piece hashes could be compared ahead of time to
287 determine which peers have the same piece hashes (they all should),
288 and then used during the download to verify the downloaded pieces.
289
290 For very large files (5 or more pieces), the torrent strings
291 are too long to store in the DHT (a single UDP packet should be less
292 than 1472 bytes to avoid fragmentation). Instead, the peers will
293 store the torrent string for large files separately in the DHT, and
294 only contain a reference to it in their stored value for the hash of
295 the file. The reference would be a hash of the torrent string. If
296 the torrent string is short enough to store in the DHT (i.e. less
297 than 1472 bytes, or 70 pieces for the SHA1 hash), then a
298 lookup of that hash in the DHT would give the torrent-like string.
299 Otherwise, a request to the peer for the hash (using the same
300 method as file downloads), should return the torrent string.
301
302 % This can cause a problem with hash checking the returned data, as
303 % hashes for the pieces are not known. Any file that fails a hash
304 % check should be downloaded again, with each piece being downloaded
305 % from different peers than it was previously. The peers are shifted
306 % by 1, so that if a peers previously downloaded piece i, it now
307 % downloads piece i+1, and the first piece is downloaded by the
308 % previous downloader of the last piece, or preferably a previously
309 % unused peer. As each piece is downloaded the running hash of the
310 % file should be checked to determine the place at which the file
311 % differs from the previous download.
312
313 % If the hash check then passes, then the peer who originally provided
314 % the bad piece can be assessed blame for the error. Otherwise, the
315 % peer who originally provided the piece is probably at fault, since
316 % he is now providing a later piece. This doesn't work if the
317 % differing piece is the first piece, in which case it is downloaded
318 % from a 3rd peer, with consensus revealing the misbehaving peer.
319
320 %%%%%%%%%%%%%%%%%%%%%%%%%%%  Section  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
321
322 \section{Sample Implementation}
323 \label{implementation}
324
325 A sample implementation has been created that functions as described
326 in section \ref{opportunity}. This software, called
327 \texttt{apt-dht}, interacts with the \texttt{apt} tool found in most
328 Debian-based Linux distributions. Apt uses SHA1 hashes to
329 verify most downloaded files, including the large index files that
330 contain the hashes of the individual packages. We chose this
331 distribution system as it is familiar to us, and there are
332 interesting statistics available for analyzing the popularity of the
333 software packages \cite{popcon}.
334
335 Since all requests from apt are in the form of HTTP downloads from a
336 server, the implementation takes the form of a caching HTTP proxy.
337 Making a standard apt implementation use the proxy is then as simple
338 as prepending the proxy location and port to the front of the mirror
339 name (i.e. ``localhost:9977/mirrorname.debian.org/\ldots'').
340
341 The DHT is based on Khashmir \cite{khashmir}, which is an implementation of the
342 Kademlia DHT \cite{kademlia} using methods familiar to BitTorrent
343 developers. It is the same DHT used by most of the existing
344 BitTorrent clients to implement trackerless operation. The
345 communication is all handled by UDP messages, and RPC requests are
346 bencoded in the same way as torrent files. Khashmir uses the high-level
347 Twisted event-driven networking engine \cite{twisted}, so Twisted is also used for
348 all other networking needs.
349
350 The torrent strings stored in the DHT are all bencoded dictionaries
351 containing similar information to what is in a torrent file. This
352 includes the piece size used, the length of the piece hash, and of
353 course the hashes of all the sub-pieces of the content.
354
355 Downloading is accomplished by sending simple HTTP requests to the
356 peer's identified (by lookups in the DHT) to have the desired file.
357 The HTTP server used for the proxy also doubles as the server
358 listening for requests for downloads from other peers. All peers
359 support HTTP/1.1, both in the server and the client, which allows
360 for pipelining of multiple requests to a peer, and the requesting of
361 smaller pieces of a large file using the Range request header.
362
363 \begin{figure}
364 \centering
365 \includegraphics[width=\columnwidth]{apt_dht_simulation-size_CDF.eps}
366 \caption{The CDF of the size of packages in a Debian system, both
367 for the actual size and adjusted size based on the popularity of
368 the package.}
369 \label{size_CDF}
370 \end{figure}
371
372 Figure \ref{size_CDF} shows the package size of the 22,298 packages
373 available in Debian in January 2008. We can see that most of the
374 packages are quite small, and so most will therefore not require
375 sub-piece information to download. We have chosen a piece
376 size of 512 kB, which means that 17,515 (78\%) of the packages will
377 not require this information. There are 3054 packages that will
378 require 2 to 4 pieces, for which the torrent string can be stored
379 directly with the package hash in the DHT. There are 1667 packages
380 that will require a separate lookup in the DHT for the longer
381 torrent string as they require 5 to 70 pieces. Finally, there are
382 only 62 packages that require more than 70 pieces, and so will
383 require a separate request to a peer for the torrent string.
384
385 \subsection{Current Status}
386 \label{status}
387
388 Though functional and useful, the current implementation is not
389 complete, and is missing some of the downloading details necessary.
390 It operates as a caching HTTP proxy, serving
391 requests from apt and other peers. Index files are identified by the
392 current implementation, and parsed to find the hashes of files for later DHT
393 lookups if they are requested. Files are downloaded from
394 peers, and those not available in peers are downloaded directly
395 from the mirror. Any downloaded files are hash checked to verify
396 them, and then added to the DHT.
397
398 However, the current implementation does not use the sub-piece
399 hashing described in section \ref{downloading}, or any parallelizing
400 of downloads. Instead, it currently chooses a peer at random from
401 the list of possible peers, and downloads the entire file from that
402 peer, regardless of the size of the file. This needs to change if
403 both a) the file is large (more than 512 KB), and b) there are
404 multiple peers with the file. The storage and retrieval of sub-piece
405 hashes has not yet been finalized though, and until it is this final
406 step is not possible.
407
408 %%%%%%%%%%%%%%%%%%%%%%%%%%%  Section  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
409
410 \section{Future Work}
411 \label{future}
412
413 There are some additional steps to be taken to succeed with this
414 project. First, the storage method of sub-piece hashes needs to be
415 finalized and properly implemented. The communication built into the
416 Khashmir-based DHT also needs to be solidified. Some additional peer
417 statistics data needs to be made available for each peer, so that
418 some form of analysis is available once the system is deployed. The
419 reference implementation then needs to be packaged for upload to the
420 Debian package archive, so that it can benefit from the widest
421 possible deployment among users.
422
423 Finally, once deployed the system needs to be analyzed to determine
424 its effectiveness at meeting the goals of this project. The analysis
425 will consist of measuring, over time:
426 \begin{itemize}
427  \item The number of peers using the system.
428  \item The amount of downloaded data by peers from other peers.
429  \item The amount of downloaded data by peers from mirrors/servers.
430  \item The bandwidth used to maintain the DHT.
431 \end{itemize}
432
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%  Section  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
434
435 \section{Conclusions}
436 \label{conclusions}
437
438 We have designed a generally applicable peer-to-peer content
439 distribution model to be used by many of the free content
440 distributors operating today. It makes use of already existing
441 features of most package management systems, to create a
442 peer-to-peer distribution that should substantially reduce the costs
443 of hosting the content.
444
445 We have also implemented our design in software to be used in
446 conjuction with Debian-based distribution of Linux software
447 packages. It will soon be in use by many users of the Debian
448 project's distribution, and so serves as an example of the
449 possibilities that exist.
450
451 \bibliographystyle{IEEEtran}
452 \bibliography{./IEEEabrv,./all}
453
454 \end{document}