Christo Wilson
CS 4700 / CS 5700 - Network Fundamentals

Project 5: Selfish BitTorrent Client

This project is due at 11:59pm on December 4, 2013.

Description

You will modify the trading policy of a BitTorrent client in order to improve the download performance. Unlike previous projects, a portion of your grade in this project will come from how your code performs when run against the solutions of your classmates, i.e. this assignment is a competition.

In this project, you will have to do background reading on BitTorrent. Since we are providing you with a working implementation, you are expected to research the BitTorrent trading scheme, improvements to it, and possible fairness attacks. Simply turning in the code that we provide (or a slightly modified implementation) will result in a very low grade. You should write selfish code, the goal of which is to improve your download speed.

Project Requirements

We will provide you with source code for an open-source BitTorrent client. Thus, all you must do is increase the performance of your client. In particular, your code must outperform the solutions of your peers, in terms of download speed. In other words, the first BitTorrent to download the file is the winner.

Clearly, you should not assume that the BitTorrent peers you are downloading from will follow the protocol. Since these are the solutions of your classmates, they may be malicious, they may upload bad data, they may lie to you, and they certainly will be greedy and selfish. Your solution should handle these errors gracefully, recover, download the file correctly, and not crash.

You may use any technique that you want to speed up your BitTorrent client, except for denial-of-servicing your peers. The techniques presented in class, from the research literature, may all be used. You are encouraged to come up with your own optimizations as well.

WARNING!

During this project, you will be writing and testing out BitTorrent clients. Do not, under any circumstances, test your code by downloading copyrighted or illegal content. Any such behavior will result in both legal and academic penalities. Instead, only join torrents that you create yourself, and share junk data (e.g., created via head -c 1000000 /dev/urandom).

Your Program

For this project, you will submit a complete BitTorrent program. It is recommended that you use the starter code provided by us; however, you may implement a BitTorrent client from scratch if you so wish (and are crazy). If you do so, you are welcome to use a language of your choice. However, if you implement a torrent client from scratch all of the code must be your own: you are not allowed to use code from other BitTorrent implementations.

The starter code is the Snark BitTorrent client. You can download Snark here, and more information is available on the project website. Snark is written in Java, and is designed to be compiled and run on the command line.

The command line syntax for Snark (and thus, your program) is given below. The program takes either a filename or a url pointing to a tracker. The syntax for launching your sending program is therefore:

Usage: java -jar snark.jar [--debug [level]] [--port <port>] [--show-peers] [--share <ip> <file>] [<url>]

with the following details:

Luckily, the code we provide to you already does all of the argument parsing and supports these options. You should develop your BitTorrent program on the CCIS Linux machines, as these have the necessary compiler and library support. You are welcome to use your own Linux/OS X/Windows machines, but you are responsible for getting your code working, and your code must work when graded on the CCIS Linux machines.

Testing Your Code

In order for you to test your code, the code we provide can be used to set up a private torrent for you to test with. In order to start a torrent, you will execute

java -jar snark.jar --share <ip> <filename>

where <ip> is the IP address that you want Snark to bind to, and <filename> is the name of the file you wish to share via the torrent. In the output, you will see the line

Torrent available on <url>

Leave this process running (as it is serving as the seeder). In order to connect clients to this torrent, you simply run

java -jar snark.jar <url>

Since BitTorrent is a scalable protocol, you can run any number of clients. However, make sure that each client instance is running in its own directory; if all of the Snark clients are run from the same directory, they will all attempt to write to the exact some download file on disk, and you will get error.

When testing, it's easy to leave old Snark processes running in the background. To clean these up, you can run killall -9 java (note that this will kill any other Java programs you have running as well).

Shark Tank

In order for you to test your code against others', we will be providing a simulator that will periodically run your code against the code of your peers. Called the Shark Tank, it will allow you to try out new approaches to maximize your performance, to test how well your code is working, and to make sure that your code works in the test harness that we will use to grade.

The Shark Tank works by creating a virtual network inside a normal Linux server. During each simulation, a BitTorrent seed will be started that is sharing a 100MB file. Once the seed is online, all of the student BitTorrent clients will be executed and passed the URL of the seed. Each BitTorrent client in the network will be connected to a 1 Mbps virtual network link with 10ms of latency. All BitTorrent instances will be bound to the loopback interface (127.0.0.1).

Each BitTorrent client will be limited to opening 12 total file descriptors (ulimit -n 12). Thus, you will need to carefully manage your open sockets, since at least 1 descriptor will need to be used to write the downloaded file to disk.

To submit your code to the Shark Tank, simply turn in you code as usual using the turn-in scripts. We will periodically copy everyone's submissions to the Shark Tank and run a simulation (i.e. start a new torrent seed, then have everyone's clients join the swarm and attempt to download the file). The results of the simulations will be posted online; the URL for the results will be announced on Piazza.

Grading

Your grade in this project will be composed by the following components: The final competition in the Shark Tank will be held on December 9. We will conduct twenty simulations and average the download times for each team to get a final score. The top 1/3 scores will each earn 3 points, the middle 1/3 will earn 2 points, and the bottom 1/3 will earn 1 point.

Extra Credit

The top ranked team in the Shark Tank on December 9 will earn 3 bonus points! :)

Submitting Your Project

Before turning in your project, you and your partner(s) must register your group. To register yourself in a group, execute the following script:
$ /course/cs5700f13/bin/register project5 [team name]
This will either report back success or will give you an error message. If you have trouble registering, please contact the course staff. You and your partner(s) must all run this script with the same [team name]. This is how we know you are part of the same group.

To turn-in your project, you should submit your (thoroughly documented) code along with three other files:

Your README, Makefile, source code, etc. should all be placed in a directory. You submit your project by running the turn-in script as follows:
$ /course/cs5700f13/bin/turnin project5 [project directory]
[project directory] is the name of the directory with your submission. The script will print out every file that you are submitting, so make sure that it prints out all of the files you wish to submit! The turn-in script will not accept submissions that are missing a README or a Makefile. Only one group member needs to submit your project. Your group may submit as many times as you wish; only the time of the last submission will determine whether your assignment is late.

Advice

A few pointers that you may find useful while working on this project:

Contact Info
  • Office: West Village H 248
  • +1 617 373 2177