zond_engine/core/
handle.rs1use std::net::IpAddr;
2use std::sync::Arc;
3use std::sync::atomic::{AtomicBool, Ordering};
4use tokio::sync::mpsc;
5
6#[derive(Debug, Clone)]
7pub enum ScanEvent {
8 NewIp(IpAddr),
9 NewHostname(String),
10 PortOpen { ip: IpAddr, port: u16 },
11}
12
13#[derive(Debug, Clone)]
14pub struct ScanHandle {
15 abort: Arc<AtomicBool>,
16 events: mpsc::UnboundedSender<ScanEvent>,
17}
18
19impl ScanHandle {
20 pub fn new() -> (Self, mpsc::UnboundedReceiver<ScanEvent>) {
21 let (tx, rx) = mpsc::unbounded_channel();
22 let abort = Arc::new(AtomicBool::new(false));
23 let self_handle = Self { abort, events: tx };
24 (self_handle, rx)
25 }
26
27 pub fn emit(&self, event: ScanEvent) {
28 let _ = self.events.send(event);
29 }
30
31 pub fn abort(&self) {
32 self.abort.store(true, Ordering::SeqCst);
33 }
34
35 pub fn should_stop(&self) -> bool {
36 self.abort.load(Ordering::SeqCst)
37 }
38}