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 pub bech32_qr_scale: usize,
34 pub bech32_qr_light: u8,
35 pub bech32_qr_dark: u8,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(rename_all = "kebab-case")]
40pub struct DiscoveryServiceConfig {
41 pub address: SocketAddr,
42 pub auth_authority: PathBuf,
43 pub tls: Option<TlsConfig>,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(rename_all = "kebab-case")]
48pub struct OfferServiceConfig {
49 pub address: SocketAddr,
50 pub auth_authority: PathBuf,
51 pub tls: Option<TlsConfig>,
52 pub max_page_size: usize,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(tag = "type", rename_all = "kebab-case")]
57pub enum BackoffConfig {
58 Stop,
59 #[serde(rename_all = "kebab-case")]
60 Exponential {
61 initial_interval_secs: Option<f64>,
62 randomization_factor: Option<f64>,
63 multiplier: Option<f64>,
64 max_interval_secs: Option<f64>,
65 max_elapsed_time_secs: Option<f64>,
66 },
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(rename_all = "kebab-case")]
71pub enum BackendSelectionConfig {
72 RoundRobin,
73 Random,
74 Consistent { max_iterations: usize },
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(rename_all = "kebab-case")]
79pub struct ServerStoreConfig {
80 pub offer: Option<OfferStoreConfig>,
81 pub discover: Option<DiscoveryStoreConfig>,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(tag = "type", rename_all = "kebab-case")]
86pub enum OfferStoreConfig {
87 #[serde(rename_all = "kebab-case")]
88 Database {
89 database_url: String,
90 max_connections: u32,
91 },
92 Memory,
93 #[serde(rename_all = "kebab-case")]
94 Http {
95 base_url: String,
96 connect_timeout_secs: f64,
97 total_timeout_secs: f64,
98 trusted_roots: Vec<PathBuf>,
99 authorization: PathBuf,
100 },
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(tag = "type", rename_all = "kebab-case")]
105pub enum DiscoveryStoreConfig {
106 #[serde(rename_all = "kebab-case")]
107 Database {
108 database_url: String,
109 max_connections: u32,
110 },
111 Memory,
112 #[serde(rename_all = "kebab-case")]
113 Http {
114 base_url: String,
115 connect_timeout_secs: f64,
116 total_timeout_secs: f64,
117 trusted_roots: Vec<PathBuf>,
118 authorization: PathBuf,
119 },
120}
121
122#[derive(Clone, Debug, Serialize, Deserialize)]
123#[serde(rename_all = "kebab-case")]
124pub struct TlsConfig {
125 pub cert_path: PathBuf,
126 pub key_path: PathBuf,
127}