Skip to main content

zond_engine/core/
session.rs

1use dashmap::DashMap;
2use std::net::IpAddr;
3use std::sync::Arc;
4use tokio::sync::mpsc;
5
6use crate::core::handle::ScanHandle;
7use crate::core::models::host::Host;
8
9/// Lightweight notifications for the status of an ongoing scan.
10#[derive(Debug, Clone)]
11pub enum ScanEvent {
12    /// Indicates that new data is available for a host.
13    /// The consumer should read from `ScanSession::store` to get the latest state.
14    HostUpdated(IpAddr),
15}
16
17/// A handle to an active network scan.
18pub struct ScanSession {
19    /// Thread-safe, lock-free store of all hosts discovered so far.
20    pub store: Arc<DashMap<IpAddr, Host>>,
21
22    /// Receiver for lightweight update events.
23    /// UI/Web interfaces can loop over this to react to changes in real-time.
24    pub events: mpsc::UnboundedReceiver<ScanEvent>,
25
26    /// Handle to control the active scan (e.g., to abort it).
27    pub handle: ScanHandle,
28}
29
30impl ScanSession {
31    pub fn new() -> (Self, ScanHandle, mpsc::UnboundedSender<ScanEvent>) {
32        let store = Arc::new(DashMap::new());
33        let handle = ScanHandle::new();
34        let (tx, rx) = mpsc::unbounded_channel();
35
36        let session = Self {
37            store,
38            events: rx,
39            handle: handle.clone(),
40        };
41
42        (session, handle, tx)
43    }
44}