mod branch; mod config; use actix::prelude::*; use kxio::network::Network; use tracing::info; use crate::server::config::{RepoConfig, RepoDetails}; pub struct RepoActor { details: RepoDetails, config: Option, // INFO: if [None] then send [StartRepo] to populate it net: Network, } impl RepoActor { pub(crate) const fn new(details: RepoDetails, net: Network) -> Self { Self { details, config: None, net, } } } impl Actor for RepoActor { type Context = Context; } #[derive(Message)] #[rtype(result = "()")] pub struct StartRepo; impl Handler for RepoActor { type Result = (); fn handle(&mut self, _msg: StartRepo, ctx: &mut Self::Context) -> Self::Result { info!(%self.details, "Starting Repo"); let details = self.details.clone(); let addr = ctx.address(); let net = self.net.clone(); config::load(details, addr, net).into_actor(self).wait(ctx); } } #[derive(Message)] #[rtype(result = "()")] struct LoadedConfig(pub RepoConfig); impl Handler for RepoActor { type Result = (); fn handle(&mut self, msg: LoadedConfig, ctx: &mut Self::Context) -> Self::Result { let config = msg.0; info!(%self.details, %config, "Config loaded"); self.config.replace(config.clone()); let addr = ctx.address(); let net = self.net.clone(); branch::validate_positions(config, addr, net) .into_actor(self) .wait(ctx); } }