diff --git a/src/cluster.rs b/src/cluster.rs index ca91f32..fc5117d 100644 --- a/src/cluster.rs +++ b/src/cluster.rs @@ -106,7 +106,7 @@ mod tests { #[derive(Deserialize)] struct TestConfig { - pub cluster_port: u32, + pub cluster_port: Option, pub cluster_id: String, pub cluster_secret: String, } @@ -118,7 +118,7 @@ mod tests { Config::new( None, - "".to_string(), + None, test_conf.cluster_port, test_conf.cluster_id, test_conf.cluster_secret, diff --git a/src/config.rs b/src/config.rs index 79a75ab..82bfaff 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use { crate::fatal, log::{error, info, warn}, std::{env, fs}, + serde::{Serialize, Deserialize} }; const CONFIG_PATH: &str = "config.toml"; @@ -97,12 +98,6 @@ impl Config { }); } - pub fn load() -> Result { - toml::from_str(&self.load_raw()?).map_err(|err| { - fatal!("Failed to parse config file"); - }) - } - pub fn join_center_url(&self, path: &str) -> String { format!("{}{}", self.center_url, path) } diff --git a/src/serve.rs b/src/serve.rs index cd20f5f..2f7a92b 100644 --- a/src/serve.rs +++ b/src/serve.rs @@ -45,8 +45,8 @@ impl IntoResponse for MeasureRes { /// /// export default MeasureRoute /// ``` +/// pub async fn measure(header: HeaderMap, Path(size): Path) -> MeasureRes { - let mut data: Vec = Vec::new(); match header.get("x-openbmclapi-secret") { Some(secret) => { if secret != "secret" { @@ -55,10 +55,9 @@ pub async fn measure(header: HeaderMap, Path(size): Path) -> MeasureRes { if size > 200 { return MeasureRes::BadResquest; } - let buffer: Vec = vec![0x00, 0x66, 0xcc, 0xff]; - for _ in 0..size { - data.extend(&buffer); - } + // size -> size * mb + let mut data: Vec = Vec::with_capacity((size * 1024 * 1024) as usize); + data.fill(114_u8); return MeasureRes::Data(data); } None => MeasureRes::Forbidden