pub fn received_cfheaders<T: BlockTree>(
        &mut self,
        from: &PeerId,
        msg: CFHeaders,
        tree: &T,
        time: LocalTime,
    ) -> Result<Height, Error> {
        let from = *from;

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

        let prev_header: FilterHeader = msg.previous_filter.into();
        let (_, tip) = self.filters.tip();

        // If the previous header doesn't match our tip, this could be a stale
        // message arriving too late. Ignore it.
        if tip != &prev_header {
            return Ok(self.filters.height());
        }

        let start_height = self.filters.height();
        let stop_height = if let Some((height, _)) = tree.get_block(&msg.stop_hash) {
            height
        } else {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: unknown stop hash",
            });
        };

        if self.inflight.remove(&msg.stop_hash).is_none() {
            return Err(Error::Ignored {
                from,
                msg: "cfheaders: unsolicited message",
            });
        }

        let hashes = msg.filter_hashes;
        let count = hashes.len();

        if start_height > stop_height {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: start height is greater than stop height",
            });
        }

        if count > MAX_MESSAGE_CFHEADERS {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: header count exceeds maximum",
            });
        }

        if (stop_height - start_height) as usize != count {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: header count does not match height range",
            });
        }

        // Ok, looks like everything's valid..

        let mut last_header = prev_header;
        let mut headers = Vec::with_capacity(count);

        // Create headers out of the hashes.
        for filter_hash in hashes {
            last_header = FilterHeader::new(filter_hash, &last_header);
            headers.push((filter_hash, last_header));
        }
        self.filters
            .import_headers(headers)
            .map(|height| {
                self.upstream.event(Event::FilterHeadersImported { height });
                assert!(height <= tree.height());

                if height == tree.height() {
                    self.upstream.event(Event::Synced(height));
                } else {
                    self.sync(tree, time);
                }
                height
            })
            .map_err(Error::from)
    }
/// Handle a `cfheaders` message from a peer.
Handle a `cfheaders` message from a peer.
Handle a ` cfheaders ` message from a peer .
pub fn received_cfheaders<T: BlockTree>(
        &mut self,
        from: &PeerId,
        msg: CFHeaders,
        tree: &T,
        time: LocalTime,
    ) -> Result<Height, Error> {
        let from = *from;
        if msg.filter_type != 0x0 {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: invalid filter type",
            });
        }
        let prev_header: FilterHeader = msg.previous_filter.into();
        let (_, tip) = self.filters.tip();
        // If the previous header doesn't match our tip, this could be a stale
        // message arriving too late. Ignore it.
        if tip != &prev_header {
            return Ok(self.filters.height());
        }
        let start_height = self.filters.height();
        let stop_height = if let Some((height, _)) = tree.get_block(&msg.stop_hash) {
            height
        } else {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: unknown stop hash",
            });
        };
        if self.inflight.remove(&msg.stop_hash).is_none() {
            return Err(Error::Ignored {
                from,
                msg: "cfheaders: unsolicited message",
            });
        }
        let hashes = msg.filter_hashes;
        let count = hashes.len();
        if start_height > stop_height {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: start height is greater than stop height",
            });
        }
        if count > MAX_MESSAGE_CFHEADERS {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: header count exceeds maximum",
            });
        }
        if (stop_height - start_height) as usize != count {
            return Err(Error::InvalidMessage {
                from,
                reason: "cfheaders: header count does not match height range",
            });
        }
        // Ok, looks like everything's valid..
        let mut last_header = prev_header;
        let mut headers = Vec::with_capacity(count);
        // Create headers out of the hashes.
        for filter_hash in hashes {
            last_header = FilterHeader::new(filter_hash, &last_header);
            headers.push((filter_hash, last_header));
        }
        self.filters
            .import_headers(headers)
            .map(|height| {
                self.upstream.event(Event::FilterHeadersImported { height });
                assert!(height <= tree.height());
                if height == tree.height() {
                    self.upstream.event(Event::Synced(height));
                } else {
                    self.sync(tree, time);
                }
                height
            })
            .map_err(Error::from)
    }
pub fn received_cfheaders < T : BlockTree > ( & mut self , from : & PeerId , msg : CFHeaders , tree : & T , time : LocalTime , ) -> Result < Height , Error > { let from = * from ; if msg . filter_type != 0x0 { return Err ( Error :: InvalidMessage { from , reason : " " , } ) ; } let prev_header : FilterHeader = msg . previous_filter . into ( ) ; let ( _ , tip ) = self . filters . tip ( ) ; // If the previous header doesn't match our tip, this could be a stale // message arriving too late. Ignore it. if tip != & prev_header { return Ok ( self . filters . height ( ) ) ; } let start_height = self . filters . height ( ) ; let stop_height = if let Some ( ( height , _ ) ) = tree . get_block ( & msg . stop_hash ) { height } else { return Err ( Error :: InvalidMessage { from , reason : " " , } ) ; } ; if self . inflight . remove ( & msg . stop_hash ) . is_none ( ) { return Err ( Error :: Ignored { from , msg : " " , } ) ; } let hashes = msg . filter_hashes ; let count = hashes . len ( ) ; if start_height > stop_height { return Err ( Error :: InvalidMessage { from , reason : " " , } ) ; } if count > MAX_MESSAGE_CFHEADERS { return Err ( Error :: InvalidMessage { from , reason : " " , } ) ; } if ( stop_height - start_height ) as usize != count { return Err ( Error :: InvalidMessage { from , reason : " " , } ) ; } // Ok, looks like everything's valid.. let mut last_header = prev_header ; let mut headers = Vec :: with_capacity ( count ) ; // Create headers out of the hashes. for filter_hash in hashes { last_header = FilterHeader :: new ( filter_hash , & last_header ) ; headers . push ( ( filter_hash , last_header ) ) ; } self . filters . import_headers ( headers ) . map ( | height | { self . upstream . event ( Event :: FilterHeadersImported { height } ) ; assert ! ( height tree height ( ) ) ; if height == tree . height ( ) { self . upstream . event ( Event :: Synced ( height ) ) ; } else { self . sync ( tree , time ) ; } height } ) . map_err ( Error :: from ) }
Handle a `cfheaders` message from a peer.
Handle a ` cfheaders ` message from a peer .
&mut self
from
&PeerId
msg
CFHeaders
tree
&T
time
LocalTime