2026-01-24 22:59:20 +00:00
|
|
|
use crate::api::ApiHandler;
|
|
|
|
|
use crate::config::Config;
|
2026-01-27 23:06:18 +00:00
|
|
|
use crate::state::StateManager;
|
2026-01-24 22:59:20 +00:00
|
|
|
use anyhow::Result;
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
use hyper::server::conn::Http;
|
|
|
|
|
use hyper::service::service_fn;
|
2026-01-24 22:59:20 +00:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use tokio::net::TcpListener;
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
use tracing::error;
|
2026-01-24 22:59:20 +00:00
|
|
|
|
|
|
|
|
pub struct Server {
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
_config: Config,
|
2026-01-24 22:59:20 +00:00
|
|
|
api_handler: Arc<ApiHandler>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Server {
|
|
|
|
|
pub async fn new(config: Config) -> Result<Self> {
|
2026-01-27 23:06:18 +00:00
|
|
|
let state_manager = Arc::new(StateManager::new());
|
|
|
|
|
let api_handler = Arc::new(ApiHandler::new(config.clone(), state_manager).await?);
|
2026-01-24 22:59:20 +00:00
|
|
|
|
|
|
|
|
Ok(Self {
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
_config: config,
|
2026-01-24 22:59:20 +00:00
|
|
|
api_handler,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn serve(&self, addr: SocketAddr) -> Result<()> {
|
|
|
|
|
let listener = TcpListener::bind(addr).await?;
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
let (stream, peer_addr) = match listener.accept().await {
|
|
|
|
|
Ok(conn) => conn,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("Failed to accept connection: {}", e);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let handler = self.api_handler.clone();
|
|
|
|
|
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
let service = service_fn(move |req| {
|
|
|
|
|
let handler = handler.clone();
|
|
|
|
|
async move {
|
|
|
|
|
handler.handle_request(req).await
|
2026-01-24 23:09:46 +00:00
|
|
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("{}", e)))
|
2026-01-24 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
if let Err(e) = Http::new()
|
|
|
|
|
.serve_connection(stream, service)
|
2026-01-27 22:47:51 +00:00
|
|
|
.with_upgrades()
|
2026-01-24 22:59:20 +00:00
|
|
|
.await
|
|
|
|
|
{
|
|
|
|
|
error!("Error serving connection from {}: {}", peer_addr, e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|