pub fn received_getcfheaders<T: BlockTree>(
        &mut self,
        from: &PeerId,
        msg: GetCFHeaders,
        tree: &T,
    ) -> Result<(), Error> {
        let from = *from;

        if msg.filter_type != 0x0 {
            return Err(Error::InvalidMessage {
                from,
                reason: "getcfheaders: invalid filter type",
            });
        }

        let start_height = msg.start_height as Height;
        let stop_height = if let Some((height, _)) = tree.get_block(&msg.stop_hash) {
            height
        } else {
            // Can't handle this message, we don't have the stop block.
            return Err(Error::Ignored {
                msg: "getcfheaders",
                from,
            });
        };

        let headers = self.filters.get_headers(start_height..stop_height);
        if !headers.is_empty() {
            let hashes = headers.iter().map(|(hash, _)| *hash);
            let prev_header = self
                .filters
                .get_prev_header(start_height)
                .expect("SpvManager::received_getcfheaders: all headers up to the tip must exist");

            self.upstream.send_cfheaders(
                from,
                CFHeaders {
                    filter_type: msg.filter_type,
                    stop_hash: msg.stop_hash,
                    previous_filter: prev_header.into(),
                    filter_hashes: hashes.collect(),
                },
            );
            return Ok(());
        }
        // We must be syncing, since we have the block headers requested but
        // not the associated filter headers. Simply ignore the request.
        Err(Error::Ignored {
            msg: "getcfheaders",
            from,
        })
    }
/// Handle a `getcfheaders` message from a peer.
Handle a `getcfheaders` message from a peer.
Handle a ` getcfheaders ` message from a peer .
pub fn received_getcfheaders<T: BlockTree>(
        &mut self,
        from: &PeerId,
        msg: GetCFHeaders,
        tree: &T,
    ) -> Result<(), Error> {
        let from = *from;
        if msg.filter_type != 0x0 {
            return Err(Error::InvalidMessage {
                from,
                reason: "getcfheaders: invalid filter type",
            });
        }
        let start_height = msg.start_height as Height;
        let stop_height = if let Some((height, _)) = tree.get_block(&msg.stop_hash) {
            height
        } else {
            // Can't handle this message, we don't have the stop block.
            return Err(Error::Ignored {
                msg: "getcfheaders",
                from,
            });
        };
        let headers = self.filters.get_headers(start_height..stop_height);
        if !headers.is_empty() {
            let hashes = headers.iter().map(|(hash, _)| *hash);
            let prev_header = self
                .filters
                .get_prev_header(start_height)
                .expect("SpvManager::received_getcfheaders: all headers up to the tip must exist");
            self.upstream.send_cfheaders(
                from,
                CFHeaders {
                    filter_type: msg.filter_type,
                    stop_hash: msg.stop_hash,
                    previous_filter: prev_header.into(),
                    filter_hashes: hashes.collect(),
                },
            );
            return Ok(());
        }
        // We must be syncing, since we have the block headers requested but
        // not the associated filter headers. Simply ignore the request.
        Err(Error::Ignored {
            msg: "getcfheaders",
            from,
        })
    }
pub fn received_getcfheaders < T : BlockTree > ( & mut self , from : & PeerId , msg : GetCFHeaders , tree : & T , ) -> Result < ( ) , Error > { let from = * from ; if msg . filter_type != 0x0 { return Err ( Error :: InvalidMessage { from , reason : " " , } ) ; } let start_height = msg . start_height as Height ; let stop_height = if let Some ( ( height , _ ) ) = tree . get_block ( & msg . stop_hash ) { height } else { // Can't handle this message, we don't have the stop block. return Err ( Error :: Ignored { msg : " " , from , } ) ; } ; let headers = self . filters . get_headers ( start_height .. stop_height ) ; if ! headers . is_empty ( ) { let hashes = headers . iter ( ) . map ( | ( hash , _ ) | * hash ) ; let prev_header = self . filters . get_prev_header ( start_height ) . expect ( " " ) ; self . upstream . send_cfheaders ( from , CFHeaders { filter_type : msg . filter_type , stop_hash : msg . stop_hash , previous_filter : prev_header . into ( ) , filter_hashes : hashes . collect ( ) , } , ) ; return Ok ( ( ) ) ; } // We must be syncing, since we have the block headers requested but // not the associated filter headers. Simply ignore the request. Err ( Error :: Ignored { msg : " " , from , } ) }
Handle a `getcfheaders` message from a peer.
Handle a ` getcfheaders ` message from a peer .
&mut self
from
&PeerId
msg
GetCFHeaders
tree
&T