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.
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_2024library for underlying network structures.
The client automatically fetches, assembles, and displays files including embedded media, opening them in the browser when required.
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.
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.
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.
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.
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
- Language: Rust (edition 2021)
- Dependencies:
wg_2024– networking and packet structurescrossbeam-channel– asynchronous messaginglog,colored– logging and colored outputhtml_parser,image,base64– parsing HTML and decoding mediawebbrowser– automatic opening of files
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
Developed for the Advanced Programming course,
University of Trento, A.Y. 2024–2025
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