pub mod service;
pub mod config;
mod auth;
mod error;
#[cfg(test)]
mod tests;
pub use config::ServerConfig;
pub use error::{ServerError, Result};
use std::net::SocketAddr;
use std::sync::Arc;
use anyhow;
use qdrant_client::Qdrant;
use crate::config::AppConfig;
use service::VectorDBServiceImpl;
use tokio::sync::oneshot;
use tonic::transport::{Server, Identity, ServerTlsConfig};
use tracing::{info, error};
#[cfg(feature = "server")]
use vectordb_proto;
#[cfg(feature = "server")]
pub async fn start_server(
addr: SocketAddr,
config: Arc<AppConfig>,
client: Arc<Qdrant>,
shutdown_signal: Option<oneshot::Receiver<()>>,
use_tls: bool,
cert_path: Option<String>,
key_path: Option<String>,
) -> anyhow::Result<()> {
let service = VectorDBServiceImpl::new(config, client);
let reflection_service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(vectordb_proto::FILE_DESCRIPTOR_SET)
.build()?;
info!("Starting gRPC server on {}", addr);
let server = Server::builder()
.add_service(reflection_service)
.add_service(vectordb_proto::vector_db_service_server::VectorDbServiceServer::new(service));
if use_tls {
error!("TLS support is temporarily disabled for compilation reasons");
return Err(anyhow::anyhow!("TLS support is temporarily disabled"));
} else {
if let Some(signal) = shutdown_signal {
server
.serve_with_shutdown(addr, async {
let _ = signal.await;
info!("Shutdown signal received, stopping server");
})
.await?;
} else {
server.serve(addr).await?;
}
}
Ok(())
}
#[cfg(not(feature = "server"))]
pub async fn start_server(
_addr: SocketAddr,
_config: Arc<AppConfig>,
_client: Arc<Qdrant>,
_shutdown_signal: Option<oneshot::Receiver<()>>,
_use_tls: bool,
_cert_path: Option<String>,
_key_path: Option<String>,
) -> anyhow::Result<()> {
error!("Server feature not enabled. Compile with --features=server to enable server mode.");
Err(anyhow::anyhow!("Server feature not enabled"))
}
pub async fn start_default_server(
port: u16,
config: Arc<AppConfig>,
client: Arc<Qdrant>,
) -> anyhow::Result<()> {
let addr = format!("0.0.0.0:{}", port).parse()?;
start_server(addr, config, client, None, false, None, None).await
}