Module policy

Module policy 

Source
Expand description

Network Policy Engine - Fine-grained control over network operations

This module provides a policy engine for enforcing various network policies:

  • Connection policies (whitelist/blacklist, rate limits)
  • Bandwidth policies (per-peer, per-protocol limits)
  • Content policies (allowed CIDs, content types)
  • Time-based policies (schedules, quotas)
  • Geographic policies (region restrictions)

Useful for production deployments requiring fine-grained control.

§Example

use ipfrs_network::{PolicyEngine, PolicyConfig, ConnectionPolicy, PolicyAction};

let config = PolicyConfig::default();
let engine = PolicyEngine::new(config);

// Add a connection policy
let policy = ConnectionPolicy::new("block-untrusted")
    .with_action(PolicyAction::Deny)
    .with_priority(100);

engine.add_connection_policy(policy)?;

// Evaluate connection
let allowed = engine.evaluate_connection("peer123").await?;
println!("Connection allowed: {}", allowed);

Structs§

BandwidthPolicy
Bandwidth policy for controlling data transfer
ConnectionPolicy
Connection policy for controlling peer connections
ContentPolicy
Content policy for controlling what content is allowed
PolicyConfig
Configuration for the policy engine
PolicyEngine
Policy engine for enforcing network policies
PolicyResult
Policy evaluation result
PolicyStats
Statistics tracked by the policy engine

Enums§

PolicyAction
Action to take when a policy matches
PolicyError
Errors that can occur in the policy engine