sgx-daemon/src/config.rs
Noor 37fbe80d42
switching to sloat and credit system
updated proto
change all units to mib
calculating sloat ration while new app and sending resource
2025-06-30 20:07:19 +05:30

62 lines
1.5 KiB
Rust

// SPDX-License-Identifier: Apache-2.0
use anyhow::Result;
use serde::Deserialize;
use std::ops::Range;
use crate::global::IP_INFO;
#[derive(Debug, Clone, Deserialize)]
pub struct HostConfig {
pub network: String,
#[serde(default = "retrieve_node_ip")]
pub host_ip_address: String,
pub operator_wallet: String,
pub max_cores_per_app: u32,
pub max_memory_mib_per_app: u32,
pub max_vcpu_reservation: u32,
pub max_mem_reservation_mib: u32,
pub max_disk_reservation_mib: u32,
pub max_ports_per_app: u32,
// price per unit per minute
pub price: u64,
#[serde(with = "range_format")]
pub public_port_range: Range<u16>,
pub delete_archive: bool,
}
fn retrieve_node_ip() -> String {
IP_INFO.ip.clone()
}
mod range_format {
use serde::{Deserialize, Deserializer, Serialize};
use std::ops::Range;
pub fn deserialize<'de, D>(deserializer: D) -> Result<Range<u16>, D::Error>
where
D: Deserializer<'de>,
{
let range_repr = RangeRepr::deserialize(deserializer)?;
Ok(range_repr.start..range_repr.end)
}
#[derive(Serialize, Deserialize)]
struct RangeRepr {
start: u16,
end: u16,
}
}
impl HostConfig {
pub fn load_from_disk(path: &str) -> Result<Self> {
let content = std::fs::read_to_string(path)?;
let config: Self = serde_yml::from_str(&content)?;
// TODO: validate all the resource are available in node
Ok(config)
}
}