use chrono::Utc;
use clock_bound_c::ClockBoundClient;
use std::env;
use std::thread::sleep;
use std::time::Duration;
const ONE_SECOND_IN_NANOSECONDS: u64 = 1000000000;
fn main() {
let args: Vec<String> = env::args().collect();
let clock_bound_d_socket = &args[1];
let client =
match ClockBoundClient::new_with_path(std::path::PathBuf::from(clock_bound_d_socket)) {
Ok(client) => client,
Err(e) => {
println!("Could not create client: {}", e);
return;
}
};
let timestamp = Utc::now().timestamp_nanos() as u64;
let timestamp = timestamp + ONE_SECOND_IN_NANOSECONDS;
let response = match client.after(timestamp) {
Ok(response) => response,
Err(e) => {
println!("Couldn't complete after request: {}", e);
return;
}
};
if response.after == false {
println!(
"{} nanoseconds since the Unix Epoch is not after the current time's error bounds.",
timestamp
)
} else if response.after == true {
println!(
"{} nanoseconds since the Unix Epoch is after the current time's error bounds.",
timestamp
)
}
println!("Waiting 2 seconds...");
sleep(Duration::from_secs(2));
let response = match client.after(timestamp) {
Ok(response) => response,
Err(e) => {
println!("Couldn't complete after request: {}", e);
return;
}
};
if response.after == false {
println!(
"{} nanoseconds since the Unix Epoch is not after the current time's error bounds.",
timestamp
)
} else if response.after == true {
println!(
"{} nanoseconds since the Unix Epoch is after the current time's error bounds.",
timestamp
)
}
}