Skip to content

Rustastic/media_client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages