use iroh::{Endpoint, protocol::Router};
use iroh_auth::Authenticator;
#[derive(Debug)]
struct MyProtocolHandler;
impl iroh::protocol::ProtocolHandler for MyProtocolHandler {
async fn accept(
&self,
_connection: iroh::endpoint::Connection,
) -> Result<(), iroh::protocol::AcceptError> {
Ok(())
}
}
#[tokio::main]
async fn main() -> Result<(), String> {
let auth = Authenticator::new("my-super-secret-password");
let endpoint = Endpoint::builder(iroh::endpoint::presets::N0)
.hooks(auth.clone())
.bind()
.await.map_err(|e| e.to_string())?;
auth.set_endpoint(&endpoint);
let router = Router::builder(endpoint)
.accept(iroh_auth::ALPN, auth.clone())
.accept(b"/my-app/1.0", MyProtocolHandler)
.spawn();
router.shutdown().await.map_err(|e| e.to_string())?;
Ok(())
}