e7c23c135b09feffe674f4721625c28650480e7b
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
- Serializes chunks into a compact binary format for batch transfer
- 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 file (per-file mode)STATUS_CHUNK: Following data is a serialized chunk (chunk mode)
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 (batch-transfer all files per chunk) |
--source-dir <path> |
Source directory to sync (overrides FASTSYNC_SOURCE_DIR) |
--dest-dir <path> |
Server-side destination directory (overrides FASTSYNC_DEST_DIR) |
--save-to-disk |
Persist received files to disk |
Environment Variables
| Variable | Description | Default |
|---|---|---|
FASTSYNC_SOURCE_DIR |
Source directory for files (fallback, overridden by --source-dir) |
Current user's documents directory |
FASTSYNC_DEST_DIR |
Destination directory (fallback, overridden by --dest-dir) |
./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 (fallback, overridden by --save-to-disk) |
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 with default settings (sends from ~/Documents/...)
./build/client -m -c 10
# Specify source and destination directories
./build/client --source-dir /path/to/send --dest-dir /path/to/receive --save-to-disk
# Chunk serialization mode (batch per chunk)
./build/client -s
# Compressed chunk serialization
./build/client -s -c 3
# Multithreaded with compressed chunk serialization
./build/client -m -s -c 3
Testing
The project includes comprehensive unit tests for core functionality:
./build/tests
An integration test / benchmark script runs all configurations against ~50 MB of generated test data with byte-for-byte verification:
python3 test.py
# Skip the throttled suite (disk I/O limits + 100ms network delay) if sudo is unavailable:
python3 test.py --no-throttled
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%