amaters_net/
lib.rs

1//! Network layer for AmateRS (Musubi - The Knot)
2//!
3//! This crate provides the gRPC-based networking layer for AmateRS,
4//! implementing secure communication over QUIC with mTLS.
5//!
6//! # Features
7//!
8//! - gRPC service for AQL queries
9//! - Request/response handling with streaming support
10//! - Error handling and retry strategies
11//! - Connection state management
12//!
13//! # Architecture
14//!
15//! The networking layer consists of:
16//! - Protocol definitions (.proto files)
17//! - Server implementation (gRPC service)
18//! - Client implementation (connection management)
19//! - Error types and conversions
20//!
21//! # Example
22//!
23//! ```rust,ignore
24//! use amaters_net::client::AqlClient;
25//! use amaters_core::{Key, CipherBlob};
26//!
27//! #[tokio::main]
28//! async fn main() -> anyhow::Result<()> {
29//!     let client = AqlClient::connect("http://localhost:50051").await?;
30//!
31//!     let key = Key::from_str("my_key");
32//!     let value = CipherBlob::new(vec![1, 2, 3]);
33//!
34//!     client.set("my_collection", key, value).await?;
35//!
36//!     Ok(())
37//! }
38//! ```
39
40#![allow(dead_code)]
41#![allow(clippy::type_complexity)]
42#![allow(clippy::too_many_arguments)]
43
44pub mod balancer;
45pub mod circuit_breaker;
46pub mod client;
47pub mod convert;
48pub mod error;
49pub mod grpc_service;
50pub mod pool;
51pub mod server;
52
53// mTLS module (feature-gated)
54#[cfg(feature = "mtls")]
55pub mod mtls;
56#[cfg(feature = "mtls")]
57pub mod tls;
58
59// Include the generated protocol buffer code
60pub mod proto {
61    pub mod types {
62        #![allow(clippy::all)]
63        #![allow(warnings)]
64        include!(concat!(env!("OUT_DIR"), "/amaters.types.rs"));
65    }
66    pub mod query {
67        #![allow(clippy::all)]
68        #![allow(warnings)]
69        include!(concat!(env!("OUT_DIR"), "/amaters.query.rs"));
70    }
71    pub mod errors {
72        #![allow(clippy::all)]
73        #![allow(warnings)]
74        include!(concat!(env!("OUT_DIR"), "/amaters.errors.rs"));
75    }
76    pub mod aql {
77        #![allow(clippy::all)]
78        #![allow(warnings)]
79        include!(concat!(env!("OUT_DIR"), "/amaters.aql.rs"));
80    }
81}
82
83// Re-exports for convenience
84pub use error::{NetError, NetResult};
85pub use server::{AqlServerBuilder, AqlServiceImpl};
86
87// mTLS re-exports
88#[cfg(feature = "mtls")]
89pub use mtls::{
90    CrlRevocationChecker, HandshakeResult, MtlsClient, MtlsClientVerifier, MtlsConfigBuilder,
91    MtlsServer, MtlsServerVerifier, OcspRevocationChecker, Principal, PrincipalMapper,
92    RevocationChecker, RevocationStatus,
93};
94#[cfg(feature = "mtls")]
95pub use tls::{
96    CertificateFormat, CertificateInfo, CertificateLoader, CertificateStore,
97    HotReloadableCertificates, PrivateKeyLoader, PrivateKeyType, SelfSignedGenerator,
98};
99
100/// Library version
101pub const VERSION: &str = env!("CARGO_PKG_VERSION");
102
103/// Protocol version
104pub const PROTOCOL_VERSION: (u32, u32, u32) = (0, 1, 0);
105
106#[cfg(test)]
107mod tests {
108    use super::*;
109
110    #[test]
111    fn test_version() {
112        // VERSION is a compile-time constant from CARGO_PKG_VERSION
113        // It should be in semver format (e.g., "0.1.0")
114        assert!(VERSION.contains('.'), "VERSION should be semver format");
115    }
116
117    #[test]
118    fn test_protocol_version() {
119        assert_eq!(PROTOCOL_VERSION, (0, 1, 0));
120    }
121}