b8186d4b52e7873fc49039e60c97dd9275c94133
Reviewed-on: #5
FastFileTransfer
A high-performance file synchronization system that implements a custom client-server protocol for efficient file transfer with compression and multithreading support.
Technical Overview
FastFileTransfer is a C implementation of a file synchronization system that:
- Uses a custom TCP-based protocol for client-server communication
- Implements chunked file transfer (10MB chunks by default)
- Supports zstd compression with configurable levels (1-22)
- Utilizes multithreading for parallel file processing
- Implements producer-consumer patterns with thread-safe queues
- Provides both in-memory and disk-based storage options
System Architecture
The system consists of two main components:
Client
- Scans source directories recursively
- Creates file chunks with configurable size (10MB default)
- Compresses data using zstd algorithm
- Sends files to server using custom protocol
- Supports both single-threaded and multi-threaded operation
Server
- Listens for client connections on port 8080
- Receives files using the custom protocol
- Decompresses received data
- Stores files either in memory or on disk
- Implements thread pool for parallel processing
Protocol Details
The client-server communication uses the following status codes:
STATUS_OK: Operation successfulSTATUS_ERROR: Error occurredSTATUS_FINISHED: Transfer completeSTATUS_NEXT: Ready for next chunk
Configuration Options
Command Line Arguments
| Argument | Description |
|---|---|
-m |
Enable multithreading mode |
-c [level] |
Enable compression with optional level (1-22, default: 5) |
-s |
Enable chunk serialization |
Environment Variables
| Variable | Description | Default |
|---|---|---|
FASTSYNC_SOURCE_DIR |
Source directory for files | Current user's documents directory |
FASTSYNC_DEST_DIR |
Destination directory | ./data_copied |
FASTSYNC_SERVER_IP |
Server IP address | 127.0.0.1 |
FASTSYNC_SERVER_PORT |
Server port | 8080 |
FASTSYNC_SAVE_TO_DISK |
Save to disk (true/false) | false |
Implementation Details
Data Structures
- Chunk: Collection of files (default 10MB total size)
- File: File metadata with path and content
- FileReceive: Received file data structure
- Config: Configuration parameters structure
- Queue: Thread-safe queue implementation using condition variables
Key Algorithms
- File Scanning: Recursive directory traversal with BFS
- Chunking: Files grouped into chunks with size limit
- Compression: zstd compression with configurable levels
- Network Protocol: Custom TCP-based protocol with status codes
- Thread Synchronization: Condition variables and mutexes for thread coordination
Build Requirements
- C11 compatible compiler
- CMake 4.1 or later
- zstd library
- pthread support
Building
mkdir -p build && cd build
cmake ..
make
Running
Server
./build/server
Client
# Basic usage
./build/client -m -c 10
Testing
The project includes comprehensive unit tests for core functionality:
./build/tests
Code Organization
src/
client/ # Client implementation
server/ # Server implementation
shared/ # Shared data structures and utilities
tests/ # Unit tests
Performance Considerations
- Chunk size (10MB default) affects memory usage and transfer efficiency
- Compression level (1-22) trades CPU usage for space savings
- Multithreading improves performance on multi-core systems
- Thread-safe queues minimize contention between producer/consumer threads
Extensibility
The system is designed with clear interfaces that allow for:
- Additional compression algorithms
- Different transport protocols
- Custom storage backends
- Extended metadata support
Description
Languages
C
86.3%
Python
12.6%
CMake
0.8%
Dockerfile
0.1%