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
//! IPFRS Interface - High-performance HTTP Gateway and API Layer
//!
//! This crate provides a comprehensive API layer for IPFRS (InterPlanetary File & Reasoning System),
//! offering multiple interfaces for accessing distributed content and computation.
//!
//! # Features
//!
//! ## HTTP Gateway
//! - **Kubo-compatible API** (`/api/v0/*`) - Full compatibility with IPFS Kubo clients
//! - **High-speed v1 API** (`/v1/*`) - Optimized endpoints with batch operations
//! - **Content gateway** (`/ipfs/{cid}`) - Direct content retrieval with range requests
//! - **Multi-range support** - Efficient sparse downloads with HTTP 206
//!
//! ## gRPC Interface
//! - **BlockService** - Raw block operations (Get, Put, Has, Delete, Batch)
//! - **DagService** - DAG operations (Get, Put, Resolve, Traverse)
//! - **FileService** - File operations (Add, Get, List, Pin)
//! - **TensorService** - Zero-copy tensor operations (Get, Slice, Stream)
//! - **Streaming RPCs** - Client, server, and bidirectional streaming
//! - **Interceptors** - Authentication, logging, metrics, rate limiting
//!
//! ## WebSocket Support
//! - **Real-time events** - Block additions, peer connections, DHT queries
//! - **Pub/sub system** - Topic-based event subscriptions
//! - **Connection management** - Automatic cleanup and heartbeat
//!
//! ## Advanced Features
//! - **Zero-copy tensor API** - Efficient ML model distribution via Safetensors
//! - **Streaming uploads/downloads** - Memory-efficient large file handling
//! - **Batch operations** - Parallel processing with atomic transactions
//! - **Flow control** - Adaptive window-based congestion control
//! - **Resume/cancel** - Robust transfer management
//!
//! ## Security & Performance
//! - **Authentication** - JWT tokens, API keys, and OAuth2 (Authorization Code, Client Credentials, PKCE)
//! - **Rate limiting** - Token bucket algorithm with per-client limits
//! - **CORS** - Configurable cross-origin resource sharing
//! - **Compression** - Gzip, Brotli, and Deflate with tunable levels
//! - **HTTP caching** - ETag and Cache-Control for CDN optimization
//! - **TLS/HTTPS** - Production-ready SSL/TLS support
//!
//! # Quick Start
//!
//! ```rust,ignore
//! // Example usage (see examples/server.rs for a complete working example)
//! use ipfrs_interface::GatewayConfig;
//! use ipfrs_storage::blockstore::BlockStoreConfig;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create gateway with default configuration
//! let storage_config = BlockStoreConfig::default();
//! let mut gateway_config = GatewayConfig::default();
//! gateway_config.storage_config = storage_config;
//! gateway_config.listen_addr = "127.0.0.1:8080".to_string();
//!
//! // See /tmp/example_server.rs for complete implementation
//! Ok(())
//! }
//! ```
//!
//! # Examples
//!
//! ## Upload a file (Kubo v0 API)
//! ```bash
//! curl -X POST -F "file=@myfile.txt" http://localhost:8080/api/v0/add
//! ```
//!
//! ## Download via gateway
//! ```bash
//! curl http://localhost:8080/ipfs/<CID>
//! ```
//!
//! ## Batch block operations (v1 API)
//! ```bash
//! curl -X POST -H "Content-Type: application/json" \
//! -d '{"cids":["<CID1>","<CID2>"]}' \
//! http://localhost:8080/v1/block/batch/get
//! ```
//!
//! ## Get tensor slice (zero-copy)
//! ```bash
//! curl "http://localhost:8080/v1/tensor/<CID>?slice=0:10,5:15"
//! ```
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────┐
//! │ HTTP Clients │ (curl, browsers, IPFS clients)
//! └────────┬────────┘
//! │
//! ┌────────▼────────┐
//! │ Axum Router │ (HTTP/HTTPS)
//! ├─────────────────┤
//! │ Middleware │ (CORS, Auth, Rate Limit, Compression)
//! ├─────────────────┤
//! │ API Handlers │ (v0, v1, Gateway, WebSocket)
//! └────────┬────────┘
//! │
//! ┌────────▼────────┐
//! │ gRPC Server │ (Tonic)
//! ├─────────────────┤
//! │ Interceptors │ (Auth, Logging, Metrics)
//! ├─────────────────┤
//! │ Services │ (Block, DAG, File, Tensor)
//! └────────┬────────┘
//! │
//! ┌────────▼────────┐
//! │ Core Layer │ (ipfrs-core, ipfrs-storage, etc.)
//! └─────────────────┘
//! ```
//!
//! # Performance
//!
//! Target performance characteristics:
//! - Request latency: < 10ms (simple GET)
//! - Throughput: > 1GB/s (range requests)
//! - Concurrent connections: 10,000+
//! - Memory per connection: < 100KB
//!
//! # See Also
//!
//! - [`Gateway`] - Main HTTP gateway implementation
//! - [`middleware`] - CORS, rate limiting, and compression
//! - [`streaming`] - Streaming operations and flow control
//! - [`websocket`] - WebSocket real-time events
// TODO: Re-enable when tonic-build 0.14 service generation is properly configured
// pub mod grpc;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ZeroCopyBuffer;
// gRPC exports
// TODO: Re-enable when tonic-build 0.14 service generation is properly configured
// pub use grpc::{
// backpressure_support, AuthInterceptor, BlockServiceImpl, BlockServiceServer,
// ChainedInterceptor, DagServiceImpl, DagServiceServer, FileServiceImpl, FileServiceServer,
// GrpcServiceConfig, LoggingInterceptor, MetricsInterceptor, RateLimitInterceptor,
// TensorServiceImpl, TensorServiceServer,
// };