Crates.io | iroh-ping |
lib.rs | iroh-ping |
version | 0.3.0 |
created_at | 2025-06-26 17:46:55.148338+00 |
updated_at | 2025-08-25 17:39:33.841028+00 |
description | high level PING-PONG iroh protocol |
homepage | |
repository | https://github.com/n0-computer/iroh-ping |
max_upload_size | |
id | 1727597 |
size | 151,863 |
A very simple iroh protocol for pinging a remote node. It's a high level example & easy starting point for new projects:
// a program that creates two endpoints & sends a ping between them
use anyhow::Result;
use iroh::{Endpoint, protocol::Router};
use iroh_ping::{ALPN as PingALPN, Ping};
#[tokio::main]
async fn main() -> Result<()> {
// create the receive side
let recv_ep = Endpoint::builder().discovery_n0().bind().await?;
let recv_router = Router::builder(recv_ep)
.accept(PingALPN, Ping::new())
.spawn();
let addr = recv_router.endpoint().node_addr().await?;
// create a send side & send a ping
let send_ep = Endpoint::builder().discovery_n0().bind().await?;
let send_pinger = Ping::new();
let rtt = send_pinger.ping(&send_ep, addr).await?;
println!("ping took: {rtt:?} to complete");
Ok(())
}
Iroh has all sorts of internal ping-type messages, this is a high level demo of a protocol, and in no way necessary for iroh's normal operation.