Skip to content

Commit

Permalink
[ADD] Added flag to chagne windows sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern committed Jan 27, 2023
1 parent 07bb2ff commit e81daaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ fn cli() -> Command {
.short('I')
.long("interval"),
)
.arg(
Arg::new("sleep_windows")
//.about("Select network interface to use")
.default_value("2")
.short('s')
.long("sleep"),
)
.arg(
Arg::new("verbose")
//.about("List of network interfaces")
Expand Down Expand Up @@ -134,13 +141,22 @@ async fn main() {
let duration: u64 = duration.parse().unwrap();
let interval = args.get_one::<String>("interval").expect("default");
let interval: u64 = interval.parse().unwrap();
let sleep_windows = args.get_one::<String>("sleep_windows").expect("default");
let sleep_windows: u64 = sleep_windows.parse().unwrap();
let verbose = args.get_one::<String>("verbose").expect("default");
let verbose: u8 = verbose.parse().unwrap();

if verbose >= 1 {
println!("Interface {} selected", interface);
}//net::packet_capture(interface);
} //net::packet_capture(interface);
net::online_fluereflow::packet_capture(
csv, interface, duration, interval, timeout, verbose,
csv,
interface,
duration,
interval,
timeout,
sleep_windows,
verbose,
)
.await;
//net::netflow(_interface);
Expand Down
8 changes: 6 additions & 2 deletions src/net/online_fluereflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub async fn packet_capture(
duration: u64,
interval: u64,
flow_timeout: u32,
sleep_windows: u64,
verbose: u8,
) {
let interface = get_interface(interface_name);
Expand Down Expand Up @@ -292,14 +293,14 @@ pub async fn packet_capture(
if verbose >= 3 {
println!("Slow down the loop for windows");
}
sleep(Duration::from_millis(2)).await;
sleep(Duration::from_millis(sleep_windows)).await;
}

// Export flows if the interval has been reached
if last_export.elapsed() >= Duration::from_millis(interval) {
for (key, flow) in active_flow.clone().iter() {
//let flow = active_flow.get(&key).unwrap();
if flow.get_last() < (packet.header.ts.tv_sec as u32 - flow_timeout/1000) {
if flow.get_last() < (packet.header.ts.tv_sec as u32 - flow_timeout / 1000) {
if verbose >= 2 {
println!("flow expired");
}
Expand Down Expand Up @@ -341,6 +342,9 @@ pub async fn packet_capture(
if verbose >= 1 {
println!("Captured in {:?}", start.elapsed());
}
for (_key, flow) in active_flow.clone().iter() {
records.push(*flow);
}
let tasks = task::spawn(async {
fluere_exporter(records, file).await;
});
Expand Down

0 comments on commit e81daaf

Please sign in to comment.