roughtime 0.1.0

A no_std-capable Roughtime secure time-sync client with pluggable crypto backends
Documentation
//! Queries the well-known public Roughtime servers and prints the consensus verified time.
//!
//! Run with: `cargo run --example query_tokio`

use std::net::ToSocketAddrs;

use roughtime::ROUGHTIME_SERVERS;
use roughtime::client::{RoughtimeClientConfig, TokioClient};

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let mut resolved = Vec::new();
    for server in ROUGHTIME_SERVERS {
        let addr = format!("{}:{}", server.host, server.port);
        if let Ok(mut addrs) = addr.to_socket_addrs()
            && let Some(sock_addr) = addrs.next()
        {
            resolved.push((*server, sock_addr.ip()));
        }
    }

    let client = TokioClient::new(RoughtimeClientConfig::default());
    match client.query(&resolved).await {
        Ok(result) => {
            println!(
                "Verified Unix time: {}s (radius {}us)",
                result.time.as_unix_seconds(),
                result.time.radius_micros
            );
            if let Some(spread) = result.spread_warning {
                println!("Warning: server spread was {spread:?}");
            }
        }
        Err(err) => eprintln!("Query failed: {err}"),
    }
}