async fn handle_chain_exchange_request<T>(
        &self,
        peer_id: Option<PeerId>,
        tsk: &TipsetKeys,
        request_len: u64,
        options: u64,
    ) -> Result<Vec<T>, String>
    where
        T: TryFrom<TipsetBundle, Error = String>,
    {
        let request = ChainExchangeRequest {
            start: tsk.cids().to_vec(),
            request_len,
            options,
        };

        let global_pre_time = SystemTime::now();
        let bs_res = match peer_id {
            Some(id) => self
                .chain_exchange_request(id, request)
                .await?
                .into_result()?,
            None => {
                let peers = self.peer_manager.top_peers_shuffled().await;
                let mut res = None;
                for p in peers.into_iter() {
                    match self
                        .chain_exchange_request(p.clone(), request.clone())
                        .await
                    {
                        Ok(bs_res) => match bs_res.into_result() {
                            Ok(r) => {
                                res = Some(r);
                                break;
                            }
                            Err(e) => {
                                warn!("Failed chain_exchange response: {}", e);
                                continue;
                            }
                        },
                        Err(e) => {
                            warn!("Failed chain_exchange request to peer {:?}: {}", p, e);
                            continue;
                        }
                    }
                }

                res.ok_or_else(|| "ChainExchange request failed for all top peers".to_string())?
            }
        };

        match SystemTime::now().duration_since(global_pre_time) {
            Ok(t) => self.peer_manager.log_global_success(t).await,
            Err(e) => warn!("logged time less than before request: {}", e),
        }

        Ok(bs_res)
    }
/// Helper function to handle the peer retrieval if no peer supplied as well as the logging
/// and updating of the peer info in the `PeerManager`.
Helper function to handle the peer retrieval if no peer supplied as well as the logging
and updating of the peer info in the `PeerManager`.
Helper function to handle the peer retrieval if no peer supplied as well as the logging and updating of the peer info in the ` PeerManager ` .
async fn handle_chain_exchange_request<T>(
        &self,
        peer_id: Option<PeerId>,
        tsk: &TipsetKeys,
        request_len: u64,
        options: u64,
    ) -> Result<Vec<T>, String>
    where
        T: TryFrom<TipsetBundle, Error = String>,
    {
        let request = ChainExchangeRequest {
            start: tsk.cids().to_vec(),
            request_len,
            options,
        };
        let global_pre_time = SystemTime::now();
        let bs_res = match peer_id {
            Some(id) => self
                .chain_exchange_request(id, request)
                .await?
                .into_result()?,
            None => {
                let peers = self.peer_manager.top_peers_shuffled().await;
                let mut res = None;
                for p in peers.into_iter() {
                    match self
                        .chain_exchange_request(p.clone(), request.clone())
                        .await
                    {
                        Ok(bs_res) => match bs_res.into_result() {
                            Ok(r) => {
                                res = Some(r);
                                break;
                            }
                            Err(e) => {
                                warn!("Failed chain_exchange response: {}", e);
                                continue;
                            }
                        },
                        Err(e) => {
                            warn!("Failed chain_exchange request to peer {:?}: {}", p, e);
                            continue;
                        }
                    }
                }
                res.ok_or_else(|| "ChainExchange request failed for all top peers".to_string())?
            }
        };
        match SystemTime::now().duration_since(global_pre_time) {
            Ok(t) => self.peer_manager.log_global_success(t).await,
            Err(e) => warn!("logged time less than before request: {}", e),
        }
        Ok(bs_res)
    }
async fn handle_chain_exchange_request < T > ( & self , peer_id : Option < PeerId > , tsk : & TipsetKeys , request_len : u64 , options : u64 , ) -> Result < Vec < T > , String > where T : TryFrom < TipsetBundle , Error = String > , { let request = ChainExchangeRequest { start : tsk . cids ( ) . to_vec ( ) , request_len , options , } ; let global_pre_time = SystemTime :: now ( ) ; let bs_res = match peer_id { Some ( id ) => self . chain_exchange_request ( id , request ) . await ? . into_result ( ) ? , None => { let peers = self . peer_manager . top_peers_shuffled ( ) . await ; let mut res = None ; for p in peers . into_iter ( ) { match self . chain_exchange_request ( p . clone ( ) , request . clone ( ) ) . await { Ok ( bs_res ) => match bs_res . into_result ( ) { Ok ( r ) => { res = Some ( r ) ; break ; } Err ( e ) => { warn ! ( " " e ) ; continue ; } } , Err ( e ) => { warn ! ( " " p e ) ; continue ; } } } res . ok_or_else ( | | " " . to_string ( ) ) ? } } ; match SystemTime :: now ( ) . duration_since ( global_pre_time ) { Ok ( t ) => self . peer_manager . log_global_success ( t ) . await , Err ( e ) => warn ! ( " " e ) , } Ok ( bs_res ) }
Helper function to handle the peer retrieval if no peer supplied as well as the logging
and updating of the peer info in the `PeerManager`.
Helper function to handle the peer retrieval if no peer supplied as well as the logging and updating of the peer info in the ` PeerManager ` .
&self
peer_id
Option<PeerId>
tsk
&TipsetKeys
request_len
u64
options
u64