4867e04677ef44a0bc3a8425c6db7f7cf716b0b7
- Fix scanner: when chunk fills up mid-directory, save DIR handle so remaining files in that directory are not skipped (pre-existing bug) - Fix -c -s: add STATUS_CHUNK to protocol, send it before chunk data, handle it on the server side for both single and multithreaded paths - Extract chunk_serialize/chunk_deserialize from chunk_compress/decompress - Remove dead declarations (file_receive_from_buffer, etc.) - Fix memory leak in receive_file_receive (free -> data_destroy) - test.py generates ~50 MB of test data across bulk files - All 8 integration tests + 7 unit tests pass
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) |
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
# 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
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%