1use serde::{Deserialize, Serialize};
2use std::net::SocketAddr;
3use std::time::Duration;
4
5use crate::transport::CoverProtocol;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct NetworkConfig {
10 pub listen_addr: SocketAddr,
12
13 pub bootstrap_nodes: Vec<String>,
15
16 pub cover_protocol: CoverProtocol,
18
19 pub max_peers: usize,
21
22 pub connection_timeout: Duration,
24
25 pub enable_nat_traversal: bool,
27
28 pub stun_servers: Vec<String>,
30
31 pub turn_servers: Vec<TurnServerConfig>,
33
34 pub dht: DhtConfig,
36
37 pub storage: StorageConfig,
39
40 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#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct TurnServerConfig {
68 pub url: String,
69 pub username: String,
70 pub password: String,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct DhtConfig {
76 pub k_value: usize,
78
79 pub alpha: usize,
81
82 pub replication_factor: usize,
84
85 pub republish_interval: Duration,
87
88 pub node_expiration: Duration,
90
91 pub enable_delayed_lookups: bool,
93
94 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#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct StorageConfig {
115 pub enabled: bool,
117
118 pub max_storage_size: u64,
120
121 pub enable_erasure_coding: bool,
123
124 pub erasure_params: (usize, usize),
126
127 pub enable_passive_replication: bool,
129
130 pub cache_size: u64,
132
133 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, enable_erasure_coding: true,
143 erasure_params: (10, 5), enable_passive_replication: true,
145 cache_size: 100 * 1024 * 1024, cache_policy: CachePolicy::LRU,
147 }
148 }
149}
150
151#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
153pub enum CachePolicy {
154 LRU,
156 LFU,
158 Random,
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize)]
164pub struct StegoConfig {
165 pub algorithm: StegoAlgorithm,
167
168 pub embedding_capacity: f64,
170
171 pub adaptive_embedding: bool,
173
174 pub cover_medium: CoverMedium,
176
177 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#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
195pub enum StegoAlgorithm {
196 LSB,
198 AdaptiveLSB,
200 DCT,
202 SpreadSpectrum,
204 Custom,
206}
207
208#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
210pub enum CoverMedium {
211 Video,
213 Audio,
215 Image,
217 Protocol,
219}