1use iroh::{Endpoint, protocol::Router};
2use iroh_auth::Authenticator;
3
4#[derive(Debug)]
5struct MyProtocolHandler;
6
7impl iroh::protocol::ProtocolHandler for MyProtocolHandler {
8 async fn accept(
9 &self,
10 _connection: iroh::endpoint::Connection,
11 ) -> Result<(), iroh::protocol::AcceptError> {
12 Ok(())
14 }
15}
16
17#[tokio::main]
18async fn main() -> Result<(), String> {
19 let auth = Authenticator::new("my-super-secret-password");
21
22 let endpoint = Endpoint::builder()
24 .hooks(auth.clone())
25 .bind()
26 .await.map_err(|e| e.to_string())?;
27
28 auth.set_endpoint(&endpoint);
31
32 let router = Router::builder(endpoint)
34 .accept(Authenticator::ALPN, auth.clone())
35
36 .accept(b"/my-app/1.0", MyProtocolHandler)
38 .spawn();
39
40 router.shutdown().await.map_err(|e| e.to_string())?;
42 Ok(())
43}