Skip to content

Sankalp0109/P2P-Distributed-File-Sharing-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

P2P Distributed File Sharing System

A peer-to-peer distributed file sharing system implemented in C++ with dual tracker architecture, multi-threaded downloads, and automatic seeder promotion.

Features

Core Functionality

  • 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

Technical Features

  • 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

Architecture

┌─────────────────┐    ┌─────────────────┐
│   Tracker 1     │◄──►│   Tracker 2     │
│   (Port 5000)   │    │   (Port 7000)   │
└─────────┬───────┘    └─────────┬───────┘
          │                      │
          └──────────┬───────────┘
                     │
         ┌───────────▼───────────┐
         │                       │
    ┌────▼────┐  ┌────▼────┐  ┌──▼──────┐
    │Client 1 │  │Client 2 │  │Client N │
    │(Peer)   │  │(Peer)   │  │(Peer)   │
    └─────────┘  └─────────┘  └─────────┘
         ▲            ▲            ▲
         └────────────┼────────────┘
                      │
              P2P File Transfer

Components

  1. Tracker Servers: Manage user authentication, group membership, and file metadata
  2. Client Applications: Handle user interface, file operations, and peer-to-peer transfers
  3. Peer Servers: Each client runs a server to share downloaded chunks with other peers

Requirements

  • Operating System: Linux
  • Compiler: g++ with C++11 support
  • Dependencies: pthread library (included in most Linux distributions)
  • Network: TCP socket support

Installation & Compilation

1. Clone/Extract the Project

cd /path/to/project/2025201083_A3

2. Compile Tracker Servers

cd tracker
make clean-all
make

3. Compile Client Application

cd ../client
make clean-all
make

Running the System

Step 1: Start Tracker Servers

Terminal 1 - Primary Tracker:

cd tracker
./tracker tracker_info.txt 1

Terminal 2 - Secondary Tracker:

cd tracker
./tracker tracker_info.txt 2

The tracker_info.txt file contains:

127.0.0.1:5000
127.0.0.1:7000

Step 2: Start Client Applications

Terminal 3 - Client 1:

cd client
./client 127.0.0.1:5001 tracker_info.txt

Terminal 4 - Client 2:

cd client
./client 127.0.0.1:5002 tracker_info.txt

Terminal 5 - Client 3:

cd client
./client 127.0.0.1:5003 tracker_info.txt

Usage Guide

Basic Workflow

  1. Create User & Login:
create_user <username> <password>
login <username> <password>
  1. Create/Join Groups:
create_group <group_name>
join_group <group_name>
list_groups
  1. 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>
  1. Group Management:
list_requests <group_name>
accept_request <group_name> <username>
leave_group <group_name>
logout

Example Session

Client 1 (File Uploader):

create_user nik password123
login nik password123
create_group documents
upload_file documents /home/user/document.pdf

Client 2 (File Downloader):

create_user mayank password456
login mayank password456
join_group documents

Client 1 (Accept Request):

list_requests documents
accept_request documents mayank

Client 2 (Download File):

list_files documents
download_file documents document.pdf /home/bob/downloads/

Features

Multi-Peer 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

Automatic Seeding

  • Downloaded chunks immediately become available for sharing
  • No manual seeding required - happens automatically
  • BitTorrent-style swarm behavior with rarest-first piece selection

Fault Tolerance

  • Dual tracker synchronization ensures no data loss
  • Automatic failover between tracker servers
  • Persistent file sharing across client restarts

File Integrity

  • SHA1 verification for complete files and individual chunks
  • Automatic retry for corrupted chunks
  • Comprehensive error handling and recovery

Project Structure

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

Common Issues

  1. Port Already in Use:

    • Change client port numbers when starting multiple clients
    • Ensure tracker ports (5000, 7000) are available
  2. Connection Refused:

    • Verify tracker servers are running before starting clients
    • Check firewall settings for the required ports
  3. File Not Found:

    • Ensure file paths are absolute when uploading
    • Verify group membership before file operations
  4. Download Failures:

    • Check that uploading peer is online and sharing the file
    • Verify sufficient disk space for downloads

Performance

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors