Skip to main content

mobius_gateway/config/
runtime.rs

1//! Host-independent lifecycle settings selected by the gateway operator.
2
3use crate::{Error, Result};
4
5mobius::embedded_config! {
6    copy;
7/// Lifecycle and optional private ingress for one gateway.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub struct RuntimeConfig {
10    /// Exit after this many idle seconds. Zero disables idle shutdown.
11    pub idle_exit_seconds: u64,
12    /// Informational content allowance; its configured collector decides admission.
13    pub storage_limit_bytes: Option<u64>,
14    /// Additional Noise-only WebSocket listener.
15    pub ingress: Option<std::net::SocketAddr>,
16    /// Refuse startup without `MOBIUS_GATEWAY_ACCESS_EXPIRES_AT`.
17    pub require_access_lease: bool,
18    /// Explicit grace added to an operator-supplied access expiry.
19    pub access_grace_seconds: u64,
20}
21    defaults = include_str!("runtime.toml");
22}
23
24impl RuntimeConfig {
25    pub(super) fn validate(&self) -> Result<()> {
26        super::bounded(
27            "runtime.idle_exit_seconds",
28            self.idle_exit_seconds,
29            0..=31_536_000,
30        )?;
31        super::bounded(
32            "runtime.access_grace_seconds",
33            self.access_grace_seconds,
34            0..=86_400,
35        )?;
36        if self
37            .storage_limit_bytes
38            .is_some_and(|limit| limit < 64 * 1024 * 1024)
39        {
40            return Err(Error::Config(
41                "storage_limit_bytes must be at least 64 MiB".into(),
42            ));
43        }
44        Ok(())
45    }
46}