SPQR
Selective Protocol for Quality and Reliability
A comprehensive implementation of reliable UDP file transfer with Selective Repeat protocol.
Features & API
Introduction
The aim of the project is to design and implement in C language using the Berkeley Socket API a client-server application for file transfer that uses the connectionless network service (socket type SOCK_DGRAM, i.e. UDP as transport layer protocol).
Core Features
Connection
Client-server connection without authentication
LIST Command
View available files on server
GET Command
Download files from server
PUT Command
Upload files to server
Reliable Transfer
Implemented with Selective Repeat protocol
RICK Command
Never gonna give you up, never gonna let you down...
Protocol Specification
1. Packet Structure
// Data Packet typedef struct { int8_t payload[PACKET_SIZE]; // Data payload int32_t seq_num; // Sequence number int32_t no_packets_to_send; // Total packets int64_t no_bytes_to_send; // Total bytes int64_t size; // Packet size bool sent; // Sent flag bool received; // Received flag bool ack; // ACK flag } packet_t;// Acknowledgment Packet typedef struct { int32_t seq_num; // Sequence number int64_t size; // Packet size int64_t write_byte; // Bytes written } ack_packet_t;
2. Control Flags
Indicates if the packet has been sent
Indicates if the packet has been received
Acknowledgment flag for packet confirmation
3. Selective Repeat Implementation
Window Management
- Dynamic window sizing (8-128 packets)
- Sliding window mechanism
- Out-of-order packet buffering
Timeout Handling
- Static or adaptive RTO
- RTT smoothing (EWMA)
- Individual packet timers
Error Control
- Sequence number tracking
- Selective acknowledgments
- Packet size verification
4. State Machine
The protocol implements a finite state machine with the following states:
- CLOSED: Initial state, waiting for connection or server start
- LISTEN: Server is waiting for client connections
- SYN_SENT: Client has sent connection request, waiting for server response
- ESTABLISHED: Connection established, ready for commands (LIST, GET, PUT)
- WAIT_FOR_COMMAND: Waiting for client to send a command
- WAIT_FOR_ACK: Waiting for acknowledgment of sent packets
- FIN_WAIT: Client is closing the connection
Note: After 3 failed connection attempts, the client is blocked.
Quick Start Guide
Build Instructions
make
Standard build with optimizations
make debug
Build with debug symbols and logging
make rick
Never gonna give you up... 🎵
make clean
Remove build artifacts
Usage Guide
1. Start the Server
Launch the server on your desired machine:
./bin/server
2. Connect with Client
Connect to the server using the client:
./bin/client <server-ip>
3. Available Commands
LIST- View files on serverGET- Download a filePUT- Upload a fileCLOSE- End connection
____ ____ ___ ____ / ___| | _ \ / _ \ | _ \ \___ \ | |_) | | | | | | |_) | ___) | | __/ | |_| | | _ < |____/elective |_|rotocol for \__\_\uality and |_| \_\eliability
____ ____ ___ ____ / ___| | _ \ / _ \ | _ \ \___ \ | |_) | | | | | | |_) | ___) | | __/ | |_| | | _ < |____/elective |_|rotocol for \__\_\uality and |_| \_\eliability
╔═════════════════════════════════╗ ║ FILE TRANSFER COMPLETED ║ ╠═════════════════════════════════╣ ║ TIME = 0.477041 sec ║ ║ THROUGHPUT = 40980.98 kB/s ║ ╚═════════════════════════════════╝
Performance Benchmarks
Adaptive Timeout Performance
Analysis of throughput with different window sizes using adaptive timeout strategy. Our research shows significant improvements in network efficiency when using dynamic adjustment methods.
- Improved response times
- Reduced network congestion
- Better resource utilization
Static Timeout Performance
Analysis of throughput with fixed timeout values, showing baseline performance characteristics and limitations of static approaches.
Cumulative Error Analysis
Evaluation of error accumulation in different timeout strategies, demonstrating the superior reliability of our adaptive approach.
Comparative Analysis
Direct comparison between adaptive and static timeout strategies, showing the advantages of our dynamic approach in various network conditions.
Throughput
Average transfer speed of 20MB/s under optimal conditions
- Peak performance: 40MB/s
- Minimum guaranteed: 10MB/s
- Adaptive based on network conditions
Reliability
99.99% successful transfer rate
- Automatic error recovery
- Corruption detection
- Packet loss handling
Scalability
Tested with:
- Up to 2727 concurrent connections
- Files up to 10GB
- Various network conditions
Enterprise Solutions
SPQR is a robust implementation of a reliable file transfer protocol built on UDP. It demonstrates how to achieve TCP-like reliability while maintaining the performance advantages of UDP.
Technology Stack
- C Programming Language
- Berkeley Sockets API
- GNU Make Build System
Project Information
- Open Source License: GPLv3
- Version: 1.0.0
- Last Updated: February 2025