A peer-to-peer distributed file sharing system implemented in C++ with dual tracker architecture, multi-threaded downloads, and automatic seeder promotion.
- User & Group Management: Create users, login/logout, create/join/leave groups
- File Operations: Upload, download, list files, stop sharing
- Downloads: Multi-peer parallel downloads with chunk-based file sharing
- Automatic Seeder Promotion: Downloaded chunks immediately become available for other peers
- Dual Tracker Architecture: Two synchronized tracker servers for fault tolerance
- Real-Time Swarming: Dynamic peer discovery and chunk availability tracking
- 512KB Chunk Size: Files split into 512KB chunks for efficient distribution
- SHA1 Integrity: Complete file and individual chunk verification using SHA1 hashing
- Thread Pool Architecture: Configurable parallel downloads (2x CPU cores, minimum 4 threads)
- Persistent File Sharing: Files remain available across login/logout cycles
┌─────────────────┐ ┌─────────────────┐
│ Tracker 1 │◄──►│ Tracker 2 │
│ (Port 5000) │ │ (Port 7000) │
└─────────┬───────┘ └─────────┬───────┘
│ │
└──────────┬───────────┘
│
┌───────────▼───────────┐
│ │
┌────▼────┐ ┌────▼────┐ ┌──▼──────┐
│Client 1 │ │Client 2 │ │Client N │
│(Peer) │ │(Peer) │ │(Peer) │
└─────────┘ └─────────┘ └─────────┘
▲ ▲ ▲
└────────────┼────────────┘
│
P2P File Transfer
- Tracker Servers: Manage user authentication, group membership, and file metadata
- Client Applications: Handle user interface, file operations, and peer-to-peer transfers
- Peer Servers: Each client runs a server to share downloaded chunks with other peers
- Operating System: Linux
- Compiler: g++ with C++11 support
- Dependencies: pthread library (included in most Linux distributions)
- Network: TCP socket support
cd /path/to/project/2025201083_A3cd tracker
make clean-all
makecd ../client
make clean-all
makeTerminal 1 - Primary Tracker:
cd tracker
./tracker tracker_info.txt 1Terminal 2 - Secondary Tracker:
cd tracker
./tracker tracker_info.txt 2The tracker_info.txt file contains:
127.0.0.1:5000
127.0.0.1:7000
Terminal 3 - Client 1:
cd client
./client 127.0.0.1:5001 tracker_info.txtTerminal 4 - Client 2:
cd client
./client 127.0.0.1:5002 tracker_info.txtTerminal 5 - Client 3:
cd client
./client 127.0.0.1:5003 tracker_info.txt- Create User & Login:
create_user <username> <password>
login <username> <password>
- Create/Join Groups:
create_group <group_name>
join_group <group_name>
list_groups
- File Operations:
upload_file <group_name> <file_path>
list_files <group_name>
download_file <group_name> <filename> [destination_path]
show_downloads
stop_share <group_name> <filename>
- Group Management:
list_requests <group_name>
accept_request <group_name> <username>
leave_group <group_name>
logout
Client 1 (File Uploader):
create_user nik password123
login nik password123
create_group documents
upload_file documents /home/user/document.pdfClient 2 (File Downloader):
create_user mayank password456
login mayank password456
join_group documentsClient 1 (Accept Request):
list_requests documents
accept_request documents mayankClient 2 (Download File):
list_files documents
download_file documents document.pdf /home/bob/downloads/- Files are automatically split into 512KB chunks
- Downloads occur simultaneously from multiple peers
- Real-time progress tracking with thread-safe updates
- Automatic failover if peers become unavailable
- Downloaded chunks immediately become available for sharing
- No manual seeding required - happens automatically
- BitTorrent-style swarm behavior with rarest-first piece selection
- Dual tracker synchronization ensures no data loss
- Automatic failover between tracker servers
- Persistent file sharing across client restarts
- SHA1 verification for complete files and individual chunks
- Automatic retry for corrupted chunks
- Comprehensive error handling and recovery
2025201083_A3_Interim/
├── client/
│ ├── client.cpp # Main client logic and networking
│ ├── file_operations.cpp # File upload/download operations
│ ├── file_operations.h # File operations header definitions
│ ├── handle_download.cpp # Download coordination and management
│ ├── handle_download.h # Download manager header definitions
│ ├── peer_server.cpp # P2P server for chunk sharing
│ ├── peer_server.h # Peer server header definitions
│ ├── thread_pool.cpp # Thread pool for parallel downloads
│ ├── thread_pool.h # Thread pool header definitions
│ ├── sha.cpp # SHA1 hashing utilities
│ ├── sha.h # SHA1 utilities header
│ ├── Makefile # Client compilation rules
│ └── tracker_info.txt # Tracker server addresses
├── tracker/
│ ├── tracker.cpp # Main tracker server logic
│ ├── data.cpp # Data management and storage
│ ├── command.cpp # Command processing and handlers
│ ├── sync.cpp # Inter-tracker synchronization
│ ├── tracker.h # Header definitions
│ ├── Makefile # Tracker compilation rules
│ └── tracker_info.txt # Tracker configuration
├── Performance_Analysis_Report.md # Performance analysis and implementation details
└── README.md # This file
-
Port Already in Use:
- Change client port numbers when starting multiple clients
- Ensure tracker ports (5000, 7000) are available
-
Connection Refused:
- Verify tracker servers are running before starting clients
- Check firewall settings for the required ports
-
File Not Found:
- Ensure file paths are absolute when uploading
- Verify group membership before file operations
-
Download Failures:
- Check that uploading peer is online and sharing the file
- Verify sufficient disk space for downloads
- Chunk Size: 512KB for optimal network utilization
- Thread Pool: Automatically configured based on CPU cores
- Concurrent Downloads: Multiple peers simultaneously
- Memory Usage: Efficient chunk-based processing