Expand description
For internal services (e.g., a Hyper webserver) Internal Service Integration
This module provides a network kernel that enables integration of internal services, such as HTTP servers, within the Citadel Protocol network. It’s particularly useful for implementing web services that need to communicate over secure Citadel channels.
§Features
- Internal service integration
- HTTP server support
- Custom service handlers
- Asynchronous processing
- Type-safe communication
- Automatic channel management
- Service lifecycle handling
§Example
use std::convert::Infallible;
use bytes::Bytes;
use citadel_sdk::prelude::*;
use http_body_util::Full;
use hyper::body::Incoming;
use hyper::service::service_fn;
use hyper::{Request, Response};
use hyper_util::rt::TokioIo;
use citadel_sdk::prefabs::server::internal_service::InternalServiceKernel;
// Create a kernel with an HTTP server bridged over the secure channel
let kernel = InternalServiceKernel::<_, _, StackedRatchet>::new(|comm| async move {
let service = service_fn(|_: Request<Incoming>| async move {
Ok::<_, Infallible>(
Response::new(Full::new(Bytes::from("Hello!")))
)
});
// Serve HTTP/1.1 over the internal service communicator
hyper::server::conn::http1::Builder::new()
.serve_connection(TokioIo::new(comm), service)
.await
.map_err(|e| citadel_io::error!(
citadel_io::ErrorCode::InternalServiceHyperError,
e.to_string()
))?;
Ok(())
});§Important Notes
- Services run in isolated contexts
- Communication is bidirectional
- Supports HTTP/1.1 and HTTP/2
- Automatic error handling
- Resource cleanup on shutdown
§Related Components
NetKernel: Base trait for network kernelsInternalServerCommunicator: Service communicationClientConnectListenerKernel: Connection handlingNodeResult: Network event handling