11use std:: { net:: IpAddr , path:: PathBuf } ;
22
33use crate :: config:: settings:: {
4- LandscapeConfig , LandscapeDnsConfig , LandscapeMetricConfig , LandscapeUIConfig ,
4+ LandscapeConfig , LandscapeDnsConfig , LandscapeMetricConfig , LandscapeTimeConfig ,
5+ LandscapeUIConfig ,
56} ;
67use crate :: gateway:: settings:: GatewayRuntimeConfig ;
7- use crate :: LANDSCAPE_DB_SQLITE_NAME ;
8+ use crate :: {
9+ DEFAULT_TIME_ENABLE , DEFAULT_TIME_SAMPLES_PER_SERVER , DEFAULT_TIME_SERVERS ,
10+ DEFAULT_TIME_STEP_THRESHOLD_MS , DEFAULT_TIME_SYNC_INTERVAL_SECS , DEFAULT_TIME_TIMEOUT_SECS ,
11+ LANDSCAPE_DB_SQLITE_NAME ,
12+ } ;
813
914#[ derive( Clone , Debug ) ]
1015pub struct RuntimeConfig {
@@ -17,6 +22,7 @@ pub struct RuntimeConfig {
1722 pub metric : MetricRuntimeConfig ,
1823 pub dns : DnsRuntimeConfig ,
1924 pub ui : LandscapeUIConfig ,
25+ pub time : TimeRuntimeConfig ,
2026 pub gateway : GatewayRuntimeConfig ,
2127 pub auto : bool ,
2228}
@@ -75,6 +81,29 @@ pub struct DnsRuntimeConfig {
7581 pub doh_http_endpoint : String ,
7682}
7783
84+ #[ derive( Clone , Debug ) ]
85+ pub struct TimeRuntimeConfig {
86+ pub enabled : bool ,
87+ pub servers : Vec < String > ,
88+ pub sync_interval_secs : u64 ,
89+ pub timeout_secs : u64 ,
90+ pub step_threshold_ms : u64 ,
91+ pub samples_per_server : u8 ,
92+ }
93+
94+ impl Default for TimeRuntimeConfig {
95+ fn default ( ) -> Self {
96+ Self {
97+ enabled : DEFAULT_TIME_ENABLE ,
98+ servers : DEFAULT_TIME_SERVERS . iter ( ) . map ( |server| ( * server) . to_string ( ) ) . collect ( ) ,
99+ sync_interval_secs : DEFAULT_TIME_SYNC_INTERVAL_SECS ,
100+ timeout_secs : DEFAULT_TIME_TIMEOUT_SECS ,
101+ step_threshold_ms : DEFAULT_TIME_STEP_THRESHOLD_MS ,
102+ samples_per_server : DEFAULT_TIME_SAMPLES_PER_SERVER ,
103+ }
104+ }
105+ }
106+
78107impl RuntimeConfig {
79108 pub fn to_string_summary ( & self ) -> String {
80109 let address_http_str = match self . web . address {
@@ -120,8 +149,16 @@ impl RuntimeConfig {
120149 DB Max Threads: {}\n \
121150 Cleanup Interval: {}s\n \
122151 Cleanup Budget: {}ms\n \
123- Cleanup Slice Window: {}s\n \
124- Aggregate Interval: {}s\n ",
152+ Cleanup Slice Window: {}s\n \
153+ Aggregate Interval: {}s\n \
154+ \n \
155+ [Time]\n \
156+ Enabled: {}\n \
157+ NTP Servers: {}\n \
158+ Sync Interval: {}s\n \
159+ Timeout: {}s\n \
160+ Step Threshold: {}ms\n \
161+ Samples Per Server: {}\n ",
125162 self . home_path. display( ) ,
126163 self . auth. admin_user,
127164 self . auth. admin_pass,
@@ -147,6 +184,12 @@ impl RuntimeConfig {
147184 self . metric. cleanup_time_budget_ms,
148185 self . metric. cleanup_slice_window_secs,
149186 self . metric. aggregate_interval_secs,
187+ self . time. enabled,
188+ self . time. servers. join( ", " ) ,
189+ self . time. sync_interval_secs,
190+ self . time. timeout_secs,
191+ self . time. step_threshold_ms,
192+ self . time. samples_per_server,
150193 )
151194 }
152195}
@@ -218,6 +261,29 @@ impl DnsRuntimeConfig {
218261 }
219262}
220263
264+ impl TimeRuntimeConfig {
265+ pub fn update_from_file_config ( & mut self , config : & LandscapeTimeConfig ) {
266+ if let Some ( v) = config. enabled {
267+ self . enabled = v;
268+ }
269+ if let Some ( v) = & config. servers {
270+ self . servers = v. clone ( ) ;
271+ }
272+ if let Some ( v) = config. sync_interval_secs {
273+ self . sync_interval_secs = v;
274+ }
275+ if let Some ( v) = config. timeout_secs {
276+ self . timeout_secs = v;
277+ }
278+ if let Some ( v) = config. step_threshold_ms {
279+ self . step_threshold_ms = v;
280+ }
281+ if let Some ( v) = config. samples_per_server {
282+ self . samples_per_server = v;
283+ }
284+ }
285+ }
286+
221287impl StoreRuntimeConfig {
222288 pub fn create_default_db_store ( home_path : & PathBuf ) -> String {
223289 let path = home_path. join ( LANDSCAPE_DB_SQLITE_NAME ) ;
0 commit comments