xaeroflux_core/config.rs
1//! Application configuration definitions for xaeroflux-actors.
2//!
3//! This module defines the configuration structures for:
4//! - Global `Config`
5//! - Append-only file settings (`AofConfig`)
6//! - Storage engine parameters (`StorageConfig`)
7//! - Merkle index tuning (`MerkleConfig`)
8//! - Peer-to-peer networking (`P2PConfig` and `DiscoveryConfig`)
9//! - Buffering strategies (`BufferConfig`)
10//! - Thread pool sizing (`ThreadConfig`)
11//! - Logging preferences (`LoggingConfig`)
12
13use std::{collections::HashMap, path::PathBuf};
14
15use serde::Deserialize;
16
17/// Top-level application configuration.
18///
19/// Aggregates all sub-configuration for various components:
20/// general metadata, AOF, storage, Merkle, P2P, buffers, threading, and logging.
21#[derive(Deserialize, Debug, Default)]
22pub struct Config {
23 pub name: String,
24 pub version: u64,
25 pub description: String,
26 pub aof: AofConfig,
27 pub storage: StorageConfig,
28 pub merkle: MerkleConfig,
29 pub p2p: P2PConfig,
30 pub event_buffers: HashMap<String, BufferConfig>,
31 pub threads: ThreadConfig,
32 pub logging: LoggingConfig,
33}
34
35/// Configuration for the append-only file (AOF) subsystem.
36///
37/// Controls file paths, flush intervals, size limits, compression, retention,
38/// threading, and buffer sizing for durable event storage.
39#[derive(Deserialize, Debug, Default)]
40pub struct AofConfig {
41 pub enabled: bool,
42 pub file_path: PathBuf,
43 pub flush_interval_ms: u64,
44 pub max_size_bytes: usize,
45 pub compression: String,
46 pub retention_policy: String,
47 pub threads: ThreadConfig,
48 pub buffer_size: usize,
49}
50
51/// Settings for the storage engine directories and file handle limits.
52///
53/// Includes data, write-ahead log, and Merkle index directories,
54/// and options for creation and open file limits.
55#[derive(Deserialize, Debug, Default)]
56pub struct StorageConfig {
57 pub data_dir: PathBuf,
58 pub wal_dir: PathBuf,
59 pub merkle_index_dir: PathBuf,
60 pub create_if_missing: bool,
61 pub max_open_files: u32,
62}
63
64/// Tuning parameters for the Merkle mountain range index.
65///
66/// Defines page size, flush periodicity, and maximum nodes per page.
67#[derive(Deserialize, Debug, Default)]
68pub struct MerkleConfig {
69 pub page_size: usize,
70 pub flush_interval_ms: u64,
71 pub max_nodes_per_page: usize,
72}
73
74/// Peer-to-peer networking configuration.
75///
76/// Specifies listen address, bootstrap nodes, mDNS usage,
77/// CRDT synchronization strategy, message size limits, and discovery options.
78#[derive(Deserialize, Debug, Default)]
79pub struct P2PConfig {
80 pub listen_address: String,
81 pub bootstrap_nodes: Vec<String>,
82 pub enable_mdns: bool,
83 pub crdt_strategy: String,
84 pub max_msg_size_bytes: usize,
85 pub discovery_config: DiscoveryConfig,
86}
87/// Settings for peer discovery mechanisms.
88///
89/// Toggles for WiFi (mDNS), Bluetooth, and geolocation-based discovery.
90#[derive(Deserialize, Debug, Default)]
91pub struct DiscoveryConfig {
92 pub wifi: bool,
93 pub bluetooth: bool,
94 pub geolocate: bool,
95}
96
97/// Configuration for event buffer behavior.
98///
99/// Includes capacity, batch size, and timeout for buffered operations.
100#[derive(Deserialize, Debug, Default)]
101pub struct BufferConfig {
102 pub capacity: usize,
103 pub batch_size: usize,
104 pub timeout_ms: u64,
105}
106
107/// Thread pool sizing and queue limits.
108///
109/// Controls number of worker and I/O threads, max queue size, and thread pinning.
110#[derive(Deserialize, Debug, Default)]
111pub struct ThreadConfig {
112 pub num_worker_threads: usize,
113 pub num_io_threads: usize,
114 pub max_queue_size: usize,
115 pub pin_threads: bool,
116}
117
118/// Logging preferences including verbosity level and output file path.
119#[derive(Deserialize, Debug, Default)]
120pub struct LoggingConfig {
121 pub level: String,
122 pub file: PathBuf,
123}