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
//! Monocle - A BGP information toolkit
//!
//! Monocle provides tools for searching, parsing, and processing BGP information
//! from public sources. It can be used as both a command-line application and
//! a library.
//!
//! # Feature Flags
//!
//! Monocle uses a simplified feature system with three options:
//!
//! | Feature | Description | Implies |
//! |---------|-------------|---------|
//! | `lib` | Complete library (database + all lenses + display) | - |
//! | `server` | WebSocket server for programmatic API access | `lib` |
//! | `cli` | Full CLI binary with all functionality | `lib`, `server` |
//!
//! ## Choosing Features
//!
//! ```toml
//! # Library-only - all lenses and database operations
//! monocle = { version = "1.0", default-features = false, features = ["lib"] }
//!
//! # Library + WebSocket server
//! monocle = { version = "1.0", default-features = false, features = ["server"] }
//!
//! # Default (full CLI binary)
//! monocle = "1.0"
//! ```
//!
//! # Architecture
//!
//! The library is organized into the following modules:
//!
//! - **[`database`]**: Database functionality (requires `lib` feature)
//! - `core`: SQLite connection management and schema definitions
//! - `session`: One-time storage (e.g., search results)
//! - `monocle`: Main monocle database (ASInfo, AS2Rel, RPKI, Pfx2as)
//!
//! - **[`lens`]**: High-level business logic (requires `lib` feature)
//! - `time`: Time parsing and formatting
//! - `country`: Country code/name lookup
//! - `ip`: IP information lookup
//! - `parse`: MRT file parsing
//! - `search`: BGP message search
//! - `rpki`: RPKI validation and data
//! - `pfx2as`: Prefix-to-ASN mapping
//! - `as2rel`: AS-level relationships
//! - `inspect`: Unified AS/prefix lookup
//!
//! - **[`server`]**: WebSocket API server (requires `server` feature)
//!
//! - **[`config`]**: Configuration management (always available)
//!
//! # Quick Start Examples
//!
//! ## Database Operations (feature = "lib")
//!
//! ```rust,ignore
//! use monocle::database::MonocleDatabase;
//!
//! // Open or create database
//! let db = MonocleDatabase::open_in_dir("~/.local/share/monocle")?;
//!
//! // Check if AS2Rel data needs update
//! use std::time::Duration;
//! let ttl = Duration::from_secs(24 * 60 * 60); // 24 hours
//! if db.needs_as2rel_refresh(ttl) {
//! let count = db.update_as2rel()?;
//! println!("Loaded {} relationships", count);
//! }
//!
//! // Query relationships
//! let rels = db.as2rel().search_asn(13335)?;
//! for rel in rels {
//! println!("AS{} <-> AS{}", rel.asn1, rel.asn2);
//! }
//! ```
//!
//! ## Time Parsing (feature = "lib")
//!
//! ```rust,ignore
//! use monocle::lens::time::{TimeLens, TimeParseArgs};
//!
//! let lens = TimeLens::new();
//! let args = TimeParseArgs::new(vec![
//! "1697043600".to_string(), // Unix timestamp
//! "2023-10-11T00:00:00Z".to_string(), // RFC3339
//! ]);
//!
//! let results = lens.parse(&args)?;
//! for t in &results {
//! println!("{} -> {}", t.unix, t.rfc3339);
//! }
//! ```
//!
//! ## RPKI Validation (feature = "lib")
//!
//! ```rust,ignore
//! use monocle::database::MonocleDatabase;
//! use monocle::lens::rpki::RpkiLens;
//!
//! let db = MonocleDatabase::open_in_dir("~/.local/share/monocle")?;
//! let lens = RpkiLens::new(&db);
//!
//! // Ensure cache is populated
//! if lens.needs_refresh()? {
//! lens.refresh()?;
//! }
//!
//! // Validate a prefix-ASN pair
//! let result = lens.validate("1.1.1.0/24", 13335)?;
//! println!("{}: {}", result.state, result.reason);
//! ```
//!
//! ## MRT Parsing with Progress (feature = "lib")
//!
//! ```rust,ignore
//! use monocle::lens::parse::{ParseLens, ParseFilters, ParseProgress};
//! use std::sync::Arc;
//!
//! let lens = ParseLens::new();
//! let filters = ParseFilters {
//! origin_asn: vec!["13335".to_string()],
//! ..Default::default()
//! };
//!
//! let callback = Arc::new(|progress: ParseProgress| {
//! if let ParseProgress::Completed { total_messages, .. } = progress {
//! println!("Parsed {} messages", total_messages);
//! }
//! });
//!
//! let elems = lens.parse_with_progress(&filters, "path/to/file.mrt", Some(callback))?;
//! ```
//!
//! ## Unified Inspection (feature = "lib")
//!
//! ```rust,ignore
//! use monocle::database::MonocleDatabase;
//! use monocle::lens::inspect::{InspectLens, InspectQueryOptions};
//!
//! let db = MonocleDatabase::open_in_dir("~/.local/share/monocle")?;
//! let lens = InspectLens::new(&db);
//!
//! // Auto-refresh data if needed
//! lens.ensure_data_available()?;
//!
//! // Query by ASN, prefix, or name (auto-detected)
//! let options = InspectQueryOptions::default();
//! let results = lens.query(&["13335".to_string()], &options)?;
//!
//! // Get JSON output
//! let json = lens.format_json(&results, true);
//! println!("{}", json);
//! ```
// Lens module - requires lib feature
// Server module - requires server feature
// =============================================================================
// Configuration (always available)
// =============================================================================
pub use MonocleConfig;
// Shared database info types (used by config and database commands)
pub use get_data_source_info;
pub use get_sqlite_info;
pub use ;
// =============================================================================
// Database Module - Re-export all public types
// =============================================================================
pub use *;
// =============================================================================
// Utility Module
// =============================================================================
// Output format utilities (lib feature)
pub use OutputFormat;
// =============================================================================
// Lens Module - Feature-gated exports
// =============================================================================
// =============================================================================
// Server Module (WebSocket API) - requires "server" feature
// =============================================================================
pub use ;