Skip to main content

ActorManager

Struct ActorManager 

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

Thread-safe implementation using DashMap for lock-free concurrent access.

Implementations§

Source§

impl ActorManager

Source

pub fn new(config: ActorConfig) -> Self

Create a new actor manager with the given configuration.

Source

pub fn config(&self) -> &ActorConfig

Get the configuration.

Source

pub fn is_enabled(&self) -> bool

Check if actor tracking is enabled.

Source

pub fn len(&self) -> usize

Get the number of tracked actors.

Source

pub fn is_empty(&self) -> bool

Check if the store is empty.

Source

pub fn get_or_create_actor( &self, ip: IpAddr, fingerprint: Option<&str>, ) -> String

Get or create an actor for the given IP and optional fingerprint.

§Correlation Logic
  1. Check if IP is already mapped to an actor
  2. Check if fingerprint is already mapped to an actor
  3. If both match different actors, prefer fingerprint (more stable)
  4. If no match, create a new actor
§Returns

The actor_id for the correlated or newly created actor.

Source

pub fn record_rule_match( &self, actor_id: &str, rule_id: &str, risk_contribution: f64, category: &str, )

Record a rule match for an actor.

§Arguments
  • actor_id - The actor ID to record the match for
  • rule_id - The rule that matched
  • risk_contribution - Risk points to add
  • category - Category of the rule (e.g., “sqli”, “xss”)
Source

pub fn touch_actor(&self, actor_id: &str)

Touch an actor to update last seen timestamp.

Source

pub fn get_actor(&self, actor_id: &str) -> Option<ActorState>

Get actor state by ID.

Source

pub fn get_actor_by_ip(&self, ip: IpAddr) -> Option<ActorState>

Get actor by IP address.

Source

pub fn get_actor_by_fingerprint(&self, fingerprint: &str) -> Option<ActorState>

Get actor by fingerprint.

Source

pub fn block_actor(&self, actor_id: &str, reason: &str) -> bool

Block an actor.

§Returns

true if the actor was blocked, false if not found.

Source

pub fn unblock_actor(&self, actor_id: &str) -> bool

Unblock an actor.

§Returns

true if the actor was unblocked, false if not found.

Source

pub fn is_blocked(&self, actor_id: &str) -> bool

Check if an actor is blocked.

Source

pub fn bind_session(&self, actor_id: &str, session_id: &str)

Associate a session with an actor. Session IDs are bounded by max_session_ids to prevent memory exhaustion.

Source

pub fn list_actors(&self, limit: usize, offset: usize) -> Vec<ActorState>

List actors with pagination.

§Arguments
  • limit - Maximum number of actors to return
  • offset - Number of actors to skip
§Returns

Vector of actor states sorted by last_seen (most recent first).

Source

pub fn list_by_min_risk( &self, min_risk: f64, limit: usize, offset: usize, ) -> Vec<ActorState>

List actors above a minimum risk score.

Results are sorted by risk score (desc), then last_seen (desc).

Source

pub fn list_blocked_actors(&self) -> Vec<ActorState>

List blocked actors.

Source

pub fn get_fingerprint_groups( &self, limit: usize, ) -> Vec<(String, Vec<String>, f64)>

Returns groups of actors sharing the same fingerprints. Used for identifying botnet clusters in the TUI.

Optimized with a 1-second cache to avoid full table scans on every TUI tick.

Source

pub fn start_background_tasks(self: Arc<Self>)

Start background tasks (decay, cleanup).

Spawns a background task that periodically:

  1. Decays risk scores by the decay factor
  2. Evicts stale actors if over capacity
Source

pub fn shutdown(&self)

Signal shutdown for background tasks.

Source

pub fn stats(&self) -> &ActorStats

Get statistics.

Source

pub fn clear(&self)

Clear all actors (primarily for testing).

Source

pub fn snapshot(&self) -> Vec<ActorState>

Create a snapshot of all actors for persistence.

Returns all actors regardless of status.

Source

pub fn restore(&self, actors: Vec<ActorState>)

Restore actors from a snapshot.

Clears existing state and loads the provided actors.

Trait Implementations§

Source§

impl Debug for ActorManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ActorManager

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,