To ensure compatibility with the original BT client, we have made changes such that the new BT client just behaves as the original one when invoked with the default arguments. Our changes are limited to a few files as listed below:
Here we give some instructions on how to run our modified BT client to enable multiple identities. Currently we only provide command-line interface. First of all, please make sure Python 2.4 and BitTorrent 4.0.4 are installed. Suppose BitTorrent is installed under you home directory, and please copy btdownloadheadless.py to ~/Bittorrent/.
And then please copy these files under directory: ~/Bittorrent/BitTorrent/, which contains all BitTorrent library files.
And now, you can begin to run our modified client.First in defaultargs.py we add a few more options. One is to specify the process ID that the BT client runs with. Second is the number of processes that will be created. In this way, each process knows which pieces it needs to download for fixed-range piece assignment approach. Third is to specify the location of log file which we can save the times when download starts and ends. The fourth option specifies where to save individual pieces. The fifth option specifies whether processes upload pieces downloaded by other processes or not. The six option specifies whether fixed-piece selection or random-piece selection algorithm is used.
Then we derive a subclass RangedPiecePicker (defined in a new file rangedpiecepicker.py) from PiecePicker to override the default piece selection algorithm.
For the fixed-range piece selection case, each process can determine the piece range based on its process ID and the number of total processes created.
For the random-piece selection case, each process needs to check the common directory to see which pieces have been downloaded or are being downloaded by other pieces and will not consider them any more. Once the algorithm chooses a piece that is not requested yet, it will create the piece file exclusively to let other processes know that it will request to download this piece.
In either case, each process announces its interest in these pieces to its peers (through INTERESTED messages) and download/upload these pieces like normal BT clients. When these processes nish downloading their assigned pieces, they will regard this as task completed and leave the swarm. This is different from the original BT client in that the latter will stay in the swarm for some time to act as seeder for other peers. It should be noted that these processes are perfectly legal to leave the swarm. After all, each process indeed does not have the complete file and it should not act as seeders. Such changes are made in files download.py and Downloader.py.
However, this is not the end of the whole process. When these processes leave the torrent, the pieces they have downloaded may be saved out of order or other pieces may be filled with zeros. So it is important for each process to order its pieces correctly and then write the part it takes charge of to disk. Then a separate process can assemble these parts correctly. Such changes are made in the file StorageWrapper.py.
In the case when a common directory is used, it is also possible to skip the reordering part and just concatenate all the pieces together to get the complete file.