pub fn received_inv<T: BlockTree, C>(
        &mut self,
        addr: PeerId,
        inv: Vec<Inventory>,
        clock: &C,
        tree: &T,
    ) where
        C: Clock,
    {
        if !self.peers.contains_key(&addr) {
            return;
        }
        let mut best_block = None;

        for i in &inv {
            if let Inventory::Block(hash) = i {
                // TODO: Update block availability for this peer.
                if !tree.is_known(hash) {
                    self.upstream.event(Event::BlockDiscovered(addr, *hash));
                    // The final block hash in the inventory should be the highest. Use
                    // that one for a `getheaders` call.
                    best_block = Some(hash);
                }
            }
        }

        if let Some(stop_hash) = best_block {
            let locators = (tree.locator_hashes(tree.height()), *stop_hash);
            let timeout = self.config.request_timeout;

            // Try to find headers leading up to the `inv` entry.

            self.request(
                addr,
                locators,
                clock.local_time(),
                timeout,
                OnTimeout::Ignore,
            );
        }
    }
/// Called when we received an `inv` message. This will happen if we are out of sync with a
/// peer, and blocks are being announced. Otherwise, we expect to receive a `headers` message.
Called when we received an `inv` message. This will happen if we are out of sync with a
peer, and blocks are being announced. Otherwise, we expect to receive a `headers` message.
Called when we received an ` inv ` message . This will happen if we are out of sync with a peer and blocks are being announced . Otherwise we expect to receive a ` headers ` message .
pub fn received_inv<T: BlockTree, C>(
        &mut self,
        addr: PeerId,
        inv: Vec<Inventory>,
        clock: &C,
        tree: &T,
    ) where
        C: Clock,
    {
        if !self.peers.contains_key(&addr) {
            return;
        }
        let mut best_block = None;
        for i in &inv {
            if let Inventory::Block(hash) = i {
                // TODO: Update block availability for this peer.
                if !tree.is_known(hash) {
                    self.upstream.event(Event::BlockDiscovered(addr, *hash));
                    // The final block hash in the inventory should be the highest. Use
                    // that one for a `getheaders` call.
                    best_block = Some(hash);
                }
            }
        }
        if let Some(stop_hash) = best_block {
            let locators = (tree.locator_hashes(tree.height()), *stop_hash);
            let timeout = self.config.request_timeout;
            // Try to find headers leading up to the `inv` entry.
            self.request(
                addr,
                locators,
                clock.local_time(),
                timeout,
                OnTimeout::Ignore,
            );
        }
    }
pub fn received_inv < T : BlockTree , C > ( & mut self , addr : PeerId , inv : Vec < Inventory > , clock : & C , tree : & T , ) where C : Clock , { if ! self . peers . contains_key ( & addr ) { return ; } let mut best_block = None ; for i in & inv { if let Inventory :: Block ( hash ) = i { // TODO: Update block availability for this peer. if ! tree . is_known ( hash ) { self . upstream . event ( Event :: BlockDiscovered ( addr , * hash ) ) ; // The final block hash in the inventory should be the highest. Use // that one for a `getheaders` call. best_block = Some ( hash ) ; } } } if let Some ( stop_hash ) = best_block { let locators = ( tree . locator_hashes ( tree . height ( ) ) , * stop_hash ) ; let timeout = self . config . request_timeout ; // Try to find headers leading up to the `inv` entry. self . request ( addr , locators , clock . local_time ( ) , timeout , OnTimeout :: Ignore , ) ; } }
Called when we received an `inv` message.
Called when we received an ` inv ` message .
&mut self
addr
PeerId
inv
Vec<Inventory>
clock
&C
tree
&T