fn inject_response(&mut self, id: BitswapId, peer: PeerId, response: BitswapResponse) {
        if let Some(id) = self.requests.remove(&id) {
            match response {
                BitswapResponse::Have(have) => {
                    self.query_manager
                        .inject_response(id, Response::Have(peer, have));
                }
                BitswapResponse::Block(data) => {
                    if let Some(info) = self.query_manager.query_info(id) {
                        let len = data.len();
                        if let Ok(block) = Block::new(info.cid, data) {
                            RECEIVED_BLOCK_BYTES.inc_by(len as u64);
                            self.db_tx.unbounded_send(DbRequest::Insert(block)).ok();
                            self.query_manager
                                .inject_response(id, Response::Block(peer, true));
                        } else {
                            tracing::error!("received invalid block");
                            RECEIVED_INVALID_BLOCK_BYTES.inc_by(len as u64);
                            self.query_manager
                                .inject_response(id, Response::Block(peer, false));
                        }
                    }
                }
            }
        }
    }
/// Processes an incoming bitswap response.
Processes an incoming bitswap response.
Processes an incoming bitswap response .
fn inject_response(&mut self, id: BitswapId, peer: PeerId, response: BitswapResponse) {
        if let Some(id) = self.requests.remove(&id) {
            match response {
                BitswapResponse::Have(have) => {
                    self.query_manager
                        .inject_response(id, Response::Have(peer, have));
                }
                BitswapResponse::Block(data) => {
                    if let Some(info) = self.query_manager.query_info(id) {
                        let len = data.len();
                        if let Ok(block) = Block::new(info.cid, data) {
                            RECEIVED_BLOCK_BYTES.inc_by(len as u64);
                            self.db_tx.unbounded_send(DbRequest::Insert(block)).ok();
                            self.query_manager
                                .inject_response(id, Response::Block(peer, true));
                        } else {
                            tracing::error!("received invalid block");
                            RECEIVED_INVALID_BLOCK_BYTES.inc_by(len as u64);
                            self.query_manager
                                .inject_response(id, Response::Block(peer, false));
                        }
                    }
                }
            }
        }
    }
fn inject_response ( & mut self , id : BitswapId , peer : PeerId , response : BitswapResponse ) { if let Some ( id ) = self . requests . remove ( & id ) { match response { BitswapResponse :: Have ( have ) => { self . query_manager . inject_response ( id , Response :: Have ( peer , have ) ) ; } BitswapResponse :: Block ( data ) => { if let Some ( info ) = self . query_manager . query_info ( id ) { let len = data . len ( ) ; if let Ok ( block ) = Block :: new ( info . cid , data ) { RECEIVED_BLOCK_BYTES . inc_by ( len as u64 ) ; self . db_tx . unbounded_send ( DbRequest :: Insert ( block ) ) . ok ( ) ; self . query_manager . inject_response ( id , Response :: Block ( peer , true ) ) ; } else { tracing :: error ! ( " " ) ; RECEIVED_INVALID_BLOCK_BYTES . inc_by ( len as u64 ) ; self . query_manager . inject_response ( id , Response :: Block ( peer , false ) ) ; } } } } } }
Processes an incoming bitswap response.
Processes an incoming bitswap response .
&mut self
id
BitswapId
peer
PeerId
response
BitswapResponse
&mut self
id
BitswapId
peer
PeerId
response
BitswapResponse