Skip to content

Commit

Permalink
Optimize Performance: Run HTTP and TCP Analyses in Parallel (#66)
Browse files Browse the repository at this point in the history
* parallel in the package analysis
  • Loading branch information
biandratti authored Feb 16, 2025
1 parent d3df99c commit b80a35a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 9 deletions.
59 changes: 58 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ log = "0.4.25"
ttl_cache = "0.5.1"
lazy_static = "1.5.0"
httparse = "1.10.0"
crossbeam = "0.8.4"

[dev-dependencies]
clap = { version = "4.5.29", features = ["derive"] }
Expand Down
46 changes: 40 additions & 6 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,26 @@ pub fn process_ipv4(
packet.get_next_level_protocol()
);
}
let http_response = http_process::process_http_ipv4(&packet, http_cache);
let tcp_response = tcp_process::process_tcp_ipv4(tcp_cache, &packet);
handle_http_tcp_responses(http_response, tcp_response)

let packet_data = packet.packet().to_vec();

crossbeam::scope(|s| {
let http_handle = s.spawn(|_| {
let packet = Ipv4Packet::new(&packet_data).unwrap();
http_process::process_http_ipv4(&packet, http_cache)
});

let tcp_handle = s.spawn(|_| {
let packet = Ipv4Packet::new(&packet_data).unwrap();
tcp_process::process_tcp_ipv4(tcp_cache, &packet)
});

let http_response = http_handle.join().unwrap();
let tcp_response = tcp_handle.join().unwrap();

handle_http_tcp_responses(http_response, tcp_response)
})
.unwrap()
}

pub fn process_ipv6(
Expand All @@ -117,9 +134,26 @@ pub fn process_ipv6(
packet.get_next_header()
);
}
let http_response = http_process::process_http_ipv6(&packet, http_cache);
let tcp_response = tcp_process::process_tcp_ipv6(tcp_cache, &packet);
handle_http_tcp_responses(http_response, tcp_response)

let packet_data = packet.packet().to_vec();

crossbeam::scope(|s| {
let http_handle = s.spawn(|_| {
let packet = Ipv6Packet::new(&packet_data).unwrap();
http_process::process_http_ipv6(&packet, http_cache)
});

let tcp_handle = s.spawn(|_| {
let packet = Ipv6Packet::new(&packet_data).unwrap();
tcp_process::process_tcp_ipv6(tcp_cache, &packet)
});

let http_response = http_handle.join().unwrap();
let tcp_response = tcp_handle.join().unwrap();

handle_http_tcp_responses(http_response, tcp_response)
})
.unwrap()
}

fn handle_http_tcp_responses(
Expand Down
4 changes: 2 additions & 2 deletions src/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ pub fn check_ts_tcp(
from_client: bool,
ts_val: u32,
) -> Option<ObservableUptime> {
let syn_data: Option<&SynData> = if !from_client {
let syn_data: Option<SynData> = if !from_client {
let client_connection = Connection {
src_ip: connection.dst_ip,
src_port: connection.dst_port,
dst_ip: connection.src_ip,
dst_port: connection.src_port,
};
cache.get(&client_connection)
cache.remove(&client_connection)
} else {
cache.insert(
connection.clone(),
Expand Down

0 comments on commit b80a35a

Please sign in to comment.