A sophisticated, multi-threaded client-server file management system that implements four distinct concurrency control models for secure, collaborative file access. This system allows multiple clients to view, edit, upload, download, and manage files in a shared directory with configurable access policies, ensuring data integrity and preventing conflicts through advanced locking mechanisms.
- Key Features
- Concurrency Models
- Available Commands
- Prerequisites
- Installation & Compilation
- Running the System
- Usage Examples
- Troubleshooting
- Project Structure
- Contributing
- License
- Four Concurrency Models: Implements EREW, CREW, ERCW, and CRCW models for flexible access control.
- Real-Time Lock Status: Detailed reporting of file lock states, including lock type (READ/WRITE) and active users.
- Robust Server Architecture: Handles abrupt client disconnections gracefully, with automatic cleanup of stale locks.
- External Editor Integration: Seamless integration with
nanoorvimfor remote file editing via the dedicated client. - Thread-Safe Logging: Comprehensive logging with timestamps, user tracking, and color-coded console output for easy monitoring.
- Multi-Threaded Design: Efficiently manages multiple concurrent clients using C++ threads and mutexes.
- Cross-Platform Compatibility: Designed for Linux/Unix systems with C++17 support.
- Security Features: Username authentication, input validation, and access control based on concurrency models.
- File Operations: Full CRUD (Create, Read, Update, Delete) support for files and directories.
- Automatic Directory Creation: Server auto-creates the shared directory if it doesn't exist.
The system supports four classical concurrency control models, each balancing safety and performance differently:
-
EREW (Exclusive Read Exclusive Write):
- Only one user can access a file at a time (read or write).
- Maximum safety, minimum concurrency.
- Ideal for critical files requiring strict serialization.
-
CREW (Concurrent Read Exclusive Write):
- Multiple users can read simultaneously.
- Only one user can write at a time, blocking all reads during writing.
- Balances safety and performance for read-heavy workloads.
-
ERCW (Exclusive Read Concurrent Write):
- Only one user can read at a time.
- Multiple users can write simultaneously.
- Suitable for write-heavy scenarios with occasional reads.
-
CRCW (Concurrent Read Concurrent Write):
- Maximum concurrency: multiple users can read and write simultaneously.
- Minimal restrictions, highest performance.
- Best for collaborative environments with low conflict risk.
| Command | Syntax | Description |
|---|---|---|
LIST / LS |
LIST |
Display all files in the shared directory with details (size, permissions, owner, modified time). |
INFO / EXIFTOOL |
INFO <filename> |
Show detailed file metadata (size, permissions, owner, timestamps, lock status). |
VIEW / CAT / SHOW |
VIEW <filename> |
Display the complete contents of a file. |
EDIT / WRITE / NANO |
EDIT <filename> |
Open an external editor (nano/vim) to modify a file (client-side only). |
UPLOAD / PUT |
UPLOAD <local_file> <remote_file> |
Upload a local file to the shared directory. |
DOWNLOAD / GET |
DOWNLOAD <remote_file> <local_file> |
Download a file from the shared directory to local machine. |
DELETE / RM / DEL |
DELETE <filename> |
Remove a file from the shared directory. |
MKDIR / MKD |
MKDIR <dirname> |
Create a new directory in the shared directory. |
RMDIR / RMD |
RMDIR <dirname> |
Remove an empty directory from the shared directory. |
TOUCH / CREATE |
TOUCH <filename> |
Create a new empty file. |
LOCKWRITE / LOCK |
LOCKWRITE <filename> |
Acquire an exclusive write lock on a file. |
UNLOCKWRITE / UNLOCK |
UNLOCKWRITE <filename> |
Release the write lock on a file. |
LOCKSTATUS / FILESTATUS |
LOCKSTATUS <filename> |
Check the current lock status and access permissions for a file. |
HELP |
HELP |
Display the command reference menu. |
EXIT / QUIT |
EXIT |
Disconnect from the server. |
- Operating System: Linux/Unix-based system (tested on Kali Linux, Ubuntu, Debian).
- Compiler: C++17 compatible compiler (e.g., g++ 7.0+).
- Build Tools:
makeutility. - Libraries: POSIX threads (
pthread), readline library (libreadline-dev). - Editors:
nanoorvimfor file editing (auto-detected by client). - Network Tools:
netcat(optional, for basic client connections). - Enhanced CLI:
rlwrap(recommended for better interactive experience withnetcat).
Install prerequisites on Debian/Ubuntu/Kali:
sudo apt-get update
sudo apt-get install -y build-essential libpthread-stubs0-dev libreadline-dev libc6-dev make nano vim rlwrap-
Clone or download the project:
git clone https://github.com/TheLeopard65/Network-File-Editor.git cd Network-File-Editor -
Compile the project:
make clean make
-
Verify compilation:
ls -la nfe_server nfe_client
nfe_server: The server executable.nfe_client: The client executable with editor integration.
- Debug Build (default):
make- Includes debug symbols and no optimizations. - Release Build:
make release- Optimized for performance, no debug symbols. - Clean Build:
make clean- Removes all compiled binaries and logs.
The server can be started with default settings or customized via command-line arguments.
# Basic usage (defaults: port 2121, EREW model, ./share/ directory)
./nfe_server
# Custom configuration
./nfe_server -p 3333 -d /path/to/shared/dir -m CREW
# Command-line options:
# -p, --port PORT Server port (default: 2121)
# -d, --directory DIR Shared directory path (default: ./share/)
# -m, --model MODEL Concurrency model: EREW, CREW, ERCW, CRCW (default: EREW)
# -h, --help Display help messageServer Logs: All server activity is logged to NFE-Server.log with timestamps and user tracking.
Method 1: Dedicated Client (Recommended)
./nfe_client [server_ip] [port]
# Examples:
./nfe_client # Connect to localhost:2121
./nfe_client 192.168.1.100 3333 # Connect to specific IP/port
./nfe_client -h # Show client helpMethod 2: Using netcat (Basic)
nc localhost 2121Method 3: Using netcat with rlwrap (Enhanced Interactive Experience)
rlwrap nc localhost 2121Note: rlwrap provides arrow key support, command history, and tab completion for a much better CLI experience.
Upon connection, clients must provide a username (alphanumeric, underscores, hyphens only, max 50 characters). The server then displays the active concurrency model and available commands.
# List files
LIST
# View file contents
VIEW example.txt
# Get file information
INFO example.txt
# Create a new file
TOUCH newfile.txt
# Create a directory
MKDIR myfolder
# Upload a local file
UPLOAD /local/path/file.txt remote_file.txt
# Download a file
DOWNLOAD remote_file.txt /local/path/file.txt# Edit with external editor
EDIT example.txtNote: This acquires a write lock, downloads the file, opens it in nano/vim, uploads changes, and releases the lock automatically.
# Check lock status
LOCKSTATUS example.txt
# Manual lock acquisition (for advanced users)
LOCKWRITE example.txt
# Manual lock release
UNLOCKWRITE example.txtUnlocked File:
[+] Current File Lock Status:
>>> UNLOCKED
>>> You can acquire WRITE lock
>>> You can acquire READ lock
File Locked for Writing (EREW/CREW):
[+] Current File Lock Status:
>>> LOCKED for WRITE Access by User: leopard
>>> WRITE access is currently restricted
>>> READ access is currently restricted
File Locked for Reading (CREW):
[+] Current File Lock Status:
>>> LOCKED for READ Access by User: alex, kali
>>> WRITE access is currently restricted
>>> You can acquire READ lock
File Locked for Concurrent Writing (ERCW):
[+] Current File Lock Status:
>>> LOCKED for CONCURRENT WRITE Access by User: leopard, alex (Total: 2)
>>> You can acquire WRITE lock
>>> READ access is currently restricted
-
User 1 (leopard) starts editing:
EDIT document.txt
File is locked for writing.
-
User 2 (alex) checks status:
LOCKSTATUS document.txt
Shows locked by leopard.
-
User 2 tries to edit:
EDIT document.txt
Access denied based on concurrency model.
-
User 1 finishes editing: Lock automatically released after upload.
-
User 2 can now edit:
EDIT document.txt
| Issue | Symptom | Solution |
|---|---|---|
| Compilation fails | g++: command not found |
Install build-essential: sudo apt-get install build-essential |
| Linker errors | undefined reference to readline |
Install libreadline-dev: sudo apt-get install libreadline-dev |
| Server won't start | Bind failed |
Check if port is in use: netstat -tlnp | grep :2121 |
| Client can't connect | Connection refused |
Ensure server is running and IP/port are correct |
Arrow keys show ^[[D |
Using nc without wrapper |
Use rlwrap nc localhost 2121 |
| File permissions | Permission denied |
Check shared directory permissions on server |
| Editor not found | Failed to execute editor |
Install nano or vim: sudo apt-get install nano vim |
| Stale locks | Files remain locked after crash | Server auto-cleans locks after 5 minutes (configurable) |
| High CPU usage | Many concurrent clients | Reduce client connections or increase server resources |
| Log file grows large | NFE-Server.log too big |
Rotate logs manually or implement log rotation |
[-] ERROR: Cannot read file - Access denied!: File is locked by another user in a restrictive model.[-] ERROR: Cannot acquire write lock for <file>: Another user holds an incompatible lock.[-] ERROR: Username contains invalid characters: Use only alphanumeric, underscore, hyphen.[-] ERROR: Failed to execute editor: Installnanoorvim.
- Server: Increase
ulimit -nfor more open file descriptors if handling many clients. - Client: For large files, increase socket buffer sizes in
client.cppif needed. - Models: Use CRCW for maximum performance, EREW for maximum safety.
Network-File-Editor/
├── LICENSE # MIT License file
├── Makefile # Build configuration and rules
├── README.md # This documentation
├── requirements.txt # List of system dependencies
├── share/ # Default shared directory (auto-created)
│ ├── code.cpp # Sample C++ file
│ ├── info.txt # Sample text file
│ └── script.sh # Sample shell script
├── source/ # Source code directory
│ ├── client/ # Client-side code
│ │ ├── client.cpp # Main client implementation
│ │ ├── client.hpp # Client header
│ │ └── main_client.cpp # Client entry point
│ ├── common/ # Shared utilities
│ │ ├── concurrency.cpp # Concurrency model implementations
│ │ ├── concurrency.hpp # Concurrency headers
│ │ ├── config.hpp # Configuration management
│ │ ├── logger.cpp # Logging system
│ │ └── logger.hpp # Logger headers
│ └── server/ # Server-side code
│ ├── client_handler.cpp # Client connection handling
│ ├── client_handler.hpp # Handler headers
│ ├── file_manager.cpp # File operations
│ ├── file_manager.hpp # File manager headers
│ ├── main_server.cpp # Server entry point
│ ├── server.cpp # Main server logic
│ └── server.hpp # Server headers
└── NFE-Server.log # Server activity log (auto-generated)
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name - Make changes and test thoroughly.
- Ensure code follows C++17 standards and includes proper error handling.
- Update documentation if adding new features.
- Submit a pull request with a clear description of changes.
- Use C++17 features consistently.
- Follow RAII principles for resource management.
- Add comprehensive logging for new features.
- Test with all four concurrency models.
- Handle edge cases (file not found, permission denied, network errors).
- Update the README for any new commands or features.
This project is licensed under the MIT License. See the LICENSE file for complete details.