Socket Programming, SHA1 hash, Multi-threading in C++
In this assignment, you need to build a group based file sharing system where users can share, download files from the group they belong to. Download should be parallel with multiple pieces from multiple peers.
- You have to divide the file into logical “pieces”, wherein the size of each piece should be 512KB.
- SHA1 : Suppose the file size is 1024KB, then divide it into two pieces of 512KB each and take SHA1 hash of each part, assume that the hashes are HASH1 & HASH2 then the corresponding hash string would be H1H2 , where H1 & H2 are starting 20 characters of HASH1 & HASH2 respectively and hence H1H2 is 40 characters.
- Authentication for login needs to be done
The Following entities will be present in the network :
1. Server(or Tracker)( 1 tracker system) :
Maintain information of clients with their files(shared by client) to assist the clients for the communication between peers
2. Clients:
a. User should create an account and register with tracker
b. Login using the user credentials
c. Create Group and hence will become owner of that group
d. Fetch list of all Groups in server
e. Request to Join Group
f. Leave Group
g. Accept Group join requests (if owner)
h. Share file across group: Share the filename and SHA1 hash of the complete file as well as piecewise SHA1 with the tracker
i. Fetch list of all sharable files in a Group
j. Download file
i. Retrieve peer information from tracker for the file
ii. Core Part: Download file from multiple peers (different pieces of file from
different peers - piece selection algorithm ) simultaneously and all the files which client downloads will be shareable to other users in the same group.
k. Show downloads
l. Stop sharing file
m. Stop sharing all files(Logout)
n. Whenever client logins, all previously shared files before logout should
automatically be on sharing mode
- go to client directory
g++ client.cpp -o client -lssl -lcrypto -lpthread
- go to server directory
g++ server.cpp -o server -lpthread
./server <my_server_ip> <my_server_port>
eg : ./server 127.0.0.1 5000
./client <CLIENT_IP> <CLIENT_PORT> <SERVER_IP> <SERVER_PORT>
-
creating client1 on new terminal with socket : 127.0.0.1:6000
eg :./client 127.0.0.1 6000 127.0.0.1 5000
-
creating client2 on another terminal with socket : 127.0.0.1:7000
eg :./client 127.0.0.1 7000 127.0.0.1 5000
1. Create User Account :
create_user <user_id> <passwd>
2. Login :
login <user_id> <passwd>
3. Create Group :
create_group <group_id>
4. Join Group :
join_group <group_id>
5. Leave Group :
leave_group <group_id>
6. List Pending Request :
requests list_requests <group_id>
7. Accept Group Joining Request :
accept_request <group_id> <user_id>
8. List All Group In Network :
list_groups
9. List All sharable Files In Group :
list_files <group_id>
10. Upload File :
upload_file <file_path> <group_id>
eg.: upload_file /home/rishabh/F/video.mp4 my_grp
11. Download File :
download_file <group_id> <file_name> <destination_path>
eg.: download_file my_grp video.mp4 /home/rishabh/D/
12. Logout :
logout
13. Show_downloads :
show_downloads
Output format:
[D] [grp_id] filename
[C] [grp_id] filename
D(Downloading), C(Complete)
14. Stop sharing :
stop_share <group_id> <file_name>
- Enter absolute path for files.