Skip to content

Polijen/UDP_File_Transfer_with_Forward_Error_Correction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

UDP File Transfer with Forward Error Correction (FEC)

Language Platform Protocol

Overview

This project implements a robust, unidirectional file transfer system over UDP. Designed to overcome the unreliability of connectionless protocols without the overhead of TCP retransmission, this application utilizes Forward Error Correction (FEC) principles (specifically Erasure Coding via libpar2) to ensure data integrity.

The sender slices a file, generates redundancy packets (repair blocks), and transmits them alongside the data. The receiver uses multi-threading to listen on multiple ports, capturing data and redundancy information simultaneously. If packets are lost during transmission, the receiver reconstructs the original file using the redundancy blocks.

Key Features

  • Erasure Coding / FEC: Uses par2 (Reed-Solomon codes) to generate redundancy data, allowing file recovery even with significant packet loss.
  • Multi-threaded Receiver: Implements pthread to listen concurrently on distinct ports for Data, Redundancy, and Control signals.
  • Custom Application Layer Protocol: Defines a specific packet structure including File ID, Size, Part Number, and Payload.
  • Integrity Verification: Automated SHA-256 checksum validation upon transfer completion.
  • Non-blocking I/O: Utilizes select() for efficient socket handling and timeout management.
  • Sparse File Handling: Uses lseek to write data out-of-order at correct offsets, handling packet reordering naturally.

Architecture

Packet Structure

To handle fragmentation and reordering, the application wraps data in a custom 1472-byte UDP packet (max payload to fit within standard Ethernet MTU):

Field Size Description
File ID 100 bytes Unique identifier/filename
File Size 8 bytes Total size of the file
Part Number 8 bytes Index of the current chunk
Data 1356 bytes Actual file content

Communication Flow

The system utilizes three UDP ports starting from a base port P:

  1. Port P (Data Channel): Transmits the actual chunks of the source file.
  2. Port P+1 (Redundancy Channel): Transmits .par2 recovery files generated based on the user-specified redundancy percentage.
  3. Port P+2 (Control/Integrity Channel): Transmits the SHA-256 hash and a "Finalization" signal.

Prerequisites

The project relies on standard Linux libraries and specific command-line tools for mathematical operations.

  • OS: Linux
  • Compiler: GCC
  • Dependencies:
    • libpar2 (command line tool par2 must be installed)
    • shasum (part of perl-digest-sha or coreutils)
# Ubuntu/Debian
sudo apt-get install par2 shasum build-essential

Compilation

gcc sender.c -o sender
gcc receiver.c -o receiver -pthread

Usage

1. Start the Receiver

# Syntax: ./receiver <PORT>
./receiver 4555

1. Start the Sender

# Syntax: ./sender <FILE_PATH> <REDUNDANCY_%> <IP_ADDRESS> <PORT>
./sender my_large_video.mp4 10 127.0.0.1 4555

Redundancy %: The percentage of extra data to generate (e.g., 10 means 10% overhead). Higher values allow recovery from higher packet loss rates.

This project was developed as a study on reliable data transfer protocols over unreliable networks using Forward Error Correction.

About

Robust unidirectional file transfer system over UDP implementing Forward Error Correction (FEC) via Reed-Solomon codes. Features a custom application-layer protocol, multi-threaded architecture and automatic data reconstruction

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors