daemon: don't track analysis file bytes written

We don't actually use this for anything
This commit is contained in:
Will Greenberg
2025-07-16 16:51:52 -07:00
committed by Cooper Quintin
parent 5db24e4b21
commit 1011c4b123
4 changed files with 8 additions and 39 deletions

View File

@@ -7,7 +7,7 @@ use axum::{
http::StatusCode,
};
use futures::TryStreamExt;
use log::{debug, error, info};
use log::{error, info};
use rayhunter::analysis::analyzer::{AnalyzerConfig, Harness};
use rayhunter::diag::{DataType, MessagesContainer};
use rayhunter::qmdl::QmdlReader;
@@ -24,7 +24,6 @@ use crate::server::ServerState;
pub struct AnalysisWriter {
writer: BufWriter<File>,
harness: Harness,
bytes_written: usize,
}
// We write our analysis results to a file immediately to minimize the amount of
@@ -39,7 +38,6 @@ impl AnalysisWriter {
let mut result = Self {
writer: BufWriter::new(file),
bytes_written: 0,
harness,
};
let metadata = result.harness.get_metadata();
@@ -48,12 +46,11 @@ impl AnalysisWriter {
}
// Runs the analysis harness on the given container, serializing the results
// to the analysis file, returning the file's new length, and whether any
// warnings were detected
// to the analysis file, returning the whether any warnings were detected
pub async fn analyze(
&mut self,
container: MessagesContainer,
) -> Result<(usize, bool), std::io::Error> {
) -> Result<bool, std::io::Error> {
let mut warning_detected = false;
for row in self.harness.analyze_qmdl_messages(container) {
if !row.is_empty() {
@@ -61,13 +58,12 @@ impl AnalysisWriter {
}
warning_detected |= row.contains_warnings();
}
Ok((self.bytes_written, warning_detected))
Ok(warning_detected)
}
async fn write<T: Serialize>(&mut self, value: &T) -> Result<(), std::io::Error> {
let mut value_str = serde_json::to_string(value).unwrap();
value_str.push('\n');
self.bytes_written += value_str.len();
self.writer.write_all(value_str.as_bytes()).await?;
self.writer.flush().await?;
Ok(())
@@ -133,7 +129,7 @@ async fn perform_analysis(
analyzer_config: &AnalyzerConfig,
) -> Result<(), String> {
info!("Opening QMDL and analysis file for {name}...");
let (analysis_file, qmdl_file, entry_index) = {
let (analysis_file, qmdl_file) = {
let mut qmdl_store = qmdl_store_lock.write().await;
let (entry_index, _) = qmdl_store
.entry_for_name(name)
@@ -147,7 +143,7 @@ async fn perform_analysis(
.await
.map_err(|e| format!("{e:?}"))?;
(analysis_file, qmdl_file, entry_index)
(analysis_file, qmdl_file)
};
let mut analysis_writer = AnalysisWriter::new(analysis_file, analyzer_config)
@@ -171,16 +167,10 @@ async fn perform_analysis(
.await
.expect("failed getting QMDL container")
{
let (size_bytes, _) = analysis_writer
let _ = analysis_writer
.analyze(container)
.await
.map_err(|e| format!("{e:?}"))?;
debug!("{name} analysis: {size_bytes} bytes written");
let mut qmdl_store = qmdl_store_lock.write().await;
qmdl_store
.update_entry_analysis_size(entry_index, size_bytes)
.await
.map_err(|e| format!("{e:?}"))?;
}
analysis_writer

View File

@@ -130,18 +130,13 @@ pub fn run_diag_read_thread(
}
if let Some(analysis_writer) = maybe_analysis_writer.as_mut() {
let analysis_output = analysis_writer.analyze(container).await
let heuristic_warning = analysis_writer.analyze(container).await
.expect("failed to analyze container");
let (analysis_file_len, heuristic_warning) = analysis_output;
if heuristic_warning {
info!("a heuristic triggered on this run!");
ui_update_sender.send(display::DisplayState::WarningDetected).await
.expect("couldn't send ui update message: {}");
}
let mut qmdl_store = qmdl_store_lock.write().await;
let index = qmdl_store.current_entry.expect("DiagDevice had qmdl_writer, but QmdlStore didn't have current entry???");
qmdl_store.update_entry_analysis_size(index, analysis_file_len).await
.expect("failed to update analysis file size");
}
},
Err(err) => {

View File

@@ -51,7 +51,6 @@ pub struct ManifestEntry {
pub start_time: DateTime<Local>,
pub last_message_time: Option<DateTime<Local>>,
pub qmdl_size_bytes: usize,
pub analysis_size_bytes: usize,
pub rayhunter_version: Option<String>,
pub system_os: Option<String>,
pub arch: Option<String>,
@@ -66,14 +65,12 @@ impl ManifestEntry {
start_time: now,
last_message_time: None,
qmdl_size_bytes: 0,
analysis_size_bytes: 0,
rayhunter_version: Some(metadata.rayhunter_version),
system_os: Some(metadata.system_os),
arch: Some(metadata.arch),
}
}
pub fn get_qmdl_filepath<P: AsRef<Path>>(&self, path: P) -> PathBuf {
let mut filepath = path.as_ref().join(&self.name);
filepath.set_extension("qmdl");
@@ -239,7 +236,6 @@ impl RecordingStore {
.open(entry.get_analysis_filepath(&self.path))
.await
.map_err(RecordingStoreError::ReadFileError)?;
self.update_entry_analysis_size(entry_index, 0).await?;
Ok(file)
}
@@ -265,16 +261,6 @@ impl RecordingStore {
self.write_manifest().await
}
// Sets the given entry's analysis file size
pub async fn update_entry_analysis_size(
&mut self,
entry_index: usize,
size_bytes: usize,
) -> Result<(), RecordingStoreError> {
self.manifest.entries[entry_index].analysis_size_bytes = size_bytes;
self.write_manifest().await
}
async fn write_manifest(&mut self) -> Result<(), RecordingStoreError> {
let tmp_path = self.path.join("manifest.toml.new");
let mut manifest_tmp_file = File::create(&tmp_path)