Skip to main content

xds_server/
config.rs

1//! Server configuration.
2
3use std::time::Duration;
4
5/// Configuration for the xDS server.
6#[derive(Debug, Clone)]
7pub struct ServerConfig {
8    /// Enable State-of-the-World protocol.
9    pub enable_sotw: bool,
10    /// Enable Delta xDS protocol.
11    pub enable_delta: bool,
12    /// Maximum concurrent streams per connection.
13    pub max_concurrent_streams: Option<u32>,
14    /// Keepalive interval.
15    pub keepalive_interval: Option<Duration>,
16    /// Keepalive timeout.
17    pub keepalive_timeout: Option<Duration>,
18    /// Maximum request size in bytes.
19    pub max_request_size: usize,
20    /// Response compression.
21    pub compression: CompressionConfig,
22    /// Grace period for shutdown.
23    pub grace_period: Duration,
24    /// Enable health checking.
25    pub enable_health: bool,
26    /// Enable metrics.
27    pub enable_metrics: bool,
28    /// Enable connection tracking.
29    pub enable_connection_tracking: bool,
30}
31
32impl Default for ServerConfig {
33    fn default() -> Self {
34        Self {
35            enable_sotw: true,
36            enable_delta: false,
37            max_concurrent_streams: Some(100),
38            keepalive_interval: Some(Duration::from_secs(30)),
39            keepalive_timeout: Some(Duration::from_secs(10)),
40            max_request_size: 4 * 1024 * 1024, // 4MB
41            compression: CompressionConfig::default(),
42            grace_period: Duration::from_secs(30),
43            enable_health: true,
44            enable_metrics: true,
45            enable_connection_tracking: true,
46        }
47    }
48}
49
50/// Compression configuration.
51#[derive(Debug, Clone, Default)]
52pub struct CompressionConfig {
53    /// Enable gzip compression for responses.
54    pub gzip: bool,
55    /// Minimum response size to compress (bytes).
56    pub min_size: usize,
57}
58
59impl CompressionConfig {
60    /// Create with gzip enabled.
61    pub fn gzip() -> Self {
62        Self {
63            gzip: true,
64            min_size: 1024,
65        }
66    }
67}