Skip to main content

firecloud_net/
protocol.rs

1//! File transfer protocol using libp2p request-response
2//!
3//! Defines the messages for chunk transfer between peers
4
5use serde::{Deserialize, Serialize};
6
7/// Protocol identifier for FireCloud file transfer
8pub const PROTOCOL_NAME: &str = "/firecloud/transfer/1.0.0";
9
10/// Request types for file transfer
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub enum TransferRequest {
13    /// Request a specific chunk by hash
14    GetChunk {
15        /// BLAKE3 hash of the chunk (32 bytes hex)
16        hash: String,
17    },
18    /// Offer to store a chunk on this peer
19    StoreChunk {
20        /// BLAKE3 hash of the chunk
21        hash: String,
22        /// Compressed, encrypted chunk data
23        data: Vec<u8>,
24        /// Original size before compression
25        original_size: u64,
26    },
27    /// Query if peer has a specific chunk
28    HasChunk {
29        hash: String,
30    },
31    /// Request file manifest by file ID
32    GetManifest {
33        file_id: String,
34    },
35    /// Announce that this peer has a file available
36    AnnounceFile {
37        file_id: String,
38        /// List of chunk hashes that make up this file
39        chunk_hashes: Vec<String>,
40        /// Total file size
41        total_size: u64,
42        /// File name (optional)
43        name: Option<String>,
44    },
45}
46
47/// Response types for file transfer
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub enum TransferResponse {
50    /// Chunk data in response to GetChunk
51    Chunk {
52        hash: String,
53        data: Vec<u8>,
54        original_size: u64,
55    },
56    /// Response to StoreChunk - whether it was stored
57    Stored {
58        hash: String,
59        success: bool,
60        message: Option<String>,
61    },
62    /// Response to HasChunk query
63    HasChunk {
64        hash: String,
65        has_it: bool,
66    },
67    /// File manifest response
68    Manifest {
69        file_id: String,
70        /// CBOR-serialized FileManifest
71        manifest_data: Vec<u8>,
72        /// Summary fields (for quick display without deserializing)
73        chunk_hashes: Vec<String>,
74        total_size: u64,
75        name: Option<String>,
76    },
77    /// Acknowledgment for file announcement
78    FileAnnounced {
79        file_id: String,
80        accepted: bool,
81    },
82    /// Error response
83    Error {
84        message: String,
85    },
86    /// Chunk not found
87    NotFound {
88        hash: String,
89    },
90}