async fn adjust_limit(&self, trigger: PolicyTrigger, create_limiter: bool) -> Result<()> {
        let scan_errors = self.ferox_scan.num_errors(trigger);
        let policy_errors = atomic_load!(self.policy_data.errors, Ordering::SeqCst);

        if let Ok(mut guard) = self.tuning_lock.try_lock() {
            if scan_errors > policy_errors {
                // errors have increased, need to reduce the requests/sec limit
                *guard = 0; // reset streak counter to 0
                if atomic_load!(self.policy_data.errors) != 0 {
                    self.policy_data.adjust_down();
                }
                self.policy_data.set_errors(scan_errors);
            } else {
                // errors can only be incremented, so an else is sufficient
                *guard += 1;
                self.policy_data.adjust_up(&*guard);
            }
        }

        if atomic_load!(self.policy_data.remove_limit) {
            self.set_rate_limiter(None).await?;
            atomic_store!(self.policy_data.remove_limit, false);
        } else if create_limiter {
            // create_limiter is really just used for unit testing situations, it's true anytime
            // during actual execution
            let new_limit = self.policy_data.get_limit(); // limit is set from within the lock
            self.set_rate_limiter(Some(new_limit)).await?;
        }

        Ok(())
    }
/// wrapper for adjust_[up,down] functions, checks error levels to determine adjustment direction
wrapper for adjust_[up,down] functions, checks error levels to determine adjustment direction
wrapper for adjust_ [ up down ] functions checks error levels to determine adjustment direction
async fn adjust_limit(&self, trigger: PolicyTrigger, create_limiter: bool) -> Result<()> {
        let scan_errors = self.ferox_scan.num_errors(trigger);
        let policy_errors = atomic_load!(self.policy_data.errors, Ordering::SeqCst);
        if let Ok(mut guard) = self.tuning_lock.try_lock() {
            if scan_errors > policy_errors {
                // errors have increased, need to reduce the requests/sec limit
                *guard = 0; // reset streak counter to 0
                if atomic_load!(self.policy_data.errors) != 0 {
                    self.policy_data.adjust_down();
                }
                self.policy_data.set_errors(scan_errors);
            } else {
                // errors can only be incremented, so an else is sufficient
                *guard += 1;
                self.policy_data.adjust_up(&*guard);
            }
        }
        if atomic_load!(self.policy_data.remove_limit) {
            self.set_rate_limiter(None).await?;
            atomic_store!(self.policy_data.remove_limit, false);
        } else if create_limiter {
            // create_limiter is really just used for unit testing situations, it's true anytime
            // during actual execution
            let new_limit = self.policy_data.get_limit(); // limit is set from within the lock
            self.set_rate_limiter(Some(new_limit)).await?;
        }
        Ok(())
    }
async fn adjust_limit ( & self , trigger : PolicyTrigger , create_limiter : bool ) -> Result < ( ) > { let scan_errors = self . ferox_scan . num_errors ( trigger ) ; let policy_errors = atomic_load ! ( self policy_data errors Ordering SeqCst ) ; if let Ok ( mut guard ) = self . tuning_lock . try_lock ( ) { if scan_errors > policy_errors { // errors have increased, need to reduce the requests/sec limit * guard = 0 ; // reset streak counter to 0 if atomic_load ! ( self policy_data errors ) != 0 { self . policy_data . adjust_down ( ) ; } self . policy_data . set_errors ( scan_errors ) ; } else { // errors can only be incremented, so an else is sufficient * guard += 1 ; self . policy_data . adjust_up ( & * guard ) ; } } if atomic_load ! ( self policy_data remove_limit ) { self . set_rate_limiter ( None ) . await ? ; atomic_store ! ( self policy_data remove_limit false ) ; } else if create_limiter { // create_limiter is really just used for unit testing situations, it's true anytime // during actual execution let new_limit = self . policy_data . get_limit ( ) ; // limit is set from within the lock self . set_rate_limiter ( Some ( new_limit ) ) . await ? ; } Ok ( ( ) ) }
wrapper for adjust_[up,down] functions, checks error levels to determine adjustment direction
wrapper for adjust_ [ up down ] functions checks error levels to determine adjustment direction
&self
trigger
PolicyTrigger
create_limiter
bool