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
impl Tracer
Sourcepub fn run(&self) -> Result<(), Error>
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.
Sourcepub fn run_with<F: Fn(&Round<'_>)>(&self, func: F) -> Result<(), Error>
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.
Sourcepub fn spawn(self) -> Result<(Self, JoinHandle<Result<(), Error>>), Error>
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
Tracer::run- Run the tracer on the current thread.
Sourcepub fn spawn_with<F: Fn(&Round<'_>) + Send + 'static>(
self,
func: F,
) -> Result<(Self, JoinHandle<Result<(), Error>>), Error>
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.
Sourcepub fn max_samples(&self) -> usize
pub fn max_samples(&self) -> usize
The maximum number of samples to record.
Sourcepub fn privilege_mode(&self) -> PrivilegeMode
pub fn privilege_mode(&self) -> PrivilegeMode
The privilege mode of the tracer.
Sourcepub fn source_addr(&self) -> Option<IpAddr>
pub fn source_addr(&self) -> Option<IpAddr>
The source address of the tracer.
Sourcepub fn target_addr(&self) -> IpAddr
pub fn target_addr(&self) -> IpAddr
The target address of the tracer.
Sourcepub fn packet_size(&self) -> PacketSize
pub fn packet_size(&self) -> PacketSize
The packet size of the tracer.
Sourcepub fn payload_pattern(&self) -> PayloadPattern
pub fn payload_pattern(&self) -> PayloadPattern
The payload pattern of the tracer.
Sourcepub fn initial_sequence(&self) -> Sequence
pub fn initial_sequence(&self) -> Sequence
The initial sequence number of the tracer.
Sourcepub fn tos(&self) -> TypeOfService
pub fn tos(&self) -> TypeOfService
The type of service of the tracer.
Sourcepub fn icmp_extension_parse_mode(&self) -> IcmpExtensionParseMode
pub fn icmp_extension_parse_mode(&self) -> IcmpExtensionParseMode
The ICMP extension parse mode of the tracer.
Sourcepub fn read_timeout(&self) -> Duration
pub fn read_timeout(&self) -> Duration
The read timeout of the tracer.
Sourcepub fn tcp_connect_timeout(&self) -> Duration
pub fn tcp_connect_timeout(&self) -> Duration
The TCP connect timeout of the tracer.
Sourcepub fn trace_identifier(&self) -> TraceId
pub fn trace_identifier(&self) -> TraceId
The trace identifier of the tracer.
Sourcepub fn max_rounds(&self) -> Option<MaxRounds>
pub fn max_rounds(&self) -> Option<MaxRounds>
The maximum number of rounds of the tracer.
Sourcepub fn first_ttl(&self) -> TimeToLive
pub fn first_ttl(&self) -> TimeToLive
The first time-to-live value of the tracer.
Sourcepub fn max_ttl(&self) -> TimeToLive
pub fn max_ttl(&self) -> TimeToLive
The maximum time-to-live value of the tracer.
Sourcepub fn grace_duration(&self) -> Duration
pub fn grace_duration(&self) -> Duration
The grace duration of the tracer.
Sourcepub fn max_inflight(&self) -> MaxInflight
pub fn max_inflight(&self) -> MaxInflight
The maximum number of in-flight probes of the tracer.
Sourcepub fn multipath_strategy(&self) -> MultipathStrategy
pub fn multipath_strategy(&self) -> MultipathStrategy
The multipath strategy of the tracer.
Sourcepub fn port_direction(&self) -> PortDirection
pub fn port_direction(&self) -> PortDirection
The port direction of the tracer.
Sourcepub fn min_round_duration(&self) -> Duration
pub fn min_round_duration(&self) -> Duration
The minimum round duration of the tracer.
Sourcepub fn max_round_duration(&self) -> Duration
pub fn max_round_duration(&self) -> Duration
The maximum round duration of the tracer.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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