use anyhow::Result;
use iroh::{Endpoint, endpoint::presets, protocol::Router};
use iroh_ping::Ping;
#[tokio::main]
async fn main() -> Result<()> {
let recv_ep = Endpoint::bind(presets::N0).await?;
let recv_router = Router::builder(recv_ep.clone())
.accept(iroh_ping::ALPN, Ping::new())
.spawn();
recv_ep.online().await;
let addr = recv_router.endpoint().addr();
let send_ep = Endpoint::bind(presets::N0).await?;
let send_pinger = Ping::new();
let rtt = send_pinger.ping(&send_ep, addr).await?;
println!("ping took: {rtt:?} to complete");
send_ep.close().await;
recv_ep.close().await;
Ok(())
}