ftr 0.10.0

A fast, parallel ICMP traceroute with ASN lookup, reverse DNS, and ISP detection
Documentation
//! Trait for probe sockets
//!
//! This module defines the interface for probe sockets, enabling
//! immediate response processing and eliminating polling delays.

use crate::probe::{ProbeInfo, ProbeResponse};
use crate::traceroute::TracerouteError;
use std::future::Future;
use std::net::IpAddr;
use std::pin::Pin;

/// Probe mode supported by the socket
///
/// This enum is `#[non_exhaustive]`: new probe modes (e.g. for IPv6) may be
/// added in minor releases, so downstream matches must include a wildcard arm.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ProbeMode {
    /// ICMP echo requests using DGRAM sockets (Linux/macOS)
    DgramIcmp,
    /// ICMP echo requests using Windows IcmpSendEcho2 API
    WindowsIcmp,
    /// UDP probes with the socket error queue (Linux): `IP_RECVERR` for
    /// IPv4 targets, `IPV6_RECVERR` for IPv6 targets
    UdpWithRecverr,
    /// Raw ICMP/ICMPv6 sockets (fallback; requires root/CAP_NET_RAW)
    RawIcmp,
    /// ICMPv6 echo requests using DGRAM sockets, unprivileged: macOS
    /// (Darwin DGRAM ICMPv6) and Linux (ping sockets, gated by
    /// `net.ipv4.ping_group_range`)
    // Appended last: inserting variants mid-enum shifts existing
    // discriminants, which cargo-semver-checks flags as breaking.
    DgramIcmpv6,
}

/// Trait for probe sockets
///
/// This trait defines the interface for all probe socket implementations.
/// It enables immediate response processing without polling delays.
pub trait ProbeSocket: Send + Sync {
    /// Get the probe mode this socket supports
    fn mode(&self) -> ProbeMode;

    /// Send a probe and get a future for its response
    ///
    /// This method sends a probe and returns a future that will resolve
    /// to the response when it arrives. This allows immediate wake-up
    /// when the response is received.
    fn send_probe_and_recv(
        &self,
        dest: IpAddr,
        probe: ProbeInfo,
    ) -> Pin<Box<dyn Future<Output = Result<ProbeResponse, TracerouteError>> + Send + '_>>;

    /// Check if the destination has been reached
    ///
    /// Returns true if we've received a response indicating we've reached
    /// the final destination (e.g., ICMP Echo Reply).
    fn destination_reached(&self) -> bool;

    /// Get the number of pending probes
    ///
    /// Returns the number of probes that have been sent but not yet
    /// received a response or timed out.
    fn pending_count(&self) -> usize;
}