pub async fn bitswap_get<TMessage: DeserializeOwned>(
        &self,
        content: Cid,
    ) -> Result<TMessage, String> {
        // Check if what we are fetching over Bitswap already exists in the
        // database. If it does, return it, else fetch over the network.
        if let Some(b) = self.db.get(&content).map_err(|e| e.to_string())? {
            return Ok(b);
        }
        let (tx, rx) = oneshot_channel();
        self.network_send
            .send(NetworkMessage::BitswapRequest {
                cid: content,
                response_channel: tx,
            })
            .await
            .map_err(|_| "failed to send bitswap request, network receiver dropped")?;
        let res = future::timeout(Duration::from_secs(RPC_TIMEOUT), rx).await;
        match res {
            Ok(Ok(())) => {
                match self.db.get(&content) {
                    Ok(Some(b)) => Ok(b),
                    Ok(None) => Err(format!("Bitswap response successful for: {:?}, but can't find it in the database", content)),
                    Err(e) => Err(format!("Bitswap response successful for: {:?}, but can't retreive it from the database: {}", content, e.to_string())),
                }
            }
            Err(_e) => {
               Err(format!("Bitswap get for {:?} timed out", content))
            }
            Ok(Err(e)) => {
                Err(format!("Bitswap get for {:?} failed: {}", content, e.to_string()))
            }
        }
    }
/// Requests that some content with a particular Cid get fetched over Bitswap if it doesn't
/// exist in the BlockStore.
Requests that some content with a particular Cid get fetched over Bitswap if it doesn't
exist in the BlockStore.
Requests that some content with a particular Cid get fetched over Bitswap if it doesn ' t exist in the BlockStore .
pub async fn bitswap_get<TMessage: DeserializeOwned>(
        &self,
        content: Cid,
    ) -> Result<TMessage, String> {
        // Check if what we are fetching over Bitswap already exists in the
        // database. If it does, return it, else fetch over the network.
        if let Some(b) = self.db.get(&content).map_err(|e| e.to_string())? {
            return Ok(b);
        }
        let (tx, rx) = oneshot_channel();
        self.network_send
            .send(NetworkMessage::BitswapRequest {
                cid: content,
                response_channel: tx,
            })
            .await
            .map_err(|_| "failed to send bitswap request, network receiver dropped")?;
        let res = future::timeout(Duration::from_secs(RPC_TIMEOUT), rx).await;
        match res {
            Ok(Ok(())) => {
                match self.db.get(&content) {
                    Ok(Some(b)) => Ok(b),
                    Ok(None) => Err(format!("Bitswap response successful for: {:?}, but can't find it in the database", content)),
                    Err(e) => Err(format!("Bitswap response successful for: {:?}, but can't retreive it from the database: {}", content, e.to_string())),
                }
            }
            Err(_e) => {
               Err(format!("Bitswap get for {:?} timed out", content))
            }
            Ok(Err(e)) => {
                Err(format!("Bitswap get for {:?} failed: {}", content, e.to_string()))
            }
        }
    }
pub async fn bitswap_get < TMessage : DeserializeOwned > ( & self , content : Cid , ) -> Result < TMessage , String > { // Check if what we are fetching over Bitswap already exists in the // database. If it does, return it, else fetch over the network. if let Some ( b ) = self . db . get ( & content ) . map_err ( | e | e . to_string ( ) ) ? { return Ok ( b ) ; } let ( tx , rx ) = oneshot_channel ( ) ; self . network_send . send ( NetworkMessage :: BitswapRequest { cid : content , response_channel : tx , } ) . await . map_err ( | _ | " " ) ? ; let res = future :: timeout ( Duration :: from_secs ( RPC_TIMEOUT ) , rx ) . await ; match res { Ok ( Ok ( ( ) ) ) => { match self . db . get ( & content ) { Ok ( Some ( b ) ) => Ok ( b ) , Ok ( None ) => Err ( format ! ( " " content ) ) , Err ( e ) => Err ( format ! ( " " content e to_string ( ) ) ) , } } Err ( _e ) => { Err ( format ! ( " " content ) ) } Ok ( Err ( e ) ) => { Err ( format ! ( " " content e to_string ( ) ) ) } } }
Requests that some content with a particular Cid get fetched over Bitswap if it doesn't
exist in the BlockStore.
Requests that some content with a particular Cid get fetched over Bitswap if it doesn ' t exist in the BlockStore .
&self
content
Cid