Skip to content

Commit fce321e

Browse files
committed
(feat/webrtc-sniffer): capture the traffic using pcap, parse network headers
1 parent 463cc59 commit fce321e

File tree

6 files changed

+337
-12
lines changed

6 files changed

+337
-12
lines changed

Cargo.lock

Lines changed: 120 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ members = [
3131
"tools/fuzzing",
3232
"tools/archive-breadcrumb-compare",
3333
"tools/heartbeats-processor",
34+
"tools/webrtc-sniffer",
35+
3436
"producer-dashboard",
3537

3638
"fuzzer",
@@ -54,8 +56,8 @@ mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "dec49a
5456
# UNCOMMENTED_IN_CI mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "dec49a9", features = [ "32x9" ] }
5557
o1-utils = { git = "https://github.com/openmina/proof-systems", rev = "dec49a9" }
5658
kimchi = { git = "https://github.com/openmina/proof-systems", rev = "dec49a9" }
57-
mina-poseidon = {git = "https://github.com/openmina/proof-systems", rev = "dec49a9" }
58-
poly-commitment = {git = "https://github.com/openmina/proof-systems", rev = "dec49a9" }
59+
mina-poseidon = { git = "https://github.com/openmina/proof-systems", rev = "dec49a9" }
60+
poly-commitment = { git = "https://github.com/openmina/proof-systems", rev = "dec49a9" }
5961

6062
libp2p = { git = "https://github.com/openmina/rust-libp2p", rev = "5c44c7d9", default-features = false }
6163
vrf = { path = "vrf" }
@@ -90,9 +92,9 @@ incremental = false
9092
codegen-units = 1
9193

9294
[patch.crates-io]
93-
ark-ff = { git = "https://github.com/openmina/algebra", rev = "aea157a" } # branch: fix-openmina-webnode
94-
ark-ec = { git = "https://github.com/openmina/algebra", rev = "aea157a" } # branch: fix-openmina-webnode
95-
ark-poly = { git = "https://github.com/openmina/algebra", rev = "aea157a" } # branch: fix-openmina-webnode
95+
ark-ff = { git = "https://github.com/openmina/algebra", rev = "aea157a" } # branch: fix-openmina-webnode
96+
ark-ec = { git = "https://github.com/openmina/algebra", rev = "aea157a" } # branch: fix-openmina-webnode
97+
ark-poly = { git = "https://github.com/openmina/algebra", rev = "aea157a" } # branch: fix-openmina-webnode
9698
ark-serialize = { git = "https://github.com/openmina/algebra", rev = "aea157a" } # branch: fix-openmina-webnode
9799

98100
num-bigint = { git = "https://github.com/openmina/num-bigint", rev = "8bb5ee4" } # branch: on-stack

tools/webrtc-sniffer/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "webrtc-sniffer"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
clap = { version = "4.5", features = ["derive"] }
8+
env_logger = { version = "0.11.6" }
9+
log = { version = "0.4.25" }
10+
pcap = { version = "2.2" }
11+
ctrlc = { version = "3.4" }
12+
sudo = { version = "0.6.0" }
13+
hex = { version = "0.4.3" }
14+
etherparse = { version = "0.17.0" }
15+
thiserror = { version = "2.0" }
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use std::path::PathBuf;
2+
3+
use clap::Parser;
4+
use pcap::{Capture, ConnectionStatus, Device, IfFlags};
5+
6+
// cargo run --release --bin sniffer -- --interface auto --port 443 --path target/test.pcap
7+
8+
#[derive(Parser)]
9+
struct Cli {
10+
#[arg(
11+
long,
12+
help = "name of the interface, use `auto` to determine automatically"
13+
)]
14+
interface: Option<String>,
15+
#[arg(long, help = "filter by the port")]
16+
port: u16,
17+
#[arg(
18+
long,
19+
help = "if `interface` is set, the packets will be written to the `pcap` file, \
20+
otherwise the file will be a source of packets"
21+
)]
22+
path: PathBuf,
23+
}
24+
25+
fn init_logger_std() -> Box<dyn log::Log> {
26+
use env_logger::{Builder, Env};
27+
28+
let env = Env::new().filter_or("RUST_LOG", "debug");
29+
let logger = Builder::default().parse_env(env).build();
30+
Box::new(logger) as Box<dyn log::Log>
31+
}
32+
33+
fn main() {
34+
log::set_boxed_logger(init_logger_std()).unwrap_or_default();
35+
log::set_max_level(log::LevelFilter::max());
36+
37+
let Cli {
38+
interface,
39+
port,
40+
path,
41+
} = Cli::parse();
42+
if let Some(name) = interface {
43+
sudo::escalate_if_needed().unwrap();
44+
45+
log::info!("try to choose device");
46+
let mut selected = None;
47+
match Device::list() {
48+
Ok(list) => {
49+
for device in list {
50+
if name != "auto" {
51+
if device.name.eq(&name) {
52+
selected = Some(device);
53+
break;
54+
}
55+
} else {
56+
log::debug!("candidate: {device:?}");
57+
if !device.addresses.is_empty()
58+
&& device.flags.contains(IfFlags::UP | IfFlags::RUNNING)
59+
&& matches!(device.flags.connection_status, ConnectionStatus::Connected)
60+
{
61+
selected = Some(device);
62+
}
63+
}
64+
}
65+
}
66+
Err(err) => log::error!("{err}"),
67+
}
68+
69+
if let Some(device) = selected {
70+
log::info!("will use: {device:?}");
71+
let res = Ok(()).and_then(|()| {
72+
let mut capture = Capture::from_device(device)?.open()?;
73+
let filter = format!("udp port {port}");
74+
capture
75+
.filter(&filter, true)
76+
.expect("Failed to apply filter");
77+
let savefile = capture.savefile(&path)?;
78+
79+
webrtc_sniffer::run(capture, Some(savefile))
80+
});
81+
if let Err(err) = res {
82+
log::error!("{err}");
83+
}
84+
} else {
85+
log::error!("cannot find a device: {name}");
86+
}
87+
} else {
88+
log::info!("use file");
89+
let res = Ok(()).and_then(|()| {
90+
let capture = Capture::from_file(&path)?;
91+
webrtc_sniffer::run(capture, None)
92+
});
93+
if let Err(err) = res {
94+
log::error!("{err}");
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)