mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-12-17 09:47:53 +00:00
init rust. WIP: tls for inbounds
This commit is contained in:
30
src/services/events.rs
Normal file
30
src/services/events.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use std::sync::OnceLock;
|
||||
use tokio::sync::broadcast;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum SyncEvent {
|
||||
InboundChanged(Uuid), // server_id
|
||||
UserAccessChanged(Uuid), // server_id
|
||||
}
|
||||
|
||||
static EVENT_SENDER: OnceLock<broadcast::Sender<SyncEvent>> = OnceLock::new();
|
||||
|
||||
/// Initialize the event bus and return a receiver
|
||||
pub fn init_event_bus() -> broadcast::Receiver<SyncEvent> {
|
||||
let (tx, rx) = broadcast::channel(100);
|
||||
EVENT_SENDER.set(tx).expect("Event bus already initialized");
|
||||
rx
|
||||
}
|
||||
|
||||
/// Send a sync event (non-blocking)
|
||||
pub fn send_sync_event(event: SyncEvent) {
|
||||
if let Some(sender) = EVENT_SENDER.get() {
|
||||
match sender.send(event.clone()) {
|
||||
Ok(_) => tracing::info!("Event sent: {:?}", event),
|
||||
Err(_) => tracing::warn!("No event receivers"),
|
||||
}
|
||||
} else {
|
||||
tracing::error!("Event bus not initialized");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user