Skip to content

Taranjain/Distributed-File-Repository-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—„οΈ Distributed File Repository System

A secure, multi-client file management system with real-time chat capabilities built on a Client-Server architecture.

Demo Demo


✨ Features

Feature Description
πŸ“€ Upload Securely upload files to a central server with chunked transfer
πŸ“₯ Download Download files from the server with encrypted transmission
πŸ—‘οΈ Delete Remove files from the server repository
πŸ’¬ Real-Time Chat Store-and-forward messaging system between users
πŸ‘₯ Multi-User Support Concurrent connections with multi-threading
πŸ” Security SSL/TLS encryption, certificate-based authentication
πŸ–₯️ GUI User-friendly graphical interface

πŸ—οΈ System Architecture

Client-Server Model

The system operates on a Client-Server Architecture where:

  • Server: Acts as a "Private Cloud" running on a specific IP and TCP port (9998). It is concurrent - handles multiple users simultaneously without blocking.
  • Clients: User-facing GUI applications that initiate requests. They don't store data permanently - they only push (upload) or pull (download) data from the central server.
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client A  │◄───────►│   Server (Cloud)  │◄───────►│  Client B   β”‚
β”‚   (GUI)     β”‚         β”‚  10.0.14.87:9998  β”‚         β”‚    (GUI)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                        β”‚
                                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                              β”‚    Client C       β”‚
                                              β”‚    (GUI)          β”‚
                                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”’ Security Layer

SSL/TLS Handshake

  1. Socket Creation: Standard TCP stream socket ensures reliable data delivery
  2. TLS Handshake: Server presents its digital certificate (server.crt)
  3. Encrypted Tunnel: All data (passwords, files, chat) is encrypted before transmission
Client                            Server
  β”‚                                  β”‚
  │───── TCP Connection ─────────────►│
  β”‚                                  β”‚
  │───── TLS Handshake ─────────────►│
  β”‚    (Certificate Exchange)        β”‚
  │◄───── Encrypted Tunnel ──────────│
  β”‚                                  β”‚
  │───── Encrypted Data ────────────►│
  │◄───── Encrypted Response ────────│

πŸ”‘ Authentication

The server implements session-based authentication:

  1. Client establishes secure connection
  2. Client sends: LOGIN <username> <password>
  3. Server validates credentials against internal dictionary
  4. Success β†’ 200 OK + is_authenticated = True
  5. Failure β†’ Connection rejected

Only authenticated users can access the server_files directory.


🧡 Multi-Threading

The server uses Python's threading module for concurrent user handling:

  • Main Server Loop: Listens for new connections
  • Per-Client Thread: Spawns handle_client thread for each new user
  • Result: User A can upload, User B can delete, User C can chat - simultaneously!
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  Main Server    β”‚
                    β”‚     Loop        β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚                 β”‚                 β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
    β”‚  Thread 1  β”‚   β”‚  Thread 2   β”‚   β”‚  Thread 3   β”‚
    β”‚ (User A)   β”‚   β”‚ (User B)    β”‚   β”‚ (User C)    β”‚
    β”‚  UPLOAD    β”‚   β”‚   DELETE    β”‚   β”‚    CHAT     β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ File Transfer Mechanics

Chunking Technique

Files are transferred in 1KB blocks to avoid loading entire files into RAM:

  1. Client sends: PUT <filename>
  2. Server opens file and responds: READY
  3. Client loop: Read 1KB β†’ Encrypt β†’ Send β†’ Repeat
  4. Client sends: FILE_END marker
  5. Server decrypts and writes each chunk to disk
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   FILE TRANSFER                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Client                                              β”‚
β”‚    β”‚                                                β”‚
β”‚    β”œβ”€β”€β–Ί READ 1KB ───► ENCRYPT ───► SEND             β”‚
β”‚    β”‚                                                β”‚
β”‚    β”œβ”€β”€β–Ί READ 1KB ───► ENCRYPT ───► SEND             β”‚
β”‚    β”‚                                                β”‚
β”‚    └──► SEND FILE_END ─────────────────────────────►│
β”‚                                                      β”‚
β”‚  Server                                              β”‚
β”‚    β”‚                                                β”‚
β”‚    β”œβ”€β”€β—„ RECEIVE ───► DECRYPT ───► WRITE to disk    β”‚
β”‚    β”‚                                                β”‚
β”‚    β”œβ”€β”€β—„ RECEIVE ───► DECRYPT ───► WRITE to disk    β”‚
β”‚    β”‚                                                β”‚
β”‚    └──◄ FILE_END                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ’¬ Chat System: Store-and-Forward

Polling Mechanism

Since TCP is a single data stream, the server acts as a temporary mailbox:

  1. User A sends a message β†’ Stored in chat_history list
  2. User B polls every 2 seconds: GET_CHAT
  3. Server responds with latest chat history
  4. Result: Real-time chat illusion without complex async protocols
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     Polls every 2s      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Client A│◄────────────────────────►│ Server  β”‚
β”‚         β”‚    "Any new messages?"  β”‚         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                         β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                                         β”‚
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚   chat_history: []      β”‚
                            β”‚   [msg1, msg2, msg3...] β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     Receives                 β”‚
β”‚ Client Bβ”‚β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚         β”‚    [msg1, msg2, msg3...]
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”’ Client-Side Concurrency: Thread Lock (Mutex)

The Client GUI handles two simultaneous operations:

  1. Background: Auto-refreshes chat every 2 seconds
  2. Foreground: Waiting for user to click "Upload"

The Problem

If both happen simultaneously, data streams could mix β†’ Protocol Violation

The Solution: Thread Lock (Mutex)

  • Acts like a "talking stick"
  • Before sending data, a function must acquire the Lock
  • If Upload holds the Lock, Chat Refresh waits until upload finishes
  • Prevents crashes during simultaneous operations

πŸš€ Getting Started

Prerequisites

  • Python 3.x
  • Required libraries: socket, ssl, threading, tkinter

Running the Server

python server.py

The server will start on 0.0.0.0:9998 and use SSL/TLS encryption.

Running the Client

python client_gui.py

Connect to the server using the server's IP address and port 9998.


πŸ“ Project Structure

Distributed-File-Repository-System/
β”œβ”€β”€ client_gui.py          # Client GUI application
β”œβ”€β”€ server.py              # Server application
β”œβ”€β”€ server.crt            # SSL certificate
β”œβ”€β”€ server.key            # SSL private key
β”œβ”€β”€ server_files/         # Repository directory for files
β”œβ”€β”€ image1.png            # Demo screenshot 1
β”œβ”€β”€ image2.png            # Demo screenshot 2
└── Readme.md             # This file

πŸ”§ Supported Commands

Command Description
LOGIN <user> <pass> Authenticate with server
PUT <filename> Upload a file
GET <filename> Download a file
DELETE <filename> Delete a file from server
LIST List all files on server
GET_CHAT Retrieve chat history
SEND_CHAT <msg> Send a chat message

πŸ›‘οΈ Security Features

  • βœ… TLS/SSL Encryption - All data encrypted in transit
  • βœ… Certificate-Based Authentication - Server identity verification
  • βœ… Session Management - Authentication state tracking
  • βœ… Per-User Thread Isolation - Secure multi-user environment

πŸ“Š Technical Highlights

  • Protocol: TCP Stream Sockets with SSL/TLS
  • Port: 9998
  • Chunk Size: 1024 bytes (1KB)
  • Chat Poll Interval: 2 seconds
  • Concurrency: Multi-threaded (one thread per client)

Built with ❀️ using Python

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors