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