Skip to content

Commit

Permalink
feat: add progress bar on offline conversion
Browse files Browse the repository at this point in the history
- added indicatif
  • Loading branch information
SkuldNorniern committed Mar 25, 2024
1 parent abc3df4 commit 02e8736
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ratatui = { version = "0.26.1", features = ["all-widgets"] }
crossterm = "0.27"
dirs = "5.0.1"
log = { version = "0.4.21", features = ["std"]}
indicatif = "0.17.8"

[workspace]
members = [
Expand Down
14 changes: 9 additions & 5 deletions src/net/offline_fluereflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use fluereflow::FluereRecord;
use log::{debug, info, trace};
use pcap::Capture;
use tokio::task;
use indicatif::ProgressBar;

pub async fn fluereflow_fileparse(arg: Args) -> Result<(), FluereError> {
let _csv_file = arg.files.csv.unwrap();
Expand Down Expand Up @@ -48,6 +49,10 @@ pub async fn fluereflow_fileparse(arg: Args) -> Result<(), FluereError> {

let mut records: Vec<FluereRecord> = Vec::new();
let mut active_flow: HashMap<Key, FluereRecord> = HashMap::new();

info!("Converting file: {}", file_name);

let bar = ProgressBar::new_spinner();

while let Ok(packet) = cap.next_packet() {
let (mut key_value, mut reverse_key) = match parse_keys(packet.clone()) {
Expand Down Expand Up @@ -109,6 +114,7 @@ pub async fn fluereflow_fileparse(arg: Args) -> Result<(), FluereError> {
flags,
time,
};

update_flow(flow, is_reverse, update_key);

trace!(
Expand All @@ -135,13 +141,11 @@ pub async fn fluereflow_fileparse(arg: Args) -> Result<(), FluereError> {
expired_flows.push(*key);
}
}

// Remove expired flows from the active flows map
// active_flow.retain(|key, _| !expired_flows.contains(key));
for key in expired_flows {
active_flow.remove(&key);
}
active_flow.retain(|key, _| !expired_flows.contains(key));
}
bar.finish();
info!("Converted in {:?}", start.elapsed());
let ac_flow_cnt = active_flow.len();
let ended_flow_cnt = records.len();
Expand Down

0 comments on commit 02e8736

Please sign in to comment.