pub mod icmp;
pub mod tcp;
pub mod udp;
use crate::error::NetPulseError;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct ProbeResult {
pub target: String,
pub rtt_us: Option<u64>,
pub timestamp: DateTime<Utc>,
pub seq: u64,
pub responder_ip: Option<String>,
}
impl ProbeResult {
pub fn loss(target: &str, seq: u64) -> Self {
Self {
target: target.to_string(),
rtt_us: None,
timestamp: Utc::now(),
seq,
responder_ip: None,
}
}
pub fn success(target: &str, seq: u64, rtt_us: u64, responder_ip: Option<String>) -> Self {
Self {
target: target.to_string(),
rtt_us: Some(rtt_us),
timestamp: Utc::now(),
seq,
responder_ip,
}
}
pub fn is_loss(&self) -> bool {
self.rtt_us.is_none()
}
}
#[async_trait]
pub trait Prober: Send + Sync {
async fn probe(
&self,
target: &str,
seq: u64,
ttl: Option<u32>,
) -> Result<ProbeResult, NetPulseError>;
fn name(&self) -> &'static str;
}