// Handle the approval / rejection of a individual request.
Handle the approval / rejection of a individual request.
Handle the approval / rejection of a individual request .
fn handle_request_approval(
        &mut self,
        request_id: RequestId,
        direction: &RequestDirection,
        is_allowed: bool,
    ) -> Option<()> {
        self.awaiting_approval.retain(|(r, _)| r != &request_id);
        let action = match direction {
            RequestDirection::Inbound => {
                let (peer, request, response_tx) = self.inbound_request_store.remove(&request_id)?;
                if !is_allowed {
                    self.connections.remove_request(&request_id, direction);
                    BehaviourAction::InboundFailure {
                        request_id,
                        peer,
                        failure: InboundFailure::NotPermitted,
                    }
                } else {
                    BehaviourAction::InboundOk {
                        request_id,
                        peer,
                        request,
                        response_tx,
                    }
                }
            }
            RequestDirection::Outbound => {
                let peer = self.outbound_request_store.get(&request_id).map(|(p, _)| *p)?;
                if !is_allowed {
                    self.outbound_request_store.remove(&request_id)?;
                    BehaviourAction::OutboundFailure {
                        request_id,
                        peer,
                        failure: OutboundFailure::NotPermitted,
                    }
                } else if let Some(connection) =
                    self.connections
                        .add_request(&peer, request_id, None, &RequestDirection::Outbound)
                {
                    let (peer, request) = self.outbound_request_store.remove(&request_id)?;
                    BehaviourAction::OutboundOk {
                        request_id,
                        peer,
                        request,
                        connection,
                    }
                } else {
                    self.awaiting_connection.entry(peer).or_default().push(request_id);
                    BehaviourAction::RequireDialAttempt(peer)
                }
            }
        };
        self.actions.push_back(action);
        Some(())
    }
fn handle_request_approval ( & mut self , request_id : RequestId , direction : & RequestDirection , is_allowed : bool , ) -> Option < ( ) > { self . awaiting_approval . retain ( | ( r , _ ) | r != & request_id ) ; let action = match direction { RequestDirection :: Inbound => { let ( peer , request , response_tx ) = self . inbound_request_store . remove ( & request_id ) ? ; if ! is_allowed { self . connections . remove_request ( & request_id , direction ) ; BehaviourAction :: InboundFailure { request_id , peer , failure : InboundFailure :: NotPermitted , } } else { BehaviourAction :: InboundOk { request_id , peer , request , response_tx , } } } RequestDirection :: Outbound => { let peer = self . outbound_request_store . get ( & request_id ) . map ( | ( p , _ ) | * p ) ? ; if ! is_allowed { self . outbound_request_store . remove ( & request_id ) ? ; BehaviourAction :: OutboundFailure { request_id , peer , failure : OutboundFailure :: NotPermitted , } } else if let Some ( connection ) = self . connections . add_request ( & peer , request_id , None , & RequestDirection :: Outbound ) { let ( peer , request ) = self . outbound_request_store . remove ( & request_id ) ? ; BehaviourAction :: OutboundOk { request_id , peer , request , connection , } } else { self . awaiting_connection . entry ( peer ) . or_default ( ) . push ( request_id ) ; BehaviourAction :: RequireDialAttempt ( peer ) } } } ; self . actions . push_back ( action ) ; Some ( ( ) ) }
Handle the approval / rejection of a individual request.
Handle the approval / rejection of a individual request .
&mut self
request_id
RequestId
direction
&RequestDirection
is_allowed
bool