limiteron 0.3.0-rc.7

Unified flow control framework for Rust
Documentation
// Copyright (c) 2026 Kirky.X🌠
// SPDX-License-Identifier: MIT
//! 事件系统模块
//!
//! 提供事件发布/订阅系统,支持事件发射、分发和 Webhook 推送。
//!
//! # 功能
//!
//! - 事件发射器 (EventEmitter): 使用 tokio broadcast channel 实现事件发布
//! - 事件分发器 (EventDispatcher): 监听事件并分发给处理器和 Webhook
//! - 事件类型 (EventType): 预定义的系统事件类型
//! - 事件处理器 (EventHandler): 可扩展的事件处理接口
//!
//! # 示例
//!
//! ```rust
//! use limiteron::{EventEmitter, EventDispatcher, Event, EventType};
//!
//! #[tokio::main]
//! async fn main() {
//!     // 创建事件发射器
//!     let emitter = EventEmitter::with_default_config();
//!
//!     // 创建分发器并启动
//!     let dispatcher = EventDispatcher::new(emitter.clone());
//!     dispatcher.start().await;
//!
//!     // 发射事件
//!     let event = Event::new(EventType::RateLimitTriggered {
//!         key: "192.168.1.1".to_string(),
//!         rule_id: "rule_1".to_string(),
//!         decision: "Deny".to_string(),
//!     });
//!     emitter.emit(event).await.unwrap();
//!
//!     // 停止分发器
//!     dispatcher.stop().await;
//! }
//! ```
//!
//! # 事件类型
//!
//! | 事件类型 | 描述 | 严重级别 |
//! |---------|------|---------|
//! | `RateLimitTriggered` | 限流触发 | 2-6 |
//! | `BanApplied` | 封禁应用 | 8 |
//! | `BanExpired` | 封禁过期 | 1 |
//! | `CircuitStateChanged` | 熔断器状态变更 | 1-9 |
//! | `QuotaAlert` | 配额告警 | 3-7 |

// 子模块
mod dispatcher;
mod emitter;
mod types;

// 事件 Outbox:封禁/配额事件 outbox 表化(需 DB 后端 feature)
#[cfg(all(
    feature = "event-system",
    any(feature = "postgres", feature = "sqlite", feature = "mysql")
))]
pub(crate) mod outbox;

// 封禁跨实例同步:经 oxcache Pub/Sub 广播封禁变更
#[cfg(all(feature = "event-system", feature = "ban-sync"))]
pub(crate) mod ban_sync;

// Webhook 外发签名:HMAC-SHA256 签名头 + 时间戳防重放。
// 公开导出经 lib.rs 根(本模块为私有 mod)。
#[cfg(feature = "webhook")]
pub(crate) mod webhook_signature;

// Re-export all public types
pub use dispatcher::EventDispatcher;
pub use emitter::EventEmitter;
pub use types::{Event, EventConfig, EventHandler, EventType};

#[cfg(all(
    feature = "event-system",
    any(feature = "postgres", feature = "sqlite", feature = "mysql")
))]
pub use outbox::{EventOutboxStore, OutboxDialect, OutboxEntry, OutboxEventKind};

#[cfg(all(feature = "event-system", feature = "ban-sync"))]
pub use ban_sync::{
    BanSyncApplier, BanSyncBus, BanSyncConfig, BanSyncKind, BanSyncListenerHandle, BanSyncMessage,
    DEFAULT_BAN_SYNC_CHANNEL,
};