Time since last change in place.
This commit is contained in:
parent
81bf3cf61d
commit
1742874c46
27
src/main.rs
27
src/main.rs
@ -26,7 +26,10 @@ fn main() {
|
||||
|
||||
let targets = vec![Ipv4Addr::new(127, 0, 0, 1),
|
||||
Ipv4Addr::new(172, 24, 10, 137),
|
||||
Ipv4Addr::new(1,1,1,1)];
|
||||
Ipv4Addr::new(1,1,1,1),
|
||||
Ipv4Addr::new(8,8,8,8),
|
||||
Ipv4Addr::new(216,121,247,231)
|
||||
];
|
||||
let mut state = State::default();
|
||||
|
||||
for current in &targets {
|
||||
@ -40,16 +43,11 @@ fn main() {
|
||||
let mut duration_since_last_loop = SystemTime::now().duration_since(display_loop_start).unwrap();
|
||||
loop {
|
||||
if let Ok(response) = ping_response_listener.recv_timeout(Duration::from_millis(100)) {
|
||||
// println!("[MM] Master got a ping response for {} with {}/{}", response.target, response.success, response.rtt);
|
||||
for (index, current_state) in state.targets.clone().iter().enumerate() {
|
||||
if current_state.target == response.target {
|
||||
// print!("start with {} and {} for {}", response.success, current_state.alive, current_state.target);
|
||||
let new_alive = current_state.alive != response.success;
|
||||
let last_alive_change = if response.success == current_state.alive {
|
||||
// println!("-- LAST ALIVE DID NOT CHANGE FOR {}", current_state.target);
|
||||
current_state.last_alive_change
|
||||
} else {
|
||||
// println!("++ LAST ALIVE IS RESET");
|
||||
SystemTime::now()
|
||||
};
|
||||
|
||||
@ -60,16 +58,27 @@ fn main() {
|
||||
last_alive_change,
|
||||
};
|
||||
state.targets[index] = new_state.clone();
|
||||
// println!("Found the target -> {}/{}/{}", new_state.target, new_state.alive, new_state.last_rtt);
|
||||
}
|
||||
}
|
||||
}
|
||||
duration_since_last_loop = SystemTime::now().duration_since(display_loop_start).expect("unable to figure out how long ago we displayed stuff");
|
||||
duration_since_last_loop = SystemTime::now()
|
||||
.duration_since(display_loop_start)
|
||||
.expect("unable to figure out how long ago we displayed stuff");
|
||||
if duration_since_last_loop.as_secs() > SECONDS_BETWEEN_DISPLAY as u64 {
|
||||
println!("DISPLAY LOOP");
|
||||
println!("------------");
|
||||
for current_result in state.targets.clone() {
|
||||
println!("{} / {} -> {} / Changed {}s ago", current_result.target, current_result.alive, current_result.last_rtt, SystemTime::now().duration_since(current_result.last_alive_change).unwrap().as_secs());
|
||||
let time_since_last_change = SystemTime::now().duration_since(current_result.last_alive_change).unwrap();
|
||||
let target_string = if current_result.target.clone().to_string().len() > 8 {
|
||||
format!("{}", current_result.target)
|
||||
} else {
|
||||
format!("{}\t", current_result.target)
|
||||
};
|
||||
println!("{}\t | {} \t | {}\t\t | Changed {}s ago",
|
||||
target_string,
|
||||
current_result.alive,
|
||||
current_result.last_rtt,time_since_last_change.as_secs()
|
||||
);
|
||||
}
|
||||
display_loop_start = SystemTime::now();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user