Skip to main content

shadow_core/
config.rs

1use serde::{Deserialize, Serialize};
2use std::net::SocketAddr;
3use std::time::Duration;
4
5use crate::transport::CoverProtocol;
6
7/// Network configuration for the shadow network
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct NetworkConfig {
10    /// Local listening address
11    pub listen_addr: SocketAddr,
12    
13    /// Bootstrap nodes for initial network discovery
14    pub bootstrap_nodes: Vec<String>,
15    
16    /// Cover protocol to use
17    pub cover_protocol: CoverProtocol,
18    
19    /// Maximum number of peer connections
20    pub max_peers: usize,
21    
22    /// Connection timeout
23    pub connection_timeout: Duration,
24    
25    /// Enable NAT traversal
26    pub enable_nat_traversal: bool,
27    
28    /// STUN server addresses
29    pub stun_servers: Vec<String>,
30    
31    /// TURN server addresses (with credentials)
32    pub turn_servers: Vec<TurnServerConfig>,
33    
34    /// DHT configuration
35    pub dht: DhtConfig,
36    
37    /// Storage configuration
38    pub storage: StorageConfig,
39    
40    /// Steganography configuration
41    pub stego: StegoConfig,
42}
43
44impl Default for NetworkConfig {
45    fn default() -> Self {
46        Self {
47            listen_addr: "0.0.0.0:0".parse().unwrap(),
48            bootstrap_nodes: vec![],
49            cover_protocol: CoverProtocol::WebRTC,
50            max_peers: 50,
51            connection_timeout: Duration::from_secs(30),
52            enable_nat_traversal: true,
53            stun_servers: vec![
54                "stun:stun.l.google.com:19302".to_string(),
55                "stun:stun1.l.google.com:19302".to_string(),
56            ],
57            turn_servers: vec![],
58            dht: DhtConfig::default(),
59            storage: StorageConfig::default(),
60            stego: StegoConfig::default(),
61        }
62    }
63}
64
65/// TURN server configuration
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct TurnServerConfig {
68    pub url: String,
69    pub username: String,
70    pub password: String,
71}
72
73/// DHT configuration
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct DhtConfig {
76    /// Number of nodes per k-bucket
77    pub k_value: usize,
78    
79    /// Number of parallel lookups (alpha)
80    pub alpha: usize,
81    
82    /// Replication parameter
83    pub replication_factor: usize,
84    
85    /// Republish interval
86    pub republish_interval: Duration,
87    
88    /// Node expiration time
89    pub node_expiration: Duration,
90    
91    /// Enable delayed lookups (for stealth)
92    pub enable_delayed_lookups: bool,
93    
94    /// Lookup delay range (min, max) in milliseconds
95    pub lookup_delay_range: (u64, u64),
96}
97
98impl Default for DhtConfig {
99    fn default() -> Self {
100        Self {
101            k_value: 20,
102            alpha: 3,
103            replication_factor: 3,
104            republish_interval: Duration::from_secs(3600),
105            node_expiration: Duration::from_secs(86400),
106            enable_delayed_lookups: true,
107            lookup_delay_range: (100, 5000),
108        }
109    }
110}
111
112/// Storage configuration
113#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct StorageConfig {
115    /// Enable distributed storage
116    pub enabled: bool,
117    
118    /// Maximum storage size in bytes
119    pub max_storage_size: u64,
120    
121    /// Enable erasure coding
122    pub enable_erasure_coding: bool,
123    
124    /// Erasure coding parameters (data shards, parity shards)
125    pub erasure_params: (usize, usize),
126    
127    /// Enable passive replication (caching)
128    pub enable_passive_replication: bool,
129    
130    /// Cache size in bytes
131    pub cache_size: u64,
132    
133    /// Cache eviction policy
134    pub cache_policy: CachePolicy,
135}
136
137impl Default for StorageConfig {
138    fn default() -> Self {
139        Self {
140            enabled: true,
141            max_storage_size: 10 * 1024 * 1024 * 1024, // 10 GB
142            enable_erasure_coding: true,
143            erasure_params: (10, 5), // 10 data shards, 5 parity shards
144            enable_passive_replication: true,
145            cache_size: 100 * 1024 * 1024, // 100 MB
146            cache_policy: CachePolicy::LRU,
147        }
148    }
149}
150
151/// Cache eviction policy
152#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
153pub enum CachePolicy {
154    /// Least Recently Used
155    LRU,
156    /// Least Frequently Used
157    LFU,
158    /// Random eviction
159    Random,
160}
161
162/// Steganography configuration
163#[derive(Debug, Clone, Serialize, Deserialize)]
164pub struct StegoConfig {
165    /// Steganography algorithm
166    pub algorithm: StegoAlgorithm,
167    
168    /// Embedding capacity (bits per unit)
169    pub embedding_capacity: f64,
170    
171    /// Enable adaptive embedding
172    pub adaptive_embedding: bool,
173    
174    /// Cover medium type
175    pub cover_medium: CoverMedium,
176    
177    /// Enable entropy matching
178    pub entropy_matching: bool,
179}
180
181impl Default for StegoConfig {
182    fn default() -> Self {
183        Self {
184            algorithm: StegoAlgorithm::AdaptiveLSB,
185            embedding_capacity: 0.1,
186            adaptive_embedding: true,
187            cover_medium: CoverMedium::Video,
188            entropy_matching: true,
189        }
190    }
191}
192
193/// Steganography algorithms
194#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
195pub enum StegoAlgorithm {
196    /// Least Significant Bit
197    LSB,
198    /// Adaptive LSB
199    AdaptiveLSB,
200    /// Discrete Cosine Transform
201    DCT,
202    /// Spread Spectrum
203    SpreadSpectrum,
204    /// Custom algorithm
205    Custom,
206}
207
208/// Cover medium types
209#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
210pub enum CoverMedium {
211    /// Video streams
212    Video,
213    /// Audio streams
214    Audio,
215    /// Images
216    Image,
217    /// Text/Protocol headers
218    Protocol,
219}