use async_trait::async_trait;
use hickory_resolver::TokioResolver;
use std::sync::Arc;
use tokio::sync::mpsc::{Receiver, Sender};
use crate::{Config, Finding, Target};
pub struct ScanInput {
pub seed: String,
pub target_rx: tokio::sync::Mutex<Receiver<Target>>,
pub live_tx: Sender<Finding>,
pub target_tx: Sender<Target>,
pub resolver: Arc<TokioResolver>,
}
impl ScanInput {
pub async fn emit(&self, f: Finding) {
if let Err(e) = self.live_tx.send(f).await {
tracing::error!(err = %e, "failed to emit finding: live channel closed");
}
}
pub async fn emit_target(&self, t: Target) {
if let Err(e) = self.target_tx.send(t).await {
tracing::error!(err = %e, "failed to emit target: target channel closed");
}
}
}
#[async_trait]
pub trait Scanner: Send + Sync {
fn name(&self) -> &'static str;
fn tags(&self) -> &[&'static str];
fn accepts(&self, target: &Target) -> bool;
async fn run(&self, input: ScanInput, config: &Config) -> anyhow::Result<()>;
}