Homework BONUS: An event-based BitTorrent client

In this assignment, you will improve a bare-bones bittorrent client to include some extra useful features. The template has already done much of the heavy lifting. However, the template is multi-threaded, and can only leech. The jobs you need to finish are:

  1. Modify the template to non-threaded format. Instead, use select() to listen for incoming packets on multiple sockets simultaneously. Handle broken connections and other peer behaviors to ensure a reliable download.

  2. Announce available pieces to peers and handle incoming piece requests to maximize performance.

  3. Request pieces in the ideal order to minimize download time.

You’ll find the template in git@git.uicbits.net:cs450-f13/public/homeworks. Details of the BitTorrent protocol can be found here.

PERFORMANCE EXPECTATIONS

Your code does not need to handle IPv6 - you can simply use an AF_INET socket instead of INET6.

For full points, your solution should produce given .torrent files. It must not reply only on seeds: it should download pieces from many peers, and it should finish significantly faster simply getting all the pieces from one seed. Your program will be tested on the .torrent files in the template only, but it is likely to work with many other .torrent files as well.

There are two .torrent files given in the template, cs450files01.torrent and cs450files.torrent. For cs450files01.torrent, there are 3 seeds running for it. Each of them can upload files at 300KB/s. To handle cs450files01.torrent, it only needs to communicate with seeds and download pieces from them. For cs450files.torrent, there is 1 seed running for it, while at least 8 peers are downloading. Each of them is limited to 100KB/s as upload speed. To handle this torrent file, besides leeching from seed, the client has to upload pieces to other peers to make them continue transmitting pieces.

TURN-IN REQUIREMENTS

Grab the skeleton code from hw-bonus in the public repository. Modify the files (assignment is named hw6 inside the directory) so that it passes the code requirements below. To download the files associated with a given .torrent file, simply run ./hw6 cs450files.torrent. The skeleton code can successfully download from seeds using threads, so the previous command should work properly if you have everything set up correctly.

Grading

There’s no grading script for this assignment. Points will be given as follows:

  1. 6 points if your code operates properly with only one thread of control, e.g. no pthreads/fork.

  2. 2 points for consistently finishing download of cs450files01.torrent (not the cs450files.torrent version)

  3. 2 points for significant upload activity (you can look for this with wireshark)

  4. 2 points for finishing faster with peers than with seeds only (e.g. correctly implementing tit-for-tat algorithm)

The grade you receive for this assignment will have equal weight to one homework. It will be due Friday, December 6 at 3 PM, with no late turn ins - code committed after 3:00 PM will not be graded or receive any points.