pub fn send_getcfheaders<T: BlockTree>(
        &mut self,
        range: Range<Height>,
        tree: &T,
        time: LocalTime,
    ) -> Option<(PeerId, Height, BlockHash)> {
        let count = range.end as usize - range.start as usize;

        debug_assert!(range.start < range.end);
        debug_assert!(!range.is_empty());

        if range.is_empty() {
            return None;
        }
        let start_height = range.start;

        // Cap request to `MAX_MESSAGE_CFHEADERS`.
        let stop_hash = if count > MAX_MESSAGE_CFHEADERS {
            let stop_height = range.start + MAX_MESSAGE_CFHEADERS as Height - 1;
            let stop_block = tree
                .get_block_by_height(stop_height)
                .expect("all headers up to the tip exist");

            stop_block.block_hash()
        } else {
            let (hash, _) = tree.tip();

            hash
        };
        if self.inflight.contains_key(&stop_hash) {
            // Don't request the same thing twice.
            return None;
        }

        // TODO: We should select peers that are caught up to the requested height.
        if let Some(peers) = NonEmpty::from_vec(self.peers.keys().collect()) {
            let ix = self.rng.usize(..peers.len());
            let peer = *peers.get(ix).unwrap(); // Can't fail.

            self.upstream.get_cfheaders(
                *peer,
                start_height,
                stop_hash,
                self.config.request_timeout,
            );
            self.inflight.insert(stop_hash, time);

            return Some((*peer, start_height, stop_hash));
        } else {
            self.upstream.event(Event::RequestCanceled {
                reason: "no peers with required services",
            });
        }
        None
    }
/// Send a `getcfheaders` message to a random peer.
Send a `getcfheaders` message to a random peer.
Send a ` getcfheaders ` message to a random peer .
pub fn send_getcfheaders<T: BlockTree>(
        &mut self,
        range: Range<Height>,
        tree: &T,
        time: LocalTime,
    ) -> Option<(PeerId, Height, BlockHash)> {
        let count = range.end as usize - range.start as usize;
        debug_assert!(range.start < range.end);
        debug_assert!(!range.is_empty());
        if range.is_empty() {
            return None;
        }
        let start_height = range.start;
        // Cap request to `MAX_MESSAGE_CFHEADERS`.
        let stop_hash = if count > MAX_MESSAGE_CFHEADERS {
            let stop_height = range.start + MAX_MESSAGE_CFHEADERS as Height - 1;
            let stop_block = tree
                .get_block_by_height(stop_height)
                .expect("all headers up to the tip exist");
            stop_block.block_hash()
        } else {
            let (hash, _) = tree.tip();
            hash
        };
        if self.inflight.contains_key(&stop_hash) {
            // Don't request the same thing twice.
            return None;
        }
        // TODO: We should select peers that are caught up to the requested height.
        if let Some(peers) = NonEmpty::from_vec(self.peers.keys().collect()) {
            let ix = self.rng.usize(..peers.len());
            let peer = *peers.get(ix).unwrap(); // Can't fail.
            self.upstream.get_cfheaders(
                *peer,
                start_height,
                stop_hash,
                self.config.request_timeout,
            );
            self.inflight.insert(stop_hash, time);
            return Some((*peer, start_height, stop_hash));
        } else {
            self.upstream.event(Event::RequestCanceled {
                reason: "no peers with required services",
            });
        }
        None
    }
pub fn send_getcfheaders < T : BlockTree > ( & mut self , range : Range < Height > , tree : & T , time : LocalTime , ) -> Option < ( PeerId , Height , BlockHash ) > { let count = range . end as usize - range . start as usize ; debug_assert ! ( range start range end ) ; debug_assert ! ( range is_empty ( ) ) ; if range . is_empty ( ) { return None ; } let start_height = range . start ; // Cap request to `MAX_MESSAGE_CFHEADERS`. let stop_hash = if count > MAX_MESSAGE_CFHEADERS { let stop_height = range . start + MAX_MESSAGE_CFHEADERS as Height - 1 ; let stop_block = tree . get_block_by_height ( stop_height ) . expect ( " " ) ; stop_block . block_hash ( ) } else { let ( hash , _ ) = tree . tip ( ) ; hash } ; if self . inflight . contains_key ( & stop_hash ) { // Don't request the same thing twice. return None ; } // TODO: We should select peers that are caught up to the requested height. if let Some ( peers ) = NonEmpty :: from_vec ( self . peers . keys ( ) . collect ( ) ) { let ix = self . rng . usize ( .. peers . len ( ) ) ; let peer = * peers . get ( ix ) . unwrap ( ) ; // Can't fail. self . upstream . get_cfheaders ( * peer , start_height , stop_hash , self . config . request_timeout , ) ; self . inflight . insert ( stop_hash , time ) ; return Some ( ( * peer , start_height , stop_hash ) ) ; } else { self . upstream . event ( Event :: RequestCanceled { reason : " " , } ) ; } None }
Send a `getcfheaders` message to a random peer.
Send a ` getcfheaders ` message to a random peer .
&mut self
range
Range<Height>
tree
&T
time
LocalTime