mutant_lib/index/master_index/
mod.rs

1use crate::config::NetworkChoice;
2use crate::index::pad_info::PadInfo;
3use serde::{Deserialize, Serialize};
4use std::collections::BTreeMap;
5
6// Re-export modules
7mod core;
8mod key_management;
9mod pad_management;
10mod status;
11mod public_keys;
12mod import_export;
13mod utils;
14
15#[cfg(test)]
16mod tests;
17
18// Re-export utility functions
19pub use utils::get_index_file_path;
20
21/// Represents an entry in the master index, which can be either private key data or public upload data.
22#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
23pub enum IndexEntry {
24    PrivateKey(Vec<PadInfo>),
25    PublicUpload(PadInfo, Vec<PadInfo>),
26}
27
28/// The central index managing all keys and scratchpads.
29#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
30pub struct MasterIndex {
31    /// Mapping from key names (e.g., file paths or public upload IDs) to their detailed information.
32    index: BTreeMap<String, IndexEntry>,
33
34    /// List of scratchpads that are currently free and available for allocation.
35    /// Each tuple contains the address, the associated encryption key, and the generation ID.
36    free_pads: Vec<PadInfo>,
37
38    /// List of scratchpads that are awaiting verification.
39    /// Each tuple contains the address and the associated encryption key.
40    pending_verification_pads: Vec<PadInfo>,
41
42    network_choice: NetworkChoice,
43}
44
45#[derive(Debug, Default)]
46pub struct StorageStats {
47    pub nb_keys: u64,
48    pub total_pads: u64,
49    pub occupied_pads: u64,
50    pub free_pads: u64,
51    pub pending_verification_pads: u64,
52}