The deadline for this lab is Wednesday 12 November 2008, xx:xx:xx hours. Strictly no submissions will be accepted after the deadline.
BitTorrent is a well known Peer-To-Peer file transfer system. The simplified objective of the BitTorrent Client is to download a file from your peers. Here, we will focus on the BitTorrent Client, which shall be known simply as the client.
Suppose a file is divided into n blocks, your program must work when 1 <= n <= 5000.
For our example, let n be 40. Then the blocks are numbered from 1 to 40 inclusive. The blocks are always numbered starting from 1 to n inclusive.
Initially, the client does not have any blocks of the file. As the client downloads the blocks from other peers, the client will mark the blocks downloaded successfully as blocks that we have. The blocks that we do not yet have are (obviously) marked as blocks that we don't have.
40 1219634584.3 0 16 1219634584.3 0 18 1219634584.3 0 9 1219634584.3 0 5 1219634632.85 0 25 1219634632.85 0 18 1219634632.85 0 40 1219634632.85 0 37 1219634632.85 0 9 1219634632.85 0 18 1219634632.85 0 27The first line contains the value of n, the number of blocks in the file. Subsequent lines consists of three numbers in each line. The first floating-point number is a time-stamp (time in seconds), the second is an integer, and the third number is the block number that we have downloaded successfully. Ignore the first two numbers in each line.
So, we received block 16 first, followed by block 18, then block 9, and so on. Notice that we receive block 18 two times. If we receive a block that we already have, this is marked as an error, and we print an error message accordingly. The following is the sample output based on the input file mh1.txt:
Number of blocks: 40 Success: Received block 16 Success: Received block 18 Success: Received block 9 Success: Received block 5 Success: Received block 25 Error: Already have block 18 Success: Received block 40 Success: Received block 37 Error: Already have block 9 Error: Already have block 18 Success: Received block 27 Number of blocks we have: 8 Number of blocks we don't have: 32 Number of errors: 3 Have list: 5,9,16,18,25,27,37,40,
Note that the number of lines in the text file is not known. You are to read the file until you reach the end of the text file.
Notice that the last line printed is the “Have list”, which contains the list of the blocks that we have, sorted and printed in ascending order. Let h be the number of blocks in the have list, and d be the number of blocks in the don't-have list (list of blocks that we do not have). If h <= d, we print the list of blocks in the have list; otherwise, print the list of blocks in the don't-have list. Remember that the lists have to be sorted and printed in ascending order.
Let us look at another text file called “mh2.txt” (It has been copied into your directory by the “pesetup” command.) Let us look at the file's contents:
40 1219634584.3 0 16 1219634584.3 0 18 1219634584.3 0 9 1219634584.3 0 5 1219634632.85 0 25 1219634632.85 0 18 1219634632.85 0 40 1219634632.85 0 37 1219634632.85 0 9 1219634632.85 0 18 1219634632.85 0 27 1219634723.93 0 3 1219634723.93 0 20 1219634723.93 0 22 1219634723.93 0 15 1219634723.93 0 4 1219634723.93 0 20 1219634723.93 0 16 1219634723.93 0 29 1219634723.93 0 19 1219634723.93 0 7 1219634723.93 0 10 1219634723.93 0 33 1219634723.93 0 9 1219634723.93 0 8 1219634723.93 0 35 1219634723.93 0 26The following is the sample output based on the input file mh2.txt:
Number of blocks: 40 Success: Received block 16 Success: Received block 18 Success: Received block 9 Success: Received block 5 Success: Received block 25 Error: Already have block 18 Success: Received block 40 Success: Received block 37 Error: Already have block 9 Error: Already have block 18 Success: Received block 27 Success: Received block 3 Success: Received block 20 Success: Received block 22 Success: Received block 15 Success: Received block 4 Error: Already have block 20 Error: Already have block 16 Success: Received block 29 Success: Received block 19 Success: Received block 7 Success: Received block 10 Success: Received block 33 Error: Already have block 9 Success: Received block 8 Success: Received block 35 Success: Received block 26 Number of blocks we have: 21 Number of blocks we don't have: 19 Number of errors: 6 Don't-have list: 1,2,6,11,12,13,14,17,21,23,24,28,30,31,32,34,36,38,39,
Follow the sample output precisely.
Remember to submit your program frequently using the submit btlog.c command, and check your submission using the check command.
All the best!