Skip to main content

BehaviorTracker

Struct BehaviorTracker 

Source
pub struct BehaviorTracker { /* private fields */ }
Expand description

The reference BehaviorTracker’s in-memory return-pattern windows.

The redis-free fallback: pattern_key -> client_ip -> timestamps, with the same sliding-window arithmetic (len(timestamps) > threshold).

Implementations§

Source§

impl BehaviorTracker

Source

pub fn new() -> Self

A fresh tracker, the harness BehaviorTracker(config) with clean windows.

Source

pub fn reset(&mut self)

Forget every window (the per-case reset the harness performs).

Source

pub fn track_endpoint_usage( &mut self, endpoint_id: &str, client_ip: &str, rule: &BehaviorRule, now: f64, ) -> bool

track_endpoint_usage: record one request observation for (endpoint_id, client_ip) inside the rule’s window, and answer whether the rule tripped (len(timestamps) > threshold, the reference’s strict comparison). now is the caller’s clock (the reference time.time() float; unix_now converts).

Source

pub fn get_recent_event_count( &self, ip: &str, window_seconds: u64, now: f64, ) -> usize

get_recent_event_count: how many tracked events any endpoint recorded for ip inside window_seconds (the reference walks every endpoint bucket’s timestamps for the identity).

Source

pub fn track_return_pattern( &mut self, endpoint_id: &str, client_ip: &str, status: u16, body_prefix: Option<&[u8]>, rule: &BehaviorRule, max_inspect_bytes: usize, now: SystemTime, ) -> bool

track_return_pattern: record one response observation for (endpoint_id, client_ip) when the response matches the rule’s pattern, and answer whether the rule tripped (len(timestamps) > threshold inside the rule’s window).

status and body_prefix are the response facts: body_prefix is the caller’s capture bounded by the inspect-bytes budget and only read when the pattern needs the body and the caller has behavior_scan_response_body enabled. now is the caller’s clock (the reference time.time() float); SystemTime converts via unix_now.

Source

pub fn check_response_pattern( &mut self, status: u16, body_prefix: Option<&[u8]>, pattern: &str, max_inspect_bytes: usize, ) -> Option<bool>

_check_response_pattern: Some(true/false) when the pattern was evaluated, None when it could not be (a body pattern while no body prefix was captured).

Source

pub fn dispatch_action( rule: &BehaviorRule, client_ip: &str, passive_mode: bool, ) -> BehaviorAction

BehaviorActionDispatchMixin.apply_action: passive mode only logs (so BehaviorAction::LoggedOnly), active mode bans with the rule duration override (else the reference 3600s default) or reduces to a note. The caller applies the ban to its IP-ban store; the reference ban reason is behavioral_violation.

Trait Implementations§

Source§

impl Default for BehaviorTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.