Initial commit: split VNOX monorepo into VNOX-Server

Unified server binary (vnox-serverd) combining:
- Gateway (TCP, auth, channels, sessions, SQLite)
- Voice-node (UDP relay, Opus, jitter buffer)

Standalone gateway (vnox-gateway) and voice-node (vnox-voice-node) preserved as sub-crates.
This commit is contained in:
loki5512344 2026-07-09 11:52:56 +02:00
commit e751e0bf5b
94 changed files with 9771 additions and 0 deletions

73
gateway/src/net/state.rs Normal file
View file

@ -0,0 +1,73 @@
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::atomic::AtomicUsize;
use tokio::sync::{RwLock, broadcast};
use crate::admin::metrics::Metrics;
use crate::bootstrap::server_identity::ServerIdentity;
use crate::domain::rate_limit::RateLimiter;
use crate::domain::{
channels::ChannelStore, config::Config, session::SessionStore, storage::Storage,
};
use crate::proto::PresenceInfo;
#[derive(Clone)]
pub struct State {
pub sessions: SessionStore,
pub channels: ChannelStore,
pub storage: Arc<Storage>,
pub config: Arc<Config>,
pub server_identity: Arc<ServerIdentity>,
pub broadcast: broadcast::Sender<BroadcastMsg>,
/// user_id → presence info (Phase 1.2)
pub presences: Arc<RwLock<HashMap<String, PresenceInfo>>>,
/// Prometheus-style counters.
pub metrics: Arc<Metrics>,
/// Live count of authenticated sessions.
pub sessions_count: Arc<AtomicUsize>,
/// Live count of channels with at least one member.
#[allow(dead_code)]
pub channels_count: Arc<AtomicUsize>,
/// Per-session rate limiter (token bucket).
pub rate_limiter: Arc<RateLimiter>,
}
impl State {
#[allow(clippy::too_many_arguments)]
pub fn new(
sessions: SessionStore,
channels: ChannelStore,
storage: Arc<Storage>,
config: Arc<Config>,
server_identity: Arc<ServerIdentity>,
broadcast: broadcast::Sender<BroadcastMsg>,
metrics: Arc<Metrics>,
sessions_count: Arc<AtomicUsize>,
channels_count: Arc<AtomicUsize>,
) -> Self {
let rate_per_sec = config.gateway.message_rate_per_sec.unwrap_or(5.0);
let burst = config.gateway.message_rate_burst.unwrap_or(10);
let rate_limiter = Arc::new(RateLimiter::new(rate_per_sec, burst));
Self {
sessions,
channels,
storage,
config,
server_identity,
broadcast,
presences: Arc::new(RwLock::new(HashMap::new())),
metrics,
sessions_count,
channels_count,
rate_limiter,
}
}
}
#[derive(Clone, Debug)]
pub struct BroadcastMsg {
pub channel_id: Option<String>,
pub exclude_session: Option<String>,
pub target_session_id: Option<String>,
pub data: Vec<u8>,
}