use std::time::Duration;
use netring::prelude::*;
#[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
let iface = std::env::args().nth(1).unwrap_or_else(|| "lo".into());
let (sink, mut rx) = ChannelSink::channel();
let consumer = tokio::spawn(async move {
while let Some(anomaly) = rx.recv().await {
println!("[consumer thread] {anomaly:?}");
}
});
let monitor = Monitor::builder()
.interface(&iface)
.protocol::<Tcp>()
.on_ctx::<FlowStarted<Tcp>>(|evt: &FlowStarted<Tcp>, ctx: &mut Ctx<'_>| {
ctx.emit("FlowStarted", Severity::Info)
.with_key(&evt.key)
.emit();
Ok(())
})
.sink(sink)
.build()?;
let run = tokio::spawn(monitor.run_for(Duration::from_secs(10)));
run.await??;
drop(consumer); Ok(())
}