switchgear_server/
config.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashSet;
3use std::net::SocketAddr;
4use std::path::PathBuf;
5
6#[derive(Clone, Debug, Serialize, Deserialize)]
7#[serde(rename_all = "kebab-case")]
8pub struct ServerConfig {
9    pub lnurl_service: Option<LnUrlBalancerServiceConfig>,
10    pub discovery_service: Option<DiscoveryServiceConfig>,
11    pub offer_service: Option<OfferServiceConfig>,
12    pub store: Option<ServerStoreConfig>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "kebab-case")]
17pub struct LnUrlBalancerServiceConfig {
18    pub partitions: HashSet<String>,
19    pub address: SocketAddr,
20    pub health_check_frequency_secs: f64,
21    pub parallel_health_check: bool,
22    pub health_check_consecutive_success_to_healthy: usize,
23    pub health_check_consecutive_failure_to_unhealthy: usize,
24    pub backend_update_frequency_secs: f64,
25    pub invoice_expiry_secs: u64,
26    pub allowed_hosts: HashSet<String>,
27    pub backoff: BackoffConfig,
28    pub backend_selection: BackendSelectionConfig,
29    pub tls: Option<TlsConfig>,
30    pub ln_client_timeout_secs: f64,
31    pub selection_capacity_bias: Option<f64>,
32    pub comment_allowed: Option<u32>,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(rename_all = "kebab-case")]
37pub struct DiscoveryServiceConfig {
38    pub address: SocketAddr,
39    pub auth_authority: PathBuf,
40    pub tls: Option<TlsConfig>,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(rename_all = "kebab-case")]
45pub struct OfferServiceConfig {
46    pub address: SocketAddr,
47    pub auth_authority: PathBuf,
48    pub tls: Option<TlsConfig>,
49    pub max_page_size: usize,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(tag = "type", rename_all = "kebab-case")]
54pub enum BackoffConfig {
55    Stop,
56    #[serde(rename_all = "kebab-case")]
57    Exponential {
58        initial_interval_secs: Option<f64>,
59        randomization_factor: Option<f64>,
60        multiplier: Option<f64>,
61        max_interval_secs: Option<f64>,
62        max_elapsed_time_secs: Option<f64>,
63    },
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(rename_all = "kebab-case")]
68pub enum BackendSelectionConfig {
69    RoundRobin,
70    Random,
71    Consistent { max_iterations: usize },
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(rename_all = "kebab-case")]
76pub struct ServerStoreConfig {
77    pub offer: Option<OfferStoreConfig>,
78    pub discover: Option<DiscoveryStoreConfig>,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(tag = "type", rename_all = "kebab-case")]
83pub enum OfferStoreConfig {
84    #[serde(rename_all = "kebab-case")]
85    Database {
86        database_url: String,
87        max_connections: u32,
88    },
89    Memory,
90    #[serde(rename_all = "kebab-case")]
91    Http {
92        base_url: String,
93        connect_timeout_secs: f64,
94        total_timeout_secs: f64,
95        trusted_roots: Vec<PathBuf>,
96        authorization: PathBuf,
97    },
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(tag = "type", rename_all = "kebab-case")]
102pub enum DiscoveryStoreConfig {
103    #[serde(rename_all = "kebab-case")]
104    Database {
105        database_url: String,
106        max_connections: u32,
107    },
108    Memory,
109    #[serde(rename_all = "kebab-case")]
110    Http {
111        base_url: String,
112        connect_timeout_secs: f64,
113        total_timeout_secs: f64,
114        trusted_roots: Vec<PathBuf>,
115        authorization: PathBuf,
116    },
117}
118
119#[derive(Clone, Debug, Serialize, Deserialize)]
120#[serde(rename_all = "kebab-case")]
121pub struct TlsConfig {
122    pub cert_path: PathBuf,
123    pub key_path: PathBuf,
124}