fn route_inv(
        &mut self,
        req: Request,
        hash: InventoryHash,
    ) -> <Self as tower::Service<Request>>::Future {
        let inventory_peer_list = self
            .inventory_registry
            .peers(&hash)
            .filter(|&key| self.ready_services.contains_key(key))
            .copied()
            .collect();

        // # Security
        //
        // Choose a random, less-loaded peer with the inventory.
        //
        // If we chose the first peer in HashMap order,
        // peers would be able to influence our choice by switching addresses.
        // But we need the choice to be random,
        // so that a peer can't provide all our inventory responses.
        let peer = self.select_p2c_peer_from_list(&inventory_peer_list);

        match peer.and_then(|key| self.take_ready_service(&key)) {
            Some(mut svc) => {
                let peer = peer.expect("just checked peer is Some");
                tracing::trace!(?hash, ?peer, "routing based on inventory");
                let fut = svc.call(req);
                self.push_unready(peer, svc);
                fut.map_err(Into::into).boxed()
            }
            None => {
                tracing::trace!(?hash, "no ready peer for inventory, falling back to p2c");
                self.route_p2c(req)
            }
        }
    }
/// Tries to route a request to a peer that advertised that inventory,
/// falling back to P2C if there is no ready peer.
Tries to route a request to a peer that advertised that inventory,
falling back to P2C if there is no ready peer.
Tries to route a request to a peer that advertised that inventory falling back to P2C if there is no ready peer .
fn route_inv(
        &mut self,
        req: Request,
        hash: InventoryHash,
    ) -> <Self as tower::Service<Request>>::Future {
        let inventory_peer_list = self
            .inventory_registry
            .peers(&hash)
            .filter(|&key| self.ready_services.contains_key(key))
            .copied()
            .collect();
        // # Security
        //
        // Choose a random, less-loaded peer with the inventory.
        //
        // If we chose the first peer in HashMap order,
        // peers would be able to influence our choice by switching addresses.
        // But we need the choice to be random,
        // so that a peer can't provide all our inventory responses.
        let peer = self.select_p2c_peer_from_list(&inventory_peer_list);
        match peer.and_then(|key| self.take_ready_service(&key)) {
            Some(mut svc) => {
                let peer = peer.expect("just checked peer is Some");
                tracing::trace!(?hash, ?peer, "routing based on inventory");
                let fut = svc.call(req);
                self.push_unready(peer, svc);
                fut.map_err(Into::into).boxed()
            }
            None => {
                tracing::trace!(?hash, "no ready peer for inventory, falling back to p2c");
                self.route_p2c(req)
            }
        }
    }
fn route_inv ( & mut self , req : Request , hash : InventoryHash , ) -> < Self as tower :: Service < Request > > :: Future { let inventory_peer_list = self . inventory_registry . peers ( & hash ) . filter ( | & key | self . ready_services . contains_key ( key ) ) . copied ( ) . collect ( ) ; // # Security // // Choose a random, less-loaded peer with the inventory. // // If we chose the first peer in HashMap order, // peers would be able to influence our choice by switching addresses. // But we need the choice to be random, // so that a peer can't provide all our inventory responses. let peer = self . select_p2c_peer_from_list ( & inventory_peer_list ) ; match peer . and_then ( | key | self . take_ready_service ( & key ) ) { Some ( mut svc ) => { let peer = peer . expect ( " " ) ; tracing :: trace ! ( hash peer " " ) ; let fut = svc . call ( req ) ; self . push_unready ( peer , svc ) ; fut . map_err ( Into :: into ) . boxed ( ) } None => { tracing :: trace ! ( hash " " ) ; self . route_p2c ( req ) } } }
Tries to route a request to a peer that advertised that inventory,
falling back to P2C if there is no ready peer.
Tries to route a request to a peer that advertised that inventory falling back to P2C if there is no ready peer .
&mut self
req
Request
hash
InventoryHash