async fn send_adnl_query<T, D>(
        &self, 
        request: T, 
        attempts: Option<u32>,
        timeout: Option<u64>
    ) -> Result<(D, Arc<Neighbour>)>
    where
        T: ton_api::AnyBoxedSerialize,
        D: ton_api::AnyBoxedSerialize
    {

        let data = TLObject::new(request);
        let attempts = attempts.unwrap_or(Self::ADNL_ATTEMPTS);

        for _ in 0..attempts {

            let peer = self.peers.choose_neighbour()?.ok_or_else(||error!("neighbour is not found!"))?;
            log::trace!("USE PEER {}, REQUEST {:?}", peer.id(), data);

            let now = std::time::Instant::now();
            let timeout = timeout.or(Some(AdnlNode::calc_timeout(peer.roundtrip_adnl())));
            let answer = self.overlay.query(peer.id(), &data, &self.overlay_id, timeout).await?;
            let t = now.elapsed();
         
            if let Some(answer) = answer {
                match answer.downcast::<D>() {
                    Ok(answer) => {
                        self.peers.update_neighbour_stats(peer.id(), &t, true, false, false)?;
                        return Ok((answer, peer))
                    },
                    Err(obj) => {
                        log::warn!("Wrong answer {:?} to {:?} from {}", obj, data, peer.id())
                    }
                }
            } else {
                log::warn!("No reply to {:?} from {}", data, peer.id())
            }
            self.peers.update_neighbour_stats(peer.id(), &t, false, false, true)?;

        }

        fail!("Cannot send query {:?} in {} attempts", data, attempts)
 
    }
// use this function if request size and answer size < 768 bytes (send query via ADNL)
use this function if request size and answer size < 768 bytes (send query via ADNL)
use this function if request size and answer size < 768 bytes ( send query via ADNL )
async fn send_adnl_query<T, D>(
        &self, 
        request: T, 
        attempts: Option<u32>,
        timeout: Option<u64>
    ) -> Result<(D, Arc<Neighbour>)>
    where
        T: ton_api::AnyBoxedSerialize,
        D: ton_api::AnyBoxedSerialize
    {
        let data = TLObject::new(request);
        let attempts = attempts.unwrap_or(Self::ADNL_ATTEMPTS);
        for _ in 0..attempts {
            let peer = self.peers.choose_neighbour()?.ok_or_else(||error!("neighbour is not found!"))?;
            log::trace!("USE PEER {}, REQUEST {:?}", peer.id(), data);
            let now = std::time::Instant::now();
            let timeout = timeout.or(Some(AdnlNode::calc_timeout(peer.roundtrip_adnl())));
            let answer = self.overlay.query(peer.id(), &data, &self.overlay_id, timeout).await?;
            let t = now.elapsed();
            if let Some(answer) = answer {
                match answer.downcast::<D>() {
                    Ok(answer) => {
                        self.peers.update_neighbour_stats(peer.id(), &t, true, false, false)?;
                        return Ok((answer, peer))
                    },
                    Err(obj) => {
                        log::warn!("Wrong answer {:?} to {:?} from {}", obj, data, peer.id())
                    }
                }
            } else {
                log::warn!("No reply to {:?} from {}", data, peer.id())
            }
            self.peers.update_neighbour_stats(peer.id(), &t, false, false, true)?;
        }
        fail!("Cannot send query {:?} in {} attempts", data, attempts)
    }
async fn send_adnl_query < T , D > ( & self , request : T , attempts : Option < u32 > , timeout : Option < u64 > ) -> Result < ( D , Arc < Neighbour > ) > where T : ton_api :: AnyBoxedSerialize , D : ton_api :: AnyBoxedSerialize { let data = TLObject :: new ( request ) ; let attempts = attempts . unwrap_or ( Self :: ADNL_ATTEMPTS ) ; for _ in 0 .. attempts { let peer = self . peers . choose_neighbour ( ) ? . ok_or_else ( | | error ! ( " " ) ) ? ; log :: trace ! ( " " peer id ( ) data ) ; let now = std :: time :: Instant :: now ( ) ; let timeout = timeout . or ( Some ( AdnlNode :: calc_timeout ( peer . roundtrip_adnl ( ) ) ) ) ; let answer = self . overlay . query ( peer . id ( ) , & data , & self . overlay_id , timeout ) . await ? ; let t = now . elapsed ( ) ; if let Some ( answer ) = answer { match answer . downcast :: < D > ( ) { Ok ( answer ) => { self . peers . update_neighbour_stats ( peer . id ( ) , & t , true , false , false ) ? ; return Ok ( ( answer , peer ) ) } , Err ( obj ) => { log :: warn ! ( " " obj data peer id ( ) ) } } } else { log :: warn ! ( " " data peer id ( ) ) } self . peers . update_neighbour_stats ( peer . id ( ) , & t , false , false , true ) ? ; } fail ! ( " " data attempts ) }
use this function if request size and answer size < 768 bytes (send query via ADNL)
use this function if request size and answer size < 768 bytes ( send query via ADNL )
&self
request
T
attempts
Option<u32>
timeout
Option<u64>
&self
request
T
attempts
Option<u32>
timeout
Option<u64>