feat(server): boot mechanism

This commit is contained in:
hdbg
2026-02-14 23:44:37 +01:00
parent a6c849f268
commit 8263bc6b6f
6 changed files with 81 additions and 15 deletions

View File

@@ -21,6 +21,7 @@ diesel-async = { version = "0.7.4", features = [
ed25519-dalek.workspace = true
arbiter-proto.path = "../arbiter-proto"
tracing.workspace = true
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tonic.workspace = true
tokio.workspace = true
rustls.workspace = true

View File

@@ -11,21 +11,15 @@ use thiserror::Error;
use tokio::sync::RwLock;
use crate::{
context::{
bootstrap::{BootstrapActor, generate_token},
lease::LeaseHandler,
tls::{TlsDataRaw, TlsManager},
},
db::{
actors::bootstrap::{self, BootstrapActor}, context::tls::{TlsDataRaw, TlsManager}, db::{
self,
models::ArbiterSetting,
schema::{self, arbiter_settings},
},
}
};
pub(crate) mod bootstrap;
pub(crate) mod lease;
pub(crate) mod tls;
pub mod tls;
#[derive(Error, Debug, Diagnostic)]
pub enum InitError {
@@ -78,7 +72,7 @@ impl ServerStateMachineContext for _Context {
}
}
pub(crate) struct _ServerContextInner {
pub struct _ServerContextInner {
pub db: db::DatabasePool,
pub state: RwLock<ServerStateMachine<_Context>>,
pub rng: StdRng,
@@ -86,7 +80,7 @@ pub(crate) struct _ServerContextInner {
pub bootstrapper: ActorRef<BootstrapActor>,
}
#[derive(Clone)]
pub(crate) struct ServerContext(Arc<_ServerContextInner>);
pub struct ServerContext(Arc<_ServerContextInner>);
impl std::ops::Deref for ServerContext {
type Target = _ServerContextInner;

View File

@@ -60,7 +60,7 @@ fn generate_cert(key: &KeyPair) -> Result<Certificate, rcgen::Error> {
}
// TODO: Implement cert rotation
pub(crate) struct TlsManager {
pub struct TlsManager {
data: TlsData,
}

View File

@@ -15,8 +15,8 @@ use crate::{
};
pub mod actors;
mod context;
mod db;
pub mod context;
pub mod db;
mod errors;
const DEFAULT_CHANNEL_SIZE: usize = 1000;
@@ -25,6 +25,12 @@ pub struct Server {
context: ServerContext,
}
impl Server {
pub fn new(context: ServerContext) -> Self {
Self { context }
}
}
#[async_trait]
impl arbiter_proto::proto::arbiter_service_server::ArbiterService for Server {
type UserAgentStream = ReceiverStream<Result<UserAgentResponse, Status>>;

View File

@@ -0,0 +1,34 @@
use arbiter_proto::proto::arbiter_service_server::ArbiterServiceServer;
use arbiter_server::{Server, context::ServerContext, db};
use tracing::info;
#[tokio::main]
async fn main() -> miette::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.init();
info!("Starting arbiter server");
info!("Initializing database");
let db = db::create_pool(None).await?;
info!("Database ready");
info!("Initializing server context");
let context = ServerContext::new(db).await?;
info!("Server context ready");
let addr = "[::1]:50051".parse().expect("valid address");
info!(%addr, "Starting gRPC server");
tonic::transport::Server::builder()
.add_service(ArbiterServiceServer::new(Server::new(context)))
.serve(addr)
.await
.map_err(|e| miette::miette!("gRPC server error: {e}"))?;
unreachable!("gRPC server should run indefinitely");
}