Skip to content

Commit 354aa73

Browse files
committed
(feat/webrtc-sniffer): add filter parameter
1 parent beb8ba7 commit 354aa73

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tools/webrtc-sniffer/src/bin/sniffer.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,30 @@ struct Cli {
1414
help = "name of the interface, use `auto` to determine automatically"
1515
)]
1616
interface: Option<String>,
17+
1718
#[arg(
1819
long,
1920
help = "if `interface` is set, the packets will be written to the `pcap` file, \
2021
otherwise the file will be a source of packets"
2122
)]
2223
path: PathBuf,
2324

25+
#[arg(long, help = "bpf filter, example: \"udp and not port 443\"")]
26+
filter: Option<String>,
27+
2428
/// Peer secret key
2529
#[arg(long, short = 's', env = "OPENMINA_P2P_SEC_KEY")]
26-
pub p2p_secret_key: Option<SecretKey>,
30+
p2p_secret_key: Option<SecretKey>,
2731

2832
// warning, this overrides `OPENMINA_P2P_SEC_KEY`
2933
/// Compatibility with OCaml Mina node
3034
#[arg(long)]
31-
pub libp2p_keypair: Option<String>,
35+
libp2p_keypair: Option<String>,
3236

3337
// warning, this overrides `OPENMINA_P2P_SEC_KEY`
3438
/// Compatibility with OCaml Mina node
3539
#[arg(env = "MINA_LIBP2P_PASS")]
36-
pub libp2p_password: Option<String>,
40+
libp2p_password: Option<String>,
3741
}
3842

3943
fn init_logger_std() -> Box<dyn log::Log> {
@@ -51,6 +55,7 @@ fn main() {
5155
let Cli {
5256
interface,
5357
path,
58+
filter,
5459
p2p_secret_key,
5560
libp2p_keypair,
5661
libp2p_password,
@@ -106,7 +111,7 @@ fn main() {
106111
let res = Ok(()).and_then(|()| {
107112
let mut capture = Capture::from_device(device)?.open()?;
108113
capture
109-
.filter("udp and not port 443", true)
114+
.filter(&filter.unwrap_or_default(), true)
110115
.expect("Failed to apply filter");
111116
let savefile = capture.savefile(&path)?;
112117

tools/webrtc-sniffer/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ pub fn run<T: Activated + ?Sized>(
1313

1414
for item in net::UdpIter::new(capture, file) {
1515
let (src, dst, data) = item?;
16-
log::info!(
17-
"{src} -> {dst}: {} {}",
18-
data.len(),
19-
hex::encode(&data[..data.len().min(12)])
20-
);
16+
log::info!("{src} -> {dst}: {} {}", data.len(), hex::encode(data));
2117
}
2218

2319
Ok(())

0 commit comments

Comments
 (0)