p2panda_blobs/
protocol.rs1use std::sync::Arc;
5
6use anyhow::Result;
7use futures_lite::future::Boxed as BoxedFuture;
8use iroh::endpoint::Connecting;
9use iroh_blobs::protocol::ALPN;
10use iroh_blobs::provider::{self, EventSender};
11use iroh_blobs::store::Store;
12use iroh_blobs::util::local_pool::LocalPoolHandle;
13use p2panda_net::ProtocolHandler;
14
15pub const BLOBS_ALPN: &[u8] = ALPN;
17
18#[derive(Debug)]
20pub struct BlobsProtocol<S> {
21 rt: LocalPoolHandle,
22 store: S,
23}
24
25impl<S: Store> BlobsProtocol<S> {
26 pub fn new(store: S, rt: LocalPoolHandle) -> Self {
31 Self { rt, store }
32 }
33}
34
35impl<S: Store> ProtocolHandler for BlobsProtocol<S> {
36 fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>> {
37 Box::pin(async move {
38 provider::handle_connection(
39 conn.await?,
40 self.store.clone(),
41 EventSender::default(),
42 self.rt.clone(),
43 )
44 .await;
45 Ok(())
46 })
47 }
48}