pub struct ActorManager { /* private fields */ }Expand description
Thread-safe implementation using DashMap for lock-free concurrent access.
Implementations§
Source§impl ActorManager
impl ActorManager
Sourcepub fn new(config: ActorConfig) -> Self
pub fn new(config: ActorConfig) -> Self
Create a new actor manager with the given configuration.
Sourcepub fn config(&self) -> &ActorConfig
pub fn config(&self) -> &ActorConfig
Get the configuration.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if actor tracking is enabled.
Sourcepub fn get_or_create_actor(
&self,
ip: IpAddr,
fingerprint: Option<&str>,
) -> String
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
- Check if IP is already mapped to an actor
- Check if fingerprint is already mapped to an actor
- If both match different actors, prefer fingerprint (more stable)
- If no match, create a new actor
§Returns
The actor_id for the correlated or newly created actor.
Sourcepub fn record_rule_match(
&self,
actor_id: &str,
rule_id: &str,
risk_contribution: f64,
category: &str,
)
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 forrule_id- The rule that matchedrisk_contribution- Risk points to addcategory- Category of the rule (e.g., “sqli”, “xss”)
Sourcepub fn touch_actor(&self, actor_id: &str)
pub fn touch_actor(&self, actor_id: &str)
Touch an actor to update last seen timestamp.
Sourcepub fn get_actor(&self, actor_id: &str) -> Option<ActorState>
pub fn get_actor(&self, actor_id: &str) -> Option<ActorState>
Get actor state by ID.
Sourcepub fn get_actor_by_ip(&self, ip: IpAddr) -> Option<ActorState>
pub fn get_actor_by_ip(&self, ip: IpAddr) -> Option<ActorState>
Get actor by IP address.
Sourcepub fn get_actor_by_fingerprint(&self, fingerprint: &str) -> Option<ActorState>
pub fn get_actor_by_fingerprint(&self, fingerprint: &str) -> Option<ActorState>
Get actor by fingerprint.
Sourcepub fn block_actor(&self, actor_id: &str, reason: &str) -> bool
pub fn block_actor(&self, actor_id: &str, reason: &str) -> bool
Sourcepub fn unblock_actor(&self, actor_id: &str) -> bool
pub fn unblock_actor(&self, actor_id: &str) -> bool
Sourcepub fn is_blocked(&self, actor_id: &str) -> bool
pub fn is_blocked(&self, actor_id: &str) -> bool
Check if an actor is blocked.
Sourcepub fn bind_session(&self, actor_id: &str, session_id: &str)
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.
Sourcepub fn list_actors(&self, limit: usize, offset: usize) -> Vec<ActorState>
pub fn list_actors(&self, limit: usize, offset: usize) -> Vec<ActorState>
Sourcepub fn list_by_min_risk(
&self,
min_risk: f64,
limit: usize,
offset: usize,
) -> Vec<ActorState>
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).
Sourcepub fn list_blocked_actors(&self) -> Vec<ActorState>
pub fn list_blocked_actors(&self) -> Vec<ActorState>
List blocked actors.
Sourcepub fn get_fingerprint_groups(
&self,
limit: usize,
) -> Vec<(String, Vec<String>, f64)>
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.
Sourcepub fn start_background_tasks(self: Arc<Self>)
pub fn start_background_tasks(self: Arc<Self>)
Start background tasks (decay, cleanup).
Spawns a background task that periodically:
- Decays risk scores by the decay factor
- Evicts stale actors if over capacity
Sourcepub fn stats(&self) -> &ActorStats
pub fn stats(&self) -> &ActorStats
Get statistics.
Sourcepub fn snapshot(&self) -> Vec<ActorState>
pub fn snapshot(&self) -> Vec<ActorState>
Create a snapshot of all actors for persistence.
Returns all actors regardless of status.
Sourcepub fn restore(&self, actors: Vec<ActorState>)
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
impl Debug for ActorManager
Auto Trait Implementations§
impl !Freeze for ActorManager
impl !RefUnwindSafe for ActorManager
impl Send for ActorManager
impl Sync for ActorManager
impl Unpin for ActorManager
impl UnsafeUnpin for ActorManager
impl UnwindSafe for ActorManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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