communitas-core 0.12.3

Core business logic for Communitas - PQC collaboration with virtual disks
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Storage metrics collection and reporting

use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;

/// Collects and manages storage system metrics
#[derive(Debug)]
pub struct StorageMetrics {
    personal_storage_ops: Arc<RwLock<u64>>,
    group_storage_ops: Arc<RwLock<u64>>,
    dht_storage_ops: Arc<RwLock<u64>>,
}

impl Default for StorageMetrics {
    fn default() -> Self {
        Self::new()
    }
}

impl StorageMetrics {
    pub fn new() -> Self {
        Self {
            personal_storage_ops: Arc::new(RwLock::new(0)),
            group_storage_ops: Arc::new(RwLock::new(0)),
            dht_storage_ops: Arc::new(RwLock::new(0)),
        }
    }

    pub async fn record_personal_storage(&self, _size: usize) {
        let mut ops = self.personal_storage_ops.write().await;
        *ops += 1;
    }

    pub async fn record_group_storage(&self, _group_id: &str, _size: usize, _shards: usize) {
        let mut ops = self.group_storage_ops.write().await;
        *ops += 1;
    }

    pub async fn record_local_hit(&self) {
        // Stub implementation
    }

    pub async fn record_dht_fallback(&self) {
        // Stub implementation
    }

    pub async fn record_reed_solomon_success(&self) {
        // Stub implementation
    }

    pub async fn record_dht_backup_used(&self) {
        // Stub implementation
    }

    pub async fn record_dht_storage_accepted(&self, _size: usize, _requester: &str) {
        let mut ops = self.dht_storage_ops.write().await;
        *ops += 1;
    }

    pub async fn get_current_metrics(&self) -> HashMap<String, u64> {
        let personal_ops = *self.personal_storage_ops.read().await;
        let group_ops = *self.group_storage_ops.read().await;
        let dht_ops = *self.dht_storage_ops.read().await;

        let mut metrics = HashMap::new();
        metrics.insert("personal_storage_ops".to_string(), personal_ops);
        metrics.insert("group_storage_ops".to_string(), group_ops);
        metrics.insert("dht_storage_ops".to_string(), dht_ops);

        metrics
    }
}