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