This project implements an emulated peer to peer file sharing service, based on the BitTorrent specification. The purpose of the project is to learn how to build a peer to peer application using socket programming to solve file sharing bottlenecks in client-server models, in which multiple clients would download files hosted on a single server. The goal is to implement a decentralized process that allows clients to share (upload & download) files in segments (pieces) from other various clients purely through peer to peer TCP connections.
Contributors:
- Richard Dong
- Winston Ye
- Leon Trieu
- Python 3.8+, pip3 installed
- OS: Linux Ubuntu, Windows 10
-
Ensure you meet the necessary environment requires above
-
In the project root directory 'p2py', run the setup.py script by:
pip3 install -e ./
-
In the directory 'src', you can start the start the server (tracker):
python3 tracker.py [src_port]
-
Start as many clients (peers) by opening a new terminal and run:
python3 client_handler.py [src_ip] [src_port] [tracker_ip] [tracker_port]
- tracker_ip and port is visible in the tracker's command line window
In the SRC directory..
- Start the tracker:
python3 tracker.py 8888
and note the IP address being served. - Start a client on a new terminal by:
python3 client_handler.py 127.0.0.1 8881 [tracker_ip] 8888
Assert the client connected successfully and the Command Line Interface is presented.
- Use the CLI to enter [3] and upload a file
- Type to enter the provided sample file:
input/music.mp3
Assert the tracker received the request payload to start uploading a file
Assert the client is now seeding the file
...
Continuing from uploading..
- With the tracker and current seeder terminal still active, start a new client that will download the file:
python3 client_handler.py 127.0.0.2 8882 [tracker_ip] 8888
- Use the CLI to enter '1' to retrieve the latest list of torrents
Assert the file 'music.mp3' is available in the list of torrents, and the list contains the seeder's id
- Use the CLI to enter '2' to download the torrent and enter its torrent id: '0'
Assert the client is now downloading the file from the seeder
- After the download is successful, assert the newly downloaded file was written to the /output folder. The program prepends the client's peer id to the filename for distinguishing downloads.
Assert the client started seeding automatically after the download was complete
...
Continuing from downloading a file..
- With the tracker and current two seeder terminals active, open another terminal and create another peer by repeating the steps from [Downloading a file] with a different client ip & port
Assert the list of torrents contains the additional seeder, and during the download it retrieves data from both available seeders.
...
Continuing from downloading from more than one peer...
- Choose two of the clients that are seeding, and enter 'CTRL+C' to stop seeding for both.
- Start a new unique client_handler.py
- Use the CLI to enter '1' to get the list of torrents. Assert that the two seeders have left, and that the last seeder is the only one left seeding in the list
p2py requires the specified the source port for the tracker/client to be a open port (through port forwarding) if you wish to host a tracker server/seed torrents. By default, the peer and tracker will use the 8888 port. For testing purposes on a single machine, you can host a tracker server and connect/seed/leech with other clients without port forwarding.
- Exiting the seeding status with "CTRL+C" may sometimes yield some exceptions, which are related to the aysncio event loop handling. These exceptions may not be caught (due to the asynchronous behaviour) and printed to terminal. However, these are not a concern to the functionality of the application, as the seeder will still first be able to update it's seeding status in the tracker before disconnecting.
- If the seeder abruptly disconnects from the tracker (for example force-closing the terminal), the seeder's status may not be updated in the tracker's side and still continue to be "seeding". If this occurs, please just restart the tracker and workflow.