run cargo fmt

This commit is contained in:
Will Greenberg
2025-07-15 14:33:34 -07:00
committed by Cooper Quintin
parent c783831e78
commit 0585e0f996
5 changed files with 32 additions and 35 deletions

View File

@@ -1 +1,2 @@
9fe75ac961c57e508bf7488ce51d596750fa8d37
76ffdf6bada515c9a5f63a600e6f1502288c147a

View File

@@ -1,9 +1,13 @@
use clap::Parser;
use futures::TryStreamExt;
use log::{error, info, warn, debug};
use log::{debug, error, info, warn};
use pcap_file_tokio::pcapng::{Block, PcapNgReader};
use rayhunter::{
analysis::analyzer::{AnalysisRow, AnalyzerConfig, EventType, Harness}, diag::DataType, gsmtap_parser, pcap::GsmtapPcapWriter, qmdl::QmdlReader
analysis::analyzer::{AnalysisRow, AnalyzerConfig, EventType, Harness},
diag::DataType,
gsmtap_parser,
pcap::GsmtapPcapWriter,
qmdl::QmdlReader,
};
use std::{collections::HashMap, future, path::PathBuf, pin::pin};
use tokio::fs::File;
@@ -50,13 +54,12 @@ impl Report {
}
for maybe_event in row.events {
let Some(event) = maybe_event else { continue };
let Some(timestamp) = row.packet_timestamp else { continue };
let Some(timestamp) = row.packet_timestamp else {
continue;
};
match event.event_type {
EventType::Informational => {
info!(
"{}: INFO - {} {}",
self.file_path, timestamp, event.message,
);
info!("{}: INFO - {} {}", self.file_path, timestamp, event.message,);
}
EventType::QualitativeWarning { severity } => {
warn!(
@@ -78,19 +81,14 @@ impl Report {
}
info!(
"{}: {} messages analyzed, {} warnings, {} messages skipped",
self.file_path,
self.total_messages,
self.warnings,
self.skipped
self.file_path, self.total_messages, self.warnings, self.skipped
);
}
}
async fn analyze_pcap(pcap_path: &str, show_skipped: bool) {
let mut harness = Harness::new_with_config(&AnalyzerConfig::default());
let pcap_file = &mut File::open(&pcap_path)
.await
.expect("failed to open file");
let pcap_file = &mut File::open(&pcap_path).await.expect("failed to open file");
let mut pcap_reader = PcapNgReader::new(pcap_file)
.await
.expect("failed to read PCAP file");
@@ -101,7 +99,7 @@ async fn analyze_pcap(pcap_path: &str, show_skipped: bool) {
other => {
debug!("{pcap_path}: skipping pcap packet {other:?}");
continue;
},
}
};
report.process_row(row);
}
@@ -185,7 +183,10 @@ async fn main() {
let harness = Harness::new_with_config(&AnalyzerConfig::default());
info!("Analyzers:");
for analyzer in harness.get_metadata().analyzers {
info!(" - {} (v{}): {}", analyzer.name, analyzer.description, analyzer.version);
info!(
" - {} (v{}): {}",
analyzer.name, analyzer.description, analyzer.version
);
}
for maybe_entry in WalkDir::new(&args.path) {

View File

@@ -34,13 +34,9 @@ pub struct AnalysisWriter {
// lets us simply append new rows to the end without parsing the entire JSON
// object beforehand.
impl AnalysisWriter {
pub async fn new(
file: File,
analyzer_config: &AnalyzerConfig,
) -> Result<Self, std::io::Error> {
pub async fn new(file: File, analyzer_config: &AnalyzerConfig) -> Result<Self, std::io::Error> {
let harness = Harness::new_with_config(analyzer_config);
let mut result = Self {
writer: BufWriter::new(file),
bytes_written: 0,
@@ -154,10 +150,9 @@ async fn perform_analysis(
(analysis_file, qmdl_file, entry_index)
};
let mut analysis_writer =
AnalysisWriter::new(analysis_file, analyzer_config)
.await
.map_err(|e| format!("{e:?}"))?;
let mut analysis_writer = AnalysisWriter::new(analysis_file, analyzer_config)
.await
.map_err(|e| format!("{e:?}"))?;
let file_size = qmdl_file
.metadata()
.await
@@ -211,12 +206,8 @@ pub fn run_analysis_thread(
let count = queued_len(analysis_status_lock.clone()).await;
for _ in 0..count {
let name = dequeue_to_running(analysis_status_lock.clone()).await;
if let Err(err) = perform_analysis(
&name,
qmdl_store_lock.clone(),
&analyzer_config,
)
.await
if let Err(err) =
perform_analysis(&name, qmdl_store_lock.clone(), &analyzer_config).await
{
error!("failed to analyze {name}: {err}");
}

View File

@@ -184,7 +184,7 @@ impl Harness {
Err(err) => {
row.skipped_message_reason = Some(format!("failed to read GsmtapHeader: {err:?}"));
return row;
},
}
};
let packet_offset = gsmtap_offset + 16;
let packet_data = &packet.data[packet_offset..];
@@ -195,9 +195,10 @@ impl Harness {
row.events = match InformationElement::try_from(&gsmtap_message) {
Ok(element) => self.analyze_information_element(&element),
Err(err) => {
row.skipped_message_reason = Some(format!("failed to convert gsmtap message to IE: {err:?}"));
row.skipped_message_reason =
Some(format!("failed to convert gsmtap message to IE: {err:?}"));
return row;
},
}
};
return row;
}

View File

@@ -195,7 +195,10 @@ impl GsmtapType {
};
match maybe_result {
Some(result) => Ok(result),
None => Err(GsmtapTypeError::InvalidTypeSubtypeCombo(gsmtap_type, gsmtap_subtype)),
None => Err(GsmtapTypeError::InvalidTypeSubtypeCombo(
gsmtap_type,
gsmtap_subtype,
)),
}
}