Skip to content

Commit 382a0f3

Browse files
docs: update iroh-ping example to latest (#429)
1 parent 129e650 commit 382a0f3

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/app/page.jsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default function Page() {
8080
</p>
8181
<p className='mt-4 text-xl font-medium text-irohGray-600 dark:text-irohGray-400'>
8282
Dial any endpoint running anywhere, big or small &mdash;
83-
cloud servers, tablets, or Raspberry Pis.
83+
cloud servers, tablets, or Raspberry Pis.
8484
</p>
8585
<p className='mt-4 text-xl font-medium text-irohGray-600 dark:text-irohGray-400 mb-8'>
8686
The core technology is <a href="https://github.com/n0-computer/iroh" className='text-irohPurple-500 hover:underline'>open source</a>, and relays are stateless. That means you can pluralize with hosting across regions and clouds, or self-host anywhere in the world.
@@ -189,18 +189,18 @@ export default function Page() {
189189
<div className='px-8 pb-8 pt-8 sm:px-10 sm:pb-10 sm:pt-10'>
190190
<p className='mt-6 text-3xl font-bold tracking-tight text-irohGray-900 dark:text-irohGray-100'>Deploy, Monitor, Fix</p>
191191
<p className='mt-4 text-xl font-medium text-irohGray-600 dark:text-irohGray-400'>All commits to iroh&apos;s main branch run through a growing set of <a href="https://perf.iroh.computer" target="_blank" className="text-irohPurple-500 hover:underline">simulations &amp; tests</a>. </p>
192-
192+
193193
<p className='mt-4 text-xl font-medium text-irohGray-600 dark:text-irohGray-400 mb-8'>
194-
When you build your app, iroh provides opt-in
194+
When you build your app, iroh provides opt-in
195195
<a href="https://docs.iroh.computer/iroh-online/metrics/custom" className="text-irohPurple-500 hover:underline"> observability</a> and
196196
<a href="https://docs.iroh.computer/metrics/custom" className="text-irohPurple-500 hover:underline"> custom metrics</a> specific for your app. Get visibility into your endpoints &mdash; track connection health and throughput across all your devices and services.
197-
197+
198198
</p>
199199

200200
<Link href='https://docs.iroh.computer/what-is-iroh' className='inline-block my-4 text-irohPurple-500 plausible-event-name=Home+Start+Building+Click'>
201201
Montior your App<ArrowRightIcon className='inline-block w-5 h-5 ml-2 -mt-1' />
202202
</Link>
203-
203+
204204
</div>
205205
</div>
206206
</div>
@@ -248,24 +248,23 @@ export default function Page() {
248248
const codeSample = `// a program that creates two endpoints & sends a ping between them
249249
use anyhow::Result;
250250
use iroh::{Endpoint, protocol::Router};
251-
use iroh_ping::{ALPN as PingALPN, Ping};
251+
use iroh_ping::Ping;
252252
253253
#[tokio::main]
254254
async fn main() -> Result<()> {
255255
// create the receive side
256-
let recv_endpoint = Endpoint::bind().await?;
257-
let recv_router = Router::builder(recv_endpoint)
258-
.accept(PingALPN, Ping::new())
259-
.spawn();
260-
261-
// get the receive side's address:
262-
let addr = recv_router.endpoint().addr().await?;
256+
let recv_ep = Endpoint::builder().bind().await?;
257+
let recv_router = Router::builder(recv_ep.clone())
258+
.accept(iroh_ping::ALPN, Ping::new())
259+
.spawn();
260+
recv_ep.online().await;
261+
let addr = recv_router.endpoint().addr();
263262
264-
// create the send side & send a ping!
265-
let send_ep = Endpoint::bind().await?;
263+
// create a send side & send a ping
264+
let send_ep = Endpoint::builder().bind().await?;
266265
let send_pinger = Ping::new();
267-
send_pinger.ping(&send_ep, addr).await?;
266+
let rtt = send_pinger.ping(&send_ep, addr).await?;
267+
println!("ping took: {rtt:?} to complete");
268268
269-
// ok!
270269
Ok(())
271270
}`

0 commit comments

Comments
 (0)