chie_shared/
constants.rs

1//! Protocol constants for CHIE.
2
3// Protocol version constants
4/// Current protocol version.
5pub const PROTOCOL_VERSION: &str = "1.0.0";
6
7/// Bandwidth proof protocol ID.
8pub const BANDWIDTH_PROOF_PROTOCOL: &str = "/chie/bandwidth-proof/1.0.0";
9
10/// Content announcement protocol ID.
11pub const CONTENT_ANNOUNCEMENT_PROTOCOL: &str = "/chie/content-announce/1.0.0";
12
13// Network constants
14/// Default DHT query timeout (30 seconds in milliseconds).
15pub const DHT_QUERY_TIMEOUT_MS: u64 = 30_000;
16
17/// Maximum peers to return in DHT query.
18pub const MAX_DHT_PEERS: usize = 20;
19
20/// Peer reputation decay rate (per day).
21pub const REPUTATION_DECAY_RATE: f32 = 0.01;
22
23/// Minimum reputation score (0.0).
24pub const MIN_REPUTATION: f32 = 0.0;
25
26/// Maximum reputation score (100.0).
27pub const MAX_REPUTATION: f32 = 100.0;
28
29/// Default reputation for new peers.
30pub const DEFAULT_REPUTATION: f32 = 50.0;
31
32// Reward constants
33/// Base reward: 10 points per GB.
34pub const BASE_POINTS_PER_GB: f64 = 10.0;
35
36/// Maximum demand multiplier (3x).
37pub const MAX_DEMAND_MULTIPLIER: f64 = 3.0;
38
39/// Minimum demand multiplier (0.5x).
40pub const MIN_DEMAND_MULTIPLIER: f64 = 0.5;
41
42/// Latency penalty threshold (500ms).
43pub const LATENCY_PENALTY_THRESHOLD_MS: u32 = 500;
44
45/// Latency penalty multiplier (0.5x if above threshold).
46pub const LATENCY_PENALTY_MULTIPLIER: f64 = 0.5;
47
48/// Platform fee percentage (10%).
49pub const PLATFORM_FEE_PERCENTAGE: f64 = 0.10;
50
51/// Creator share percentage (20%).
52pub const CREATOR_SHARE_PERCENTAGE: f64 = 0.20;
53
54// Storage and bandwidth limits
55/// Minimum free disk space required (1 GB).
56pub const MIN_FREE_DISK_SPACE: u64 = 1024 * 1024 * 1024;
57
58/// Default storage allocation (10 GB).
59pub const DEFAULT_STORAGE_ALLOCATION: u64 = 10 * 1024 * 1024 * 1024;
60
61/// Default bandwidth limit (100 Mbps).
62pub const DEFAULT_BANDWIDTH_LIMIT_BPS: u64 = 100 * 1_000_000;
63
64/// Maximum concurrent transfers per node.
65pub const MAX_CONCURRENT_TRANSFERS: usize = 10;
66
67/// Chunk request timeout (10 seconds in milliseconds).
68pub const CHUNK_REQUEST_TIMEOUT_MS: u64 = 10_000;
69
70// Rate limiting
71/// Maximum proofs per peer per hour.
72pub const MAX_PROOFS_PER_PEER_PER_HOUR: u32 = 1000;
73
74/// Maximum failed requests before temporary ban.
75pub const MAX_FAILED_REQUESTS: u32 = 10;
76
77/// Temporary ban duration (1 hour in seconds).
78pub const TEMP_BAN_DURATION_SECS: u64 = 3600;
79
80/// Permanent ban threshold (repeated temp bans).
81pub const PERMANENT_BAN_THRESHOLD: u32 = 3;
82
83// Anomaly detection thresholds
84/// Z-score threshold for anomaly detection.
85pub const ANOMALY_Z_SCORE_THRESHOLD: f64 = 3.0;
86
87/// Minimum samples required for statistical analysis.
88pub const MIN_SAMPLES_FOR_STATS: usize = 30;
89
90/// Maximum bandwidth deviation percentage.
91pub const MAX_BANDWIDTH_DEVIATION_PERCENT: f64 = 200.0;
92
93// Cache and database
94/// Nonce cache TTL (10 minutes in seconds).
95pub const NONCE_CACHE_TTL_SECS: u64 = 600;
96
97/// Maximum nonce cache size.
98pub const MAX_NONCE_CACHE_SIZE: usize = 100_000;
99
100/// Database connection pool size.
101pub const DB_POOL_SIZE: u32 = 10;
102
103/// Database query timeout (30 seconds).
104pub const DB_QUERY_TIMEOUT_SECS: u64 = 30;
105
106// Content limits
107/// Maximum preview images per content.
108pub const MAX_PREVIEW_IMAGES: usize = 10;
109
110/// Maximum file size for preview image (5 MB).
111pub const MAX_PREVIEW_IMAGE_SIZE: usize = 5 * 1024 * 1024;
112
113/// Minimum price for content (1 point).
114pub const MIN_CONTENT_PRICE: u64 = 1;
115
116/// Maximum price for content (1 million points).
117pub const MAX_CONTENT_PRICE: u64 = 1_000_000;
118
119// User and account limits
120/// Minimum username length.
121pub const MIN_USERNAME_LENGTH: usize = 3;
122
123/// Maximum username length.
124pub const MAX_USERNAME_LENGTH: usize = 20;
125
126/// Minimum password length.
127pub const MIN_PASSWORD_LENGTH: usize = 8;
128
129/// Maximum password length.
130pub const MAX_PASSWORD_LENGTH: usize = 128;
131
132/// Maximum email length.
133pub const MAX_EMAIL_LENGTH: usize = 254;
134
135/// Maximum API keys per user.
136pub const MAX_API_KEYS_PER_USER: usize = 5;
137
138// Pagination defaults
139/// Default page size for list queries.
140pub const DEFAULT_PAGE_SIZE: u64 = 20;
141
142/// Maximum page size for list queries.
143pub const MAX_PAGE_SIZE: u64 = 100;
144
145// Retry and backoff
146/// Maximum retry attempts for proof submission.
147pub const MAX_PROOF_SUBMISSION_RETRIES: u32 = 3;
148
149/// Base backoff delay in milliseconds.
150pub const BASE_BACKOFF_DELAY_MS: u64 = 1000;
151
152/// Maximum backoff delay in milliseconds.
153pub const MAX_BACKOFF_DELAY_MS: u64 = 60_000;
154
155// Gossipsub topic names
156/// Topic for content announcements.
157pub const GOSSIPSUB_CONTENT_ANNOUNCE_TOPIC: &str = "chie/content/announce";
158
159/// Topic for peer discovery.
160pub const GOSSIPSUB_PEER_DISCOVERY_TOPIC: &str = "chie/peer/discovery";
161
162/// Topic for demand updates.
163pub const GOSSIPSUB_DEMAND_UPDATE_TOPIC: &str = "chie/demand/update";
164
165// Metrics and monitoring
166/// Metrics collection interval (60 seconds).
167pub const METRICS_COLLECTION_INTERVAL_SECS: u64 = 60;
168
169/// Metrics retention period (7 days).
170pub const METRICS_RETENTION_DAYS: u32 = 7;
171
172/// Health check interval (30 seconds).
173pub const HEALTH_CHECK_INTERVAL_SECS: u64 = 30;
174
175// Garbage collection
176/// Minimum content age for garbage collection (30 days in seconds).
177pub const MIN_CONTENT_AGE_FOR_GC_SECS: u64 = 30 * 24 * 3600;
178
179/// Minimum seeder count before unpinning.
180pub const MIN_SEEDER_COUNT: u32 = 3;
181
182/// Profitability check interval (24 hours in seconds).
183pub const PROFITABILITY_CHECK_INTERVAL_SECS: u64 = 24 * 3600;
184
185// Worker configuration
186/// Maximum parallel encryption jobs.
187pub const MAX_PARALLEL_ENCRYPTION_JOBS: usize = 4;
188
189/// Job retry attempts.
190pub const JOB_RETRY_ATTEMPTS: u32 = 3;
191
192/// Job timeout (10 minutes in seconds).
193pub const JOB_TIMEOUT_SECS: u64 = 600;