1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//! Core protocol logic for CHIE Protocol.
//!
//! This crate provides the main node implementation and content management for the
//! CHIE (Collective Hybrid Intelligence Ecosystem) protocol - a decentralized content
//! distribution system with incentive mechanisms.
//!
//! # Overview
//!
//! The chie-core crate contains the fundamental building blocks for running a CHIE node:
//!
//! - **Node Management** ([`node`]): Core node implementation for handling content and proofs
//! - **Storage** ([`storage`]): Chunk-based storage system with encryption support
//! - **Protocol** ([`protocol`]): Bandwidth proof protocol and validation
//! - **Content Management** ([`content`]): Content metadata caching and management
//! - **Cryptography** ([`chunk_encryption`]): Per-chunk encryption utilities
//! - **Analytics** ([`analytics`]): Performance metrics and statistics tracking
//! - **Utilities** ([`utils`]): Helper functions for common operations
//!
//! # Quick Start
//!
//! ```no_run
//! use chie_core::{ContentNode, NodeConfig, PinnedContent};
//! use std::path::PathBuf;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a node with storage
//! let config = NodeConfig {
//! storage_path: PathBuf::from("./chie-data"),
//! max_storage_bytes: 50 * 1024 * 1024 * 1024, // 50 GB
//! max_bandwidth_bps: 100 * 1024 * 1024 / 8, // 100 Mbps
//! coordinator_url: "https://coordinator.chie.network".to_string(),
//! };
//!
//! let mut node = ContentNode::with_storage(config).await?;
//!
//! // Pin content for distribution
//! let content = PinnedContent {
//! cid: "QmExample123".to_string(),
//! size_bytes: 1024 * 1024,
//! encryption_key: [0u8; 32],
//! predicted_revenue_per_gb: 10.0,
//! };
//! node.pin_content(content);
//!
//! println!("Node public key: {:?}", node.public_key());
//! println!("Pinned content count: {}", node.pinned_count());
//!
//! Ok(())
//! }
//! ```
//!
//! # Features
//!
//! ## Content Storage
//!
//! The storage system splits content into chunks, encrypts each chunk individually,
//! and stores them with cryptographic verification:
//!
//! ```no_run
//! use chie_core::{ChunkStorage, split_into_chunks};
//! use chie_crypto::{generate_key, generate_nonce};
//! use std::path::PathBuf;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let storage_path = PathBuf::from("./storage");
//! let max_bytes = 10 * 1024 * 1024 * 1024; // 10 GB
//!
//! let mut storage = ChunkStorage::new(storage_path, max_bytes).await?;
//!
//! // Split and store content
//! let data = b"Hello, CHIE Protocol!";
//! let chunks = split_into_chunks(data, 1024);
//! let key = generate_key();
//! let nonce = generate_nonce();
//!
//! storage.pin_content("QmTest", &chunks, &key, &nonce).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Bandwidth Proof Protocol
//!
//! Nodes earn rewards by serving content and generating cryptographically-signed
//! bandwidth proofs:
//!
//! ```no_run
//! use chie_core::{create_chunk_request, create_bandwidth_proof};
//! use chie_crypto::KeyPair;
//!
//! # fn example() {
//! let requester_keypair = KeyPair::generate();
//! let provider_keypair = KeyPair::generate();
//!
//! // Create a chunk request with challenge nonce
//! let request = create_chunk_request(
//! "QmContent123".to_string(),
//! 0, // chunk index
//! "requester-peer-id".to_string(),
//! requester_keypair.public_key(),
//! );
//!
//! // Provider serves chunk and signs response
//! // Requester verifies and co-signs
//! // Both submit dual-signed proof to coordinator
//! # }
//! ```
//!
//! ## Performance Optimization
//!
//! The crate includes several performance optimization features:
//!
//! - **Chunk Prefetching** ([`prefetch`]): Predict and preload chunks based on access patterns
//! - **Tiered Storage** ([`tiered_storage`]): Hot/warm/cold storage tiers for cost optimization
//! - **Rate Limiting** ([`ratelimit`]): Per-peer bandwidth throttling
//! - **Content Deduplication** ([`dedup`]): Avoid storing duplicate chunks
//! - **Garbage Collection** ([`gc`]): Remove unprofitable content automatically
//!
//! # Module Overview
//!
//! - [`adaptive_ratelimit`] - Adaptive rate limiting with dynamic adjustments
//! - [`analytics`] - Performance metrics and earnings tracking
//! - [`anomaly`] - Anomaly detection for fraud prevention
//! - [`auto_repair`] - Automatic data integrity repair for corrupted chunks
//! - [`backup`] - Storage backup and recovery utilities
//! - [`batch`] - Batch processing utilities
//! - [`cache`] - Advanced caching with TTL and memory management
//! - [`cache_invalidation`] - Distributed cache invalidation notifications
//! - [`chunk_encryption`] - Encrypted chunk data structures
//! - [`circuit_breaker`] - Circuit breaker pattern for resilient service calls
//! - [`compression`] - Content compression utilities
//! - [`connection_multiplexing`] - HTTP connection pooling and multiplexing for coordinator communication
//! - [`content`] - Content metadata management
//! - [`content_aware_cache`] - Content-aware cache sizing with intelligent management
//! - [`content_router`] - Content routing optimizer
//! - [`custom_exporters`] - Custom metrics exporters (StatsD, InfluxDB)
//! - [`dedup`] - Content deduplication
//! - [`gc`] - Garbage collection for storage
//! - [`health`] - Health check system for node monitoring
//! - [`http_pool`] - HTTP connection pooling utilities
//! - [`integrity`] - Content integrity verification
//! - [`lifecycle`] - Content lifecycle events and webhooks
//! - [`metrics`] - Prometheus-compatible metrics exporter
//! - [`network_diag`] - Network diagnostics and monitoring
//! - [`node`] - Core node implementation
//! - [`peer_selection`] - Intelligent peer selection and ranking
//! - [`pinning`] - Selective pinning optimizer
//! - [`popularity`] - Content popularity tracking
//! - [`prefetch`] - Chunk prefetching
//! - [`profiler`] - Performance profiling and timing utilities
//! - [`proof_submit`] - Proof submission with retry logic
//! - [`protocol`] - Bandwidth proof protocol
//! - [`qos`] - Quality of Service with priority-based scheduling
//! - [`quic_transport`] - QUIC transport integration for modern, efficient networking
//! - [`ratelimit`] - Rate limiting
//! - [`reputation`] - Peer reputation tracking
//! - [`resource_mgmt`] - Advanced resource management and monitoring
//! - [`storage`] - Chunk storage backend
//! - [`storage_health`] - Storage health monitoring with predictive failure detection
//! - [`streaming`] - Streaming utilities for large content
//! - [`tiered_storage`] - Multi-tier storage system
//! - [`tracing`] - OpenTelemetry tracing integration for distributed observability
//! - [`utils`] - Utility functions
//! - [`validation`] - Content and proof validation utilities
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// bandwidth_estimation module available via `chie_core::bandwidth_estimation::`
// (not glob re-exported to avoid conflict with ratelimit::BandwidthStats)
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// custom_exporters module available via `chie_core::custom_exporters::`
// (not glob re-exported to avoid conflict with metrics_exporter::MetricValue)
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// quic_transport module available via `chie_core::quic_transport::`
// (not glob re-exported to avoid type conflicts with network modules)
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// system_coordinator module available via `chie_core::system_coordinator::`
// (not glob re-exported to avoid conflict with dashboard::SystemStatus)
pub use *;
// tiered_cache module available via `chie_core::tiered_cache::`
// (not glob re-exported to avoid conflict with cache::TieredCache)
pub use *;
pub use *;
// tracing module available via `chie_core::tracing::`
// (not glob re-exported to avoid conflicts)
pub use *;
pub use *;
pub use *;
pub use *;