feat(server): boot mechanism
This commit is contained in:
31
server/Cargo.lock
generated
31
server/Cargo.lock
generated
@@ -87,6 +87,7 @@ dependencies = [
|
|||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tonic",
|
"tonic",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1340,6 +1341,15 @@ dependencies = [
|
|||||||
"minimal-lexical",
|
"minimal-lexical",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nu-ansi-term"
|
||||||
|
version = "0.50.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-bigint"
|
name = "num-bigint"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -2393,6 +2403,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"valuable",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-log"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"once_cell",
|
||||||
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2402,12 +2424,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
|
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"matchers",
|
"matchers",
|
||||||
|
"nu-ansi-term",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"regex-automata",
|
"regex-automata",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
|
"smallvec",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2480,6 +2505,12 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "valuable"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "vcpkg"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ diesel-async = { version = "0.7.4", features = [
|
|||||||
ed25519-dalek.workspace = true
|
ed25519-dalek.workspace = true
|
||||||
arbiter-proto.path = "../arbiter-proto"
|
arbiter-proto.path = "../arbiter-proto"
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
tonic.workspace = true
|
tonic.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
rustls.workspace = true
|
rustls.workspace = true
|
||||||
|
|||||||
@@ -11,21 +11,15 @@ use thiserror::Error;
|
|||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::{
|
actors::bootstrap::{self, BootstrapActor}, context::tls::{TlsDataRaw, TlsManager}, db::{
|
||||||
bootstrap::{BootstrapActor, generate_token},
|
|
||||||
lease::LeaseHandler,
|
|
||||||
tls::{TlsDataRaw, TlsManager},
|
|
||||||
},
|
|
||||||
db::{
|
|
||||||
self,
|
self,
|
||||||
models::ArbiterSetting,
|
models::ArbiterSetting,
|
||||||
schema::{self, arbiter_settings},
|
schema::{self, arbiter_settings},
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) mod bootstrap;
|
|
||||||
pub(crate) mod lease;
|
pub mod tls;
|
||||||
pub(crate) mod tls;
|
|
||||||
|
|
||||||
#[derive(Error, Debug, Diagnostic)]
|
#[derive(Error, Debug, Diagnostic)]
|
||||||
pub enum InitError {
|
pub enum InitError {
|
||||||
@@ -78,7 +72,7 @@ impl ServerStateMachineContext for _Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct _ServerContextInner {
|
pub struct _ServerContextInner {
|
||||||
pub db: db::DatabasePool,
|
pub db: db::DatabasePool,
|
||||||
pub state: RwLock<ServerStateMachine<_Context>>,
|
pub state: RwLock<ServerStateMachine<_Context>>,
|
||||||
pub rng: StdRng,
|
pub rng: StdRng,
|
||||||
@@ -86,7 +80,7 @@ pub(crate) struct _ServerContextInner {
|
|||||||
pub bootstrapper: ActorRef<BootstrapActor>,
|
pub bootstrapper: ActorRef<BootstrapActor>,
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct ServerContext(Arc<_ServerContextInner>);
|
pub struct ServerContext(Arc<_ServerContextInner>);
|
||||||
|
|
||||||
impl std::ops::Deref for ServerContext {
|
impl std::ops::Deref for ServerContext {
|
||||||
type Target = _ServerContextInner;
|
type Target = _ServerContextInner;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ fn generate_cert(key: &KeyPair) -> Result<Certificate, rcgen::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement cert rotation
|
// TODO: Implement cert rotation
|
||||||
pub(crate) struct TlsManager {
|
pub struct TlsManager {
|
||||||
data: TlsData,
|
data: TlsData,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub mod actors;
|
pub mod actors;
|
||||||
mod context;
|
pub mod context;
|
||||||
mod db;
|
pub mod db;
|
||||||
mod errors;
|
mod errors;
|
||||||
|
|
||||||
const DEFAULT_CHANNEL_SIZE: usize = 1000;
|
const DEFAULT_CHANNEL_SIZE: usize = 1000;
|
||||||
@@ -25,6 +25,12 @@ pub struct Server {
|
|||||||
context: ServerContext,
|
context: ServerContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Server {
|
||||||
|
pub fn new(context: ServerContext) -> Self {
|
||||||
|
Self { context }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl arbiter_proto::proto::arbiter_service_server::ArbiterService for Server {
|
impl arbiter_proto::proto::arbiter_service_server::ArbiterService for Server {
|
||||||
type UserAgentStream = ReceiverStream<Result<UserAgentResponse, Status>>;
|
type UserAgentStream = ReceiverStream<Result<UserAgentResponse, Status>>;
|
||||||
|
|||||||
34
server/crates/arbiter-server/src/main.rs
Normal file
34
server/crates/arbiter-server/src/main.rs
Normal 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");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user