use dashmap::DashMap;
use std::net::IpAddr;
use std::sync::Arc;
use tokio::sync::mpsc;
use crate::core::handle::ScanHandle;
use crate::core::models::host::Host;
#[derive(Debug, Clone)]
pub enum ScanEvent {
HostUpdated(IpAddr),
}
pub struct ScanSession {
pub store: Arc<DashMap<IpAddr, Host>>,
pub events: mpsc::UnboundedReceiver<ScanEvent>,
pub handle: ScanHandle,
}
impl ScanSession {
pub fn new() -> (Self, ScanHandle, mpsc::UnboundedSender<ScanEvent>) {
let store = Arc::new(DashMap::new());
let handle = ScanHandle::new();
let (tx, rx) = mpsc::unbounded_channel();
let session = Self {
store,
events: rx,
handle: handle.clone(),
};
(session, handle, tx)
}
}