// New request that has been sent/ received, but with no response yet.
// Assign the request to the provided connection or else to a random established one.
// Return [`None`] if there are no connections.
New request that has been sent/ received, but with no response yet.
Assign the request to the provided connection or else to a random established one.
Return [`None`] if there are no connections.
New request that has been sent / received but with no response yet . Assign the request to the provided connection or else to a random established one . Return [ ` None ` ] if there are no connections .
pub fn add_request(
        &mut self,
        peer: &PeerId,
        request_id: RequestId,
        connection: Option<ConnectionId>,
        direction: &RequestDirection,
    ) -> Option<ConnectionId> {
        let connections = self.established.get(peer)?.connections.keys();
        let conn = match connection {
            Some(conn) => {
                // Check if the provided connection is active.
                connections.into_iter().find(|&c| c == &conn)?;
                conn
            }
            None => {
                // Assign request to a rather random connection.
                let index = (request_id.value() as usize) % connections.len();
                #[allow(clippy::iter_skip_next)]
                connections.skip(index).next().cloned()?
            }
        };
        let pending_responses = self
            .pending_responses
            .entry(conn)
            .or_insert_with(PendingResponses::default);
        match direction {
            RequestDirection::Inbound => pending_responses.inbound_requests.insert(request_id),
            RequestDirection::Outbound => pending_responses.outbound_requests.insert(request_id),
        };
        Some(conn)
    }
pub fn add_request ( & mut self , peer : & PeerId , request_id : RequestId , connection : Option < ConnectionId > , direction : & RequestDirection , ) -> Option < ConnectionId > { let connections = self . established . get ( peer ) ? . connections . keys ( ) ; let conn = match connection { Some ( conn ) => { // Check if the provided connection is active. connections . into_iter ( ) . find ( | & c | c == & conn ) ? ; conn } None => { // Assign request to a rather random connection. let index = ( request_id . value ( ) as usize ) % connections . len ( ) ; # [ allow ( clippy iter_skip_next ) ] connections . skip ( index ) . next ( ) . cloned ( ) ? } } ; let pending_responses = self . pending_responses . entry ( conn ) . or_insert_with ( PendingResponses :: default ) ; match direction { RequestDirection :: Inbound => pending_responses . inbound_requests . insert ( request_id ) , RequestDirection :: Outbound => pending_responses . outbound_requests . insert ( request_id ) , } ; Some ( conn ) }
New request that has been sent/ received, but with no response yet.
New request that has been sent / received but with no response yet .
&mut self
peer
&PeerId
request_id
RequestId
connection
Option<ConnectionId>
direction
&RequestDirection