1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! [`ProtocolHandler`] implementation for the docs [`Engine`].

use std::sync::Arc;

use anyhow::Result;
use futures_lite::future::Boxed as BoxedFuture;
use iroh_net::endpoint::Connecting;
use iroh_router::ProtocolHandler;

use crate::engine::Engine;

impl<D: iroh_blobs::store::Store> ProtocolHandler for Engine<D> {
    fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>> {
        Box::pin(async move { self.handle_connection(conn).await })
    }

    fn shutdown(self: Arc<Self>) -> BoxedFuture<()> {
        Box::pin(async move {
            if let Err(err) = (*self).shutdown().await {
                tracing::warn!("shutdown error: {:?}", err);
            }
        })
    }
}