A simple peer-to-peer file sharing system using TCP sockets.
View Source.
This was made for an assignment in a graduate course on Operating Systems.
For educational purposes.
Caution
Warranty NOT included. Use at your own risk.
The system consists of two components:
-
Tracker:
A server that keeps track of the files available on the network.
It listens for incoming connections from clients and other trackers.
It also responds to queries from clients and other trackers. -
Client: A client that connects to the tracker to get a list of files available on the network.
It can download files from other clients on the network.
It can also upload files to other clients on the network.
The tracker is a server that listens for incoming connections from clients and other trackers.
Every request to the tracker is saved as a Transaction.
Atleast one tracker must be online at any point in time.
Whenever a new tracker joins the network, it receives a list of all the successful transactions from the others.
The new tracker then executes these transactions to get up to date with the network.
The client connects to the tracker to get a list of files available on the network. It can download files from other clients on the network.
There are 2 daemon-type components that run in the background.
The DownloadManager is responsible for downloading files from other clients on the network.
The user of the class can enqueue a download request, and the DownloadManager will download the file in the background.
The user can either poll the status of the downloads or register a callback to be notified when the download is complete.
This is a part of our custom networking library.
The TCP Server is a high-level abstraction over TCP socket, which in turn is a high-level abstraction over the POSIX socket API.
The TCPServer class is loosely based on the QTcpServer class from the Qt framework.
TCPSocket is similarly modelled after QTcpSocket.
-
The default block size for files is 512 KB.
This can be changed by modifying theblock_sizeconstant in fileinfo.hpp. -
TCP Server uses the
selectsystem call to handle multiple connections.
As a result, the maximum number of connections it can handle is limited.
The system will not scale well, and has problems handling files with many pieces.
When I created it, I was not aware of the existence of the improvedpollandepollsystem calls.
Honestly,select()should be deprecated by now. See:
This project has a .editorconfig file to enforce project level coding standards.
CLion has built-in support,
VSCode requires a plugin.
Important
Requires a POSIX compliant system.
This project requires CMake to build.
Your IDE (VSCode or CLion) should automatically detect the CMakeLists.txt file and build the project.
Install extensions for CMake support if prompted.
If you are using the command line, you can run the following commands:
cmake -B build
cmake --build build --config Release
./build/tracker/tracker ./build/tracker_info.txt 1 # run the tracker first
./build/client/client 127.0.0.1:9999 ./build/tracker_info.txt # and then the clientquit
quitcreate_user <user_id> <passwd>login <user_id> <passwd>logoutcreate_group <group_id>join_group <group_id>leave_group <group_id>list_requests <group_id>accept_request <group_id> <user_id>list_groupslist_files <group_id>upload_file <file_path> <group_id>download_file <group_id> <file_name> <destination_path>show_downloads
This project uses Doxygen to generate documentation.
If Doxygen is available on your system,
You can generate the documentation by running the doc CMake target.
cmake -B build
cmake --build build --target docThis repository also has an automated workflow to generate documentatation via Github Actions.
The generated documentation can be viewed at /docs.
pushd docs ; python3 -m http.server 9999; popd # if you have python installed and want to use a serveropen docs/index.html # or open the file from the OS file managerA good starting point to explore the codebase is the file listing page. (files.html if you are viewing this in a browser)