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
//! IPFRS - Inter-Planet File RUST System
//!
//! Version: 0.2.0 "Network Release"
//!
//! A next-generation distributed file system built in Rust, combining:
//! - High-performance zero-copy data transport
//! - Semantic routing and vector search
//! - TensorLogic integration for distributed reasoning
//! - ARM-optimized implementation
//! - Content-addressed storage with IPLD
//! - Distributed networking via libp2p
//! - Pin management and garbage collection
//! - Comprehensive observability (metrics, logging, tracing)
//!
//! # Architecture
//!
//! IPFRS follows a bi-layer architecture:
//!
//! ## Logical Layer (The Brain)
//! - **Semantic Router**: Vector search and logic solving for content discovery
//! - **TensorLogic**: Distributed reasoning and knowledge representation
//! - **Differentiable Storage**: Gradient tracking for learning
//!
//! ## Physical Layer (The Body)
//! - **TensorSwap**: Optimized tensor streaming protocol
//! - **Block Storage**: Sled-backed content-addressed storage
//! - **Network Stack**: libp2p with QUIC, Bitswap, and DHT
//! - **Pin Management**: Protect important content from garbage collection
//!
//! # Features
//!
//! ## Content-Addressed Storage
//! - Store and retrieve data by content hash (CID)
//! - IPLD support for structured data with links
//! - DAG operations for hierarchical data structures
//!
//! ## Semantic Search
//! - Vector similarity search using HNSW index
//! - Filter-based queries
//! - Persistent index with save/load support
//!
//! ## Logic Programming
//! - TensorLogic integration for facts, rules, and inference
//! - Backward chaining reasoning
//! - Proof generation and verification
//! - Knowledge base persistence
//!
//! ## Networking
//! - Peer-to-peer content distribution
//! - DHT-based content discovery
//! - Bitswap protocol for block exchange
//! - NAT traversal and relay support
//!
//! ## Pin Management
//! - Direct and recursive pinning
//! - Automatic DAG traversal for recursive pins
//! - Protect content from garbage collection
//!
//! ## Observability
//! - Prometheus metrics
//! - Structured logging with tracing
//! - OpenTelemetry integration
//! - Health checks and status monitoring
//!
//! # Quick Start
//!
//! ## Basic Node Setup
//!
//! ```rust,no_run
//! use ipfrs::{Node, NodeConfig};
//!
//! #[tokio::main]
//! async fn main() -> ipfrs::Result<()> {
//! // Create and start a node with default configuration
//! let config = NodeConfig::default();
//! let mut node = Node::new(config)?;
//! node.start().await?;
//!
//! // Node is now running and ready to use
//! println!("Node started successfully!");
//!
//! // Stop the node when done
//! node.stop().await?;
//! Ok(())
//! }
//! ```
//!
//! ## Storing and Retrieving Content
//!
//! ```rust,no_run
//! # use ipfrs::{Node, NodeConfig, Block};
//! # use bytes::Bytes;
//! #
//! # #[tokio::main]
//! # async fn main() -> ipfrs::Result<()> {
//! # let mut node = Node::new(NodeConfig::default())?;
//! # node.start().await?;
//! // Store content
//! let data = Bytes::from("Hello, IPFRS!");
//! let block = Block::new(data.clone())?;
//! let cid = *block.cid();
//! node.put_block(&block).await?;
//! println!("Stored content with CID: {}", cid);
//!
//! // Retrieve content
//! let retrieved = node.get_block(&cid).await?;
//! assert!(retrieved.is_some());
//! # Ok(())
//! # }
//! ```
//!
//! ## Pin Management
//!
//! ```rust,no_run
//! # use ipfrs::{Node, NodeConfig, Block};
//! # use bytes::Bytes;
//! #
//! # #[tokio::main]
//! # async fn main() -> ipfrs::Result<()> {
//! # let mut node = Node::new(NodeConfig::default())?;
//! # node.start().await?;
//! # let block = Block::new(Bytes::from("data"))?;
//! # let cid = *block.cid();
//! # node.put_block(&block).await?;
//! // Pin content to prevent garbage collection
//! node.pin_add(&cid, false, Some("important-data".to_string())).await?;
//!
//! // List all pins
//! let pins = node.pin_ls()?;
//! for pin in pins {
//! println!("Pinned: {} ({:?})", pin.cid, pin.pin_type);
//! }
//!
//! // Unpin when no longer needed
//! node.pin_rm(&cid, false).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Semantic Search
//!
//! ```rust,no_run
//! # use ipfrs::{Node, NodeConfig, Block};
//! # use bytes::Bytes;
//! #
//! # #[tokio::main]
//! # async fn main() -> ipfrs::Result<()> {
//! # let mut node = Node::new(NodeConfig::default().with_semantic(Default::default()))?;
//! # node.start().await?;
//! # let block = Block::new(Bytes::from("content"))?;
//! # let cid = *block.cid();
//! # node.put_block(&block).await?;
//! // Index content for semantic search
//! let embedding = vec![0.1; 768]; // Your embedding vector
//! node.index_content(&cid, &embedding).await?;
//!
//! // Perform similarity search
//! let query = vec![0.2; 768];
//! let results = node.search_similar(&query, 10).await?;
//! for result in results {
//! println!("Found: {} (score: {})", result.cid, result.score);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Logic Programming
//!
//! ```rust,no_run
//! # use ipfrs::{Node, NodeConfig, Predicate, Term, Constant};
//! #
//! # #[tokio::main]
//! # async fn main() -> ipfrs::Result<()> {
//! # let mut node = Node::new(NodeConfig::default().with_tensorlogic())?;
//! # node.start().await?;
//! // Add facts
//! let fact = Predicate::new(
//! "parent".to_string(),
//! vec![
//! Term::Const(Constant::String("alice".to_string())),
//! Term::Const(Constant::String("bob".to_string())),
//! ],
//! );
//! node.add_fact(fact)?;
//!
//! // Perform inference
//! let query = Predicate::new(
//! "parent".to_string(),
//! vec![
//! Term::Var("X".to_string()),
//! Term::Const(Constant::String("bob".to_string())),
//! ],
//! );
//! let results = node.infer(&query)?;
//! println!("Found {} results", results.len());
//! # Ok(())
//! # }
//! ```
// Re-export core types
pub use ;
// Re-export network types
pub use ;
// Re-export storage types
pub use ;
// Re-export transport types
pub use ;
// Re-export semantic types
pub use ;
// Re-export interface types
pub use ;
// Re-export TensorLogic types
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;