Tracer

Struct Tracer 

Source
pub struct Tracer { /* private fields */ }
Expand description

A traceroute implementation.

See the crate documentation for more information.

Note that this is type cheaply cloneable.

Implementations§

Source§

impl Tracer

Source

pub fn run(&self) -> Result<(), Error>

Run the Tracer.

This method will block until either the trace completes all rounds (if crate::Builder::max_rounds has been called to set to a non-zero value) or until the trace fails.

At the completion of the trace, the state of the tracer can be retrieved using the Tracer::snapshot method.

If you want to run the tracer indefinitely (by not setting crate::Builder::max_rounds), you can either clone and run the tracer on a separate thread by using the Tracer::spawn method or by use the Tracer::run_with method in the current thread to gather pee round state manually.

§Example

The following will run the tracer for a fixed number (3) of rounds and then retrieve the final state snapshot:

use trippy_core::Builder;

let addr = IpAddr::from_str("1.1.1.1")?;
let tracer = Builder::new(addr).max_rounds(Some(3)).build()?;
tracer.run()?;
let _state = tracer.snapshot();
§See Also
  • Tracer::run_with - Run the tracer with a custom round handler.
  • Tracer::spawn - Spawn the tracer on a new thread without a custom round handler.
Source

pub fn run_with<F: Fn(&Round<'_>)>(&self, func: F) -> Result<(), Error>

Run the Tracer with a custom round handler.

This method will block until either the trace completes all rounds (if crate::Builder::max_rounds has been called to set to a non-zero value) or until the trace fails.

At the completion of the trace, the state of the tracer can be retrieved using the Tracer::snapshot method.

This method will additionally call the provided function for each round that is completed. This can be useful if you want to gather round state manually if the tracer is run indefinitely (by not setting crate::Builder::max_rounds)

§Example

The following will run the tracer indefinitely and print the data from each round of tracing:

use trippy_core::Builder;

let addr = IpAddr::from_str("1.1.1.1")?;
let tracer = Builder::new(addr).build()?;
tracer.run_with(|round| println!("{:?}", round))?;
§See Also
  • Tracer::run - Run the tracer without a custom round handler.
Source

pub fn spawn(self) -> Result<(Self, JoinHandle<Result<(), Error>>), Error>

Spawn the tracer on a new thread.

This method will spawn a new thread to run the tracer and immediately return the Tracer and a handle to the thread, so it may be joined with JoinHandle::join.

If you want to run the tracer indefinitely (by not setting crate::Builder::max_rounds) you can use this method to spawn the tracer on a new thread and return the Tracer such that a Tracer::snapshot of the state can be taken at any time.

§Example

The following will spawn a tracer on a new thread and take a snapshot of the state every 5 seconds:

use trippy_core::Builder;

let addr = IpAddr::from_str("1.1.1.1")?;
let (tracer, _) = Builder::new(addr).build()?.spawn()?;
loop {
    thread::sleep(Duration::from_secs(5));
    // get the latest state.
    let _state = tracer.snapshot();
}
§See Also
Source

pub fn spawn_with<F: Fn(&Round<'_>) + Send + 'static>( self, func: F, ) -> Result<(Self, JoinHandle<Result<(), Error>>), Error>

Spawn the tracer with a custom round handler on a new thread.

This method will spawn a new thread to run the tracer with a custom round handler and immediately return the Tracer and a handle to the thread, so it may be joined with JoinHandle::join.

§Example

The following will spawn a tracer on a new thread with a custom round handler to print the data from each round of tracing and also take a snapshot of the state every 5 seconds until the tracer completes all rounds:

use trippy_core::Builder;

let addr = IpAddr::from_str("1.1.1.1")?;
let (tracer, handle) = Builder::new(addr)
    .max_rounds(Some(3))
    .build()?
    .spawn_with(|round| println!("{:?}", round))?;
for i in 0..3 {
    thread::sleep(Duration::from_secs(5));
    // get the latest state.
    let _state = tracer.snapshot();
}
handle.join().unwrap()?;
§See Also
  • Tracer::spawn - Spawn the tracer on a new thread without a custom round handler.
Source

pub fn snapshot(&self) -> State

Take a snapshot of the tracer state.

Source

pub fn clear(&self)

Clear the tracer state.

Source

pub fn max_flows(&self) -> usize

The maximum number of flows to record.

Source

pub fn max_samples(&self) -> usize

The maximum number of samples to record.

Source

pub fn privilege_mode(&self) -> PrivilegeMode

The privilege mode of the tracer.

Source

pub fn protocol(&self) -> Protocol

The protocol of the tracer.

Source

pub fn interface(&self) -> Option<&str>

The interface to use for the tracer.

Source

pub fn source_addr(&self) -> Option<IpAddr>

The source address of the tracer.

Source

pub fn target_addr(&self) -> IpAddr

The target address of the tracer.

Source

pub fn packet_size(&self) -> PacketSize

The packet size of the tracer.

Source

pub fn payload_pattern(&self) -> PayloadPattern

The payload pattern of the tracer.

Source

pub fn initial_sequence(&self) -> Sequence

The initial sequence number of the tracer.

Source

pub fn tos(&self) -> TypeOfService

The type of service of the tracer.

Source

pub fn icmp_extension_parse_mode(&self) -> IcmpExtensionParseMode

The ICMP extension parse mode of the tracer.

Source

pub fn read_timeout(&self) -> Duration

The read timeout of the tracer.

Source

pub fn tcp_connect_timeout(&self) -> Duration

The TCP connect timeout of the tracer.

Source

pub fn trace_identifier(&self) -> TraceId

The trace identifier of the tracer.

Source

pub fn max_rounds(&self) -> Option<MaxRounds>

The maximum number of rounds of the tracer.

Source

pub fn first_ttl(&self) -> TimeToLive

The first time-to-live value of the tracer.

Source

pub fn max_ttl(&self) -> TimeToLive

The maximum time-to-live value of the tracer.

Source

pub fn grace_duration(&self) -> Duration

The grace duration of the tracer.

Source

pub fn max_inflight(&self) -> MaxInflight

The maximum number of in-flight probes of the tracer.

Source

pub fn multipath_strategy(&self) -> MultipathStrategy

The multipath strategy of the tracer.

Source

pub fn port_direction(&self) -> PortDirection

The port direction of the tracer.

Source

pub fn min_round_duration(&self) -> Duration

The minimum round duration of the tracer.

Source

pub fn max_round_duration(&self) -> Duration

The maximum round duration of the tracer.

Trait Implementations§

Source§

impl Clone for Tracer

Source§

fn clone(&self) -> Tracer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tracer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Tracer

§

impl !RefUnwindSafe for Tracer

§

impl Send for Tracer

§

impl Sync for Tracer

§

impl Unpin for Tracer

§

impl !UnwindSafe for Tracer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more