Skip to content

Latest commit

Β 

History

History
117 lines (81 loc) Β· 3.97 KB

File metadata and controls

117 lines (81 loc) Β· 3.97 KB

media_client

Rust License: GPL v3

media_client is a Rust library that implements a client for the Rustastic network, capable of sending, receiving, and assembling text and media files in a distributed network of nodes.
This project was developed as part of the Advanced Programming course (A.Y. 2024–2025) at the University of Trento.


🎯 Project Overview

The goal of this project is to provide a robust client capable of:

  • Handling text and media files with distributed references;
  • Managing network communication through packets, commands, and events;
  • Assembling files from fragments (FileAssembler);
  • Performing flood-based network discovery and routing;
  • Integrating with the wg_2024 library for underlying network structures.

The client automatically fetches, assembles, and displays files including embedded media, opening them in the browser when required.


🧠 Design Highlights

1. MediaClient Architecture

The MediaClient is the main logic unit responsible for:

  • Maintaining network connectivity and packet routing (Router);
  • Sending and receiving messages and commands (MediaClientCommand, MediaClientEvent);
  • Managing file assembly and media references (FileAssembler);
  • Sending ACK/NACK packets and handling flood requests/responses.

2. FileAssembler

FileAssembler manages:

  • Text files containing references to media (<img src="media_id">);
  • Media file storage and association with text files;
  • Generation of complete HTML files with decoded media;
  • Automatic opening of assembled files in the browser.

3. Network Communication

The client communicates with other nodes using:

  • Packets (Packet) of various types: MsgFragment, Ack, Nack, FloodRequest, FloodResponse;
  • Flooding mechanism to discover network topology;
  • Routing based on headers computed from Router.

4. Concurrency

The client uses crossbeam channels for:

  • Receiving commands from the controller;
  • Sending events to the controller;
  • Managing packets in and out of the network asynchronously.

🧩 Repository Structure

src/
β”œβ”€β”€ lib.rs                  # Library entry point and public exports
└── media_client/
   β”œβ”€β”€ mod.rs               # MediaClient struct and core methods
   β”œβ”€β”€ file_assembler.rs    # Handling text and media files
   β”œβ”€β”€ handle_command.rs    # MediaClientCommand processing
   β”œβ”€β”€ handle_message.rs    # Handling messages received from network
   β”œβ”€β”€ send_to.rs           # Sending packets or events to controller
   └── handle_packet/
      β”œβ”€β”€ mod.rs            # Packet processing logic (ACK, NACK, Flood)
      └── test.rs           # Unit tests

βš™οΈ Technical Stack

  • Language: Rust (edition 2021)
  • Dependencies:
    • wg_2024 – networking and packet structures
    • crossbeam-channel – asynchronous messaging
    • log, colored – logging and colored output
    • html_parser, image, base64 – parsing HTML and decoding media
    • webbrowser – automatic opening of files

πŸ§ͺ Testing and Validation

Unit tests verify:

  • Correct assembly of text and media files;
  • Proper handling of packet types (MsgFragment, Ack, Nack, FloodRequest, FloodResponse);
  • Flooding-based discovery and routing of network nodes.

Run tests with:

> cargo test

πŸ“š Acknowledgements

Developed for the Advanced Programming course,
University of Trento, A.Y. 2024–2025


πŸͺͺ License

This project is released under the GNU General Public License v3.0 (GPLv3).
See https://www.gnu.org/licenses/gpl-3.0.html.

Β© 2025 Giulio Bosio