Expand description
Asset distribution for large file transfers.
This module provides efficient transfer of large files (textures, maps, mods) with chunking, integrity verification, and resumable downloads.
§Architecture
┌────────────────────────────────────────────────────────────────┐
│ Asset Transfer │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Chunker │───▶│ Compressor │───▶│ Sender │ │
│ │ (64KB) │ │ (LZ4) │ │ (Reliable) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Hasher │◀───│ Assembler │◀───│ Receiver │ │
│ │ (BLAKE3) │ │ │ │ (Ordered) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└────────────────────────────────────────────────────────────────┘§Features
- Chunked Transfer: Splits large files into 64KB chunks
- Compression: Optional LZ4 compression for faster transfers
- Integrity: BLAKE3 hash verification per chunk and per file
- Resumable: Can resume interrupted transfers
- Progress: Real-time progress callbacks
§Example
§Server (sending assets)
use fastnet::assets::{AssetServer, AssetConfig};
#[tokio::main]
async fn main() -> std::io::Result<()> {
let mut server = AssetServer::new(AssetConfig::default());
// Register assets to serve
server.register("map_forest.pak", "/game/maps/forest.pak").await?;
server.register("textures.pak", "/game/textures/pack1.pak").await?;
// Handle requests (integrate with your game server)
// server.handle_request(peer_id, request).await?;
Ok(())
}§Client (downloading assets)
use fastnet::assets::{AssetClient, AssetEvent};
#[tokio::main]
async fn main() -> std::io::Result<()> {
let mut client = AssetClient::new();
// Request an asset
client.request("map_forest.pak", "/local/maps/forest.pak").await?;
// Process download
loop {
for event in client.poll().await? {
match event {
AssetEvent::Progress { id, received, total } => {
let percent = (received as f64 / total as f64) * 100.0;
println!("Downloading: {:.1}%", percent);
}
AssetEvent::Completed { id, path } => {
println!("Downloaded: {}", path);
break;
}
AssetEvent::Failed { id, error } => {
eprintln!("Failed: {}", error);
break;
}
}
}
}
Ok(())
}Structs§
- Asset
Chunk - Outgoing chunk for transfer.
- Asset
Client - Client-side asset downloading.
- Asset
Config - Configuration for asset transfers.
- Asset
Info - Asset metadata.
- Asset
Server - Server-side asset management.
- Transfer
Stats - Transfer statistics.
Enums§
- Asset
Event - Asset transfer events.
Constants§
- DEFAULT_
CHUNK_ SIZE - Default chunk size (64KB).
Functions§
- deserialize_
asset_ info - Deserialize asset info from network.
- deserialize_
chunk - Deserialize a chunk from network.
- serialize_
asset_ info - Serialize asset info for network transfer.
- serialize_
chunk - Serialize a chunk for network transfer.