pub struct CampaignManager { /* private fields */ }Expand description
Main orchestrator for campaign correlation.
Coordinates fingerprint indexing, campaign detection, and state management. This is the entry point for the correlation subsystem.
§Thread Safety
All methods are thread-safe and can be called concurrently. The manager uses lock-free data structures (DashMap) and atomic counters for high-performance concurrent access.
§Registration vs Detection
- Registration (
register_*methods): Called per-request, must be FAST. Only updates indexes, no detection logic. - Detection (
run_detection_cycle): Called periodically by background worker or on-demand. Processes all detectors and applies campaign updates.
§Detectors (ordered by weight)
- Attack Sequence (50) - Same attack payloads across actors
- Auth Token (45) - Same JWT structure/issuer across IPs
- HTTP Fingerprint (40) - Identical browser fingerprint (JA4H)
- TLS Fingerprint (35) - Same TLS signature (JA4)
- Behavioral Similarity (30) - Identical navigation/timing patterns
- Timing Correlation (25) - Coordinated request timing (botnets)
- Network Proximity (15) - Same ASN or /24 subnet
Implementations§
Source§impl CampaignManager
impl CampaignManager
Sourcepub fn with_config(config: ManagerConfig) -> Self
pub fn with_config(config: ManagerConfig) -> Self
Create a new campaign manager with custom configuration.
Sourcepub fn set_access_list_manager(
&mut self,
manager: Arc<ParkingLotRwLock<AccessListManager>>,
)
pub fn set_access_list_manager( &mut self, manager: Arc<ParkingLotRwLock<AccessListManager>>, )
Set the AccessListManager for automated mitigation.
Sourcepub fn set_telemetry_client(&mut self, client: Arc<TelemetryClient>)
pub fn set_telemetry_client(&mut self, client: Arc<TelemetryClient>)
Set the TelemetryClient for cross-tenant correlation.
Sourcepub fn register_ja4(&self, ip: IpAddr, fingerprint: String)
pub fn register_ja4(&self, ip: IpAddr, fingerprint: String)
Register a JA4 fingerprint for an IP address.
Called during request processing - must be fast. Only updates indexes, no detection logic is run.
§Arguments
ip- The IP address of the clientfingerprint- The JA4 TLS fingerprint
Sourcepub fn register_ja4_arc(&self, ip: IpAddr, fingerprint: Arc<str>)
pub fn register_ja4_arc(&self, ip: IpAddr, fingerprint: Arc<str>)
Register a JA4 fingerprint using Arc
Optimized version for callers who already have an Arc
§Arguments
ip- The IP address of the clientfingerprint- The JA4 TLS fingerprint as Arc
Sourcepub fn register_combined(&self, ip: IpAddr, fingerprint: String)
pub fn register_combined(&self, ip: IpAddr, fingerprint: String)
Register a combined (JA4+JA4H) fingerprint for an IP address.
Combined fingerprints provide higher confidence correlation due to increased specificity.
§Arguments
ip- The IP address of the clientfingerprint- The combined fingerprint hash
Sourcepub fn register_combined_arc(&self, ip: IpAddr, fingerprint: Arc<str>)
pub fn register_combined_arc(&self, ip: IpAddr, fingerprint: Arc<str>)
Register a combined fingerprint using Arc
Optimized version for callers who already have an Arc
§Arguments
ip- The IP address of the clientfingerprint- The combined fingerprint hash as Arc
Sourcepub fn register_fingerprints(
&self,
ip: IpAddr,
ja4: Option<String>,
ja4h: Option<String>,
)
pub fn register_fingerprints( &self, ip: IpAddr, ja4: Option<String>, ja4h: Option<String>, )
Register both JA4 and JA4H fingerprints.
Convenience method for registering both fingerprint types in one call.
§Arguments
ip- The IP address of the clientja4- Optional JA4 TLS fingerprintja4h- Optional JA4H HTTP fingerprint (used in combined hash)
Sourcepub fn record_attack(
&self,
ip: IpAddr,
payload_hash: String,
attack_type: String,
path: String,
)
pub fn record_attack( &self, ip: IpAddr, payload_hash: String, attack_type: String, path: String, )
Record an attack payload observation for campaign correlation.
Called when an attack is detected (SQLi, XSS, etc.) to correlate identical payloads across different IPs. Weight: 50 (highest signal).
§Arguments
ip- The IP address of the attackerpayload_hash- Hash of the normalized attack payloadattack_type- Classification (sqli, xss, path_traversal, etc.)path- Target path of the attack
Sourcepub fn record_token(&self, ip: IpAddr, jwt: &str)
pub fn record_token(&self, ip: IpAddr, jwt: &str)
Record a JWT token observation for campaign correlation.
Called when a JWT is seen in request headers. Correlates IPs using tokens with identical structure or issuer. Weight: 45.
§Arguments
ip- The IP address of the clientjwt- The raw JWT string (header.payload.signature)
Sourcepub fn record_request(&self, ip: IpAddr, method: &str, path: &str)
pub fn record_request(&self, ip: IpAddr, method: &str, path: &str)
Record a request for behavioral and timing analysis.
Should be called for every request to build behavioral patterns and detect timing correlations. Updates multiple detectors:
- Behavioral detector (weight: 30) - navigation patterns
- Timing detector (weight: 25) - request synchronization
- Network detector (weight: 15) - subnet correlation
§Arguments
ip- The IP address of the clientmethod- HTTP method (GET, POST, etc.)path- Request path
Sourcepub fn record_request_full(
&self,
ip: IpAddr,
method: &str,
path: &str,
ja4: Option<&str>,
jwt: Option<&str>,
)
pub fn record_request_full( &self, ip: IpAddr, method: &str, path: &str, ja4: Option<&str>, jwt: Option<&str>, )
Record a request with full context for all applicable detectors.
Convenience method that records data to multiple detectors at once. Call this during request processing to capture all correlation signals.
§Arguments
ip- The IP address of the clientmethod- HTTP methodpath- Request pathja4- Optional JA4 TLS fingerprintjwt- Optional JWT from Authorization header
Sourcepub fn record_relation(&self, entity_a: &str, entity_b: &str)
pub fn record_relation(&self, entity_a: &str, entity_b: &str)
Record a relationship for graph correlation.
Records a connection between two entities (e.g., IP and Fingerprint) to build the correlation graph.
§Arguments
entity_a- First entity ID (e.g., “ip:1.2.3.4”)entity_b- Second entity ID (e.g., “fp:abc12345”)
Sourcepub fn calculate_campaign_score(&self, campaign: &Campaign) -> f64
pub fn calculate_campaign_score(&self, campaign: &Campaign) -> f64
Calculate weighted campaign score from all correlation reasons.
The score is computed as the weighted average of all correlation
reasons, where each reason’s contribution is:
weight * confidence / total_reasons
§Arguments
campaign- The campaign to score
§Returns
A score between 0.0 and 50.0 (max weight * max confidence)
Sourcepub async fn run_detection_cycle(&self) -> DetectorResult<usize>
pub async fn run_detection_cycle(&self) -> DetectorResult<usize>
Run all 7 detectors in parallel and process updates with weighted scoring.
Called periodically by background worker or on-demand. Detectors run concurrently for improved performance (~70ms savings at scale):
- Attack Sequence (50) - Same attack payloads
- Auth Token (45) - Same JWT structure/issuer
- HTTP Fingerprint (40) - Identical JA4H
- TLS Fingerprint (35) - Same JA4
- Behavioral Similarity (30) - Navigation patterns
- Timing Correlation (25) - Synchronized requests
- Network Proximity (15) - Same ASN/subnet
§Returns
Number of campaign updates processed.
§Errors
Returns an error if any detector fails critically.
Sourcepub async fn get_cached_groups(&self, threshold: usize) -> Vec<FingerprintGroup>
pub async fn get_cached_groups(&self, threshold: usize) -> Vec<FingerprintGroup>
Get fingerprint groups above threshold with caching.
This method caches the results of get_groups_above_threshold() for 100ms
to avoid repeated expensive O(n) scans during a single detection cycle.
Multiple detectors can use the same cached result within the TTL window.
§Arguments
threshold- Minimum number of IPs required for a group
§Returns
Vector of fingerprint groups above the threshold.
Sourcepub async fn invalidate_group_cache(&self)
pub async fn invalidate_group_cache(&self)
Invalidate the fingerprint groups cache.
Called when significant changes occur that would affect group composition.
Sourcepub fn should_trigger_detection(&self, ip: &IpAddr) -> bool
pub fn should_trigger_detection(&self, ip: &IpAddr) -> bool
Sourcepub fn get_campaigns(&self) -> Vec<Campaign>
pub fn get_campaigns(&self) -> Vec<Campaign>
Get all active campaigns for API response.
Returns campaigns with Detected or Active status.
Sourcepub fn get_all_campaigns(&self) -> Vec<Campaign>
pub fn get_all_campaigns(&self) -> Vec<Campaign>
Get all campaigns (including resolved/dormant).
Sourcepub fn snapshot(&self) -> Vec<Campaign>
pub fn snapshot(&self) -> Vec<Campaign>
Create a snapshot of all campaigns for persistence.
Returns all campaigns regardless of status.
Sourcepub fn restore(&self, campaigns: Vec<Campaign>)
pub fn restore(&self, campaigns: Vec<Campaign>)
Restore campaigns from a snapshot.
Clears existing state and loads the provided campaigns.
Sourcepub fn get_campaign(&self, id: &str) -> Option<Campaign>
pub fn get_campaign(&self, id: &str) -> Option<Campaign>
Sourcepub fn get_campaign_actors(&self, campaign_id: &str) -> Vec<IpAddr>
pub fn get_campaign_actors(&self, campaign_id: &str) -> Vec<IpAddr>
Sourcepub fn get_campaign_graph(&self, campaign_id: &str) -> Value
pub fn get_campaign_graph(&self, campaign_id: &str) -> Value
Get the correlation graph for a campaign.
Sourcepub fn get_campaign_graph_paginated(
&self,
campaign_id: &str,
limit: Option<usize>,
offset: Option<usize>,
hash_identifiers: bool,
) -> PaginatedGraph
pub fn get_campaign_graph_paginated( &self, campaign_id: &str, limit: Option<usize>, offset: Option<usize>, hash_identifiers: bool, ) -> PaginatedGraph
Get the correlation graph for a campaign with pagination and identifier hashing. P1 fix: Supports pagination to prevent memory exhaustion and hashes identifiers to prevent information disclosure.
Sourcepub fn stats(&self) -> ManagerStats
pub fn stats(&self) -> ManagerStats
Get current statistics.
Returns a snapshot of manager statistics including index and store stats.
Sourcepub fn start_background_worker(self: Arc<Self>) -> JoinHandle<()>
pub fn start_background_worker(self: Arc<Self>) -> JoinHandle<()>
Start background detection worker.
Returns a handle that can be used to await worker completion. The worker runs detection cycles at the configured interval until the manager is dropped or shutdown is signaled.
§Returns
JoinHandle for the background task.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Check if shutdown has been signaled.
Sourcepub fn remove_ip(&self, ip: &IpAddr)
pub fn remove_ip(&self, ip: &IpAddr)
Remove an IP from tracking (called when entity is evicted).
Cleans up the IP from:
- Fingerprint index
- Any associated campaigns
§Arguments
ip- The IP address to remove
Sourcepub fn index(&self) -> &Arc<FingerprintIndex>
pub fn index(&self) -> &Arc<FingerprintIndex>
Get the fingerprint index (for integration with EntityManager).
Allows direct access to the index for advanced use cases.
Sourcepub fn store(&self) -> &Arc<CampaignStore>
pub fn store(&self) -> &Arc<CampaignStore>
Get the campaign store (for integration).
Allows direct access to the store for advanced use cases.
Sourcepub fn config(&self) -> &ManagerConfig
pub fn config(&self) -> &ManagerConfig
Get the current configuration.
Sourcepub fn resolve_campaign(
&self,
campaign_id: &str,
reason: &str,
) -> Result<(), DetectorError>
pub fn resolve_campaign( &self, campaign_id: &str, reason: &str, ) -> Result<(), DetectorError>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CampaignManager
impl !RefUnwindSafe for CampaignManager
impl Send for CampaignManager
impl Sync for CampaignManager
impl Unpin for CampaignManager
impl UnsafeUnpin for CampaignManager
impl !UnwindSafe for CampaignManager
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