diff --git a/crates/lavina-core/src/clustering.rs b/crates/lavina-core/src/clustering.rs index 524087f..6431a27 100644 --- a/crates/lavina-core/src/clustering.rs +++ b/crates/lavina-core/src/clustering.rs @@ -20,8 +20,9 @@ pub struct ClusterConfig { #[derive(Deserialize, Debug, Clone)] pub struct ClusterMetadata { + /// The node id of the current node. pub node_id: u32, - /// Owns all rooms and players in the cluster. + /// Owns all rooms in the cluster except the ones specified in `rooms`. pub main_owner: u32, pub rooms: HashMap, } @@ -46,7 +47,13 @@ impl LavinaClient { return Err(anyhow!("Unknown node")); }; match self.client.post(format!("http://{}{}", address, path)).json(&req).send().await { - Ok(_) => Ok(()), + Ok(res) => { + if res.status().is_server_error() || res.status().is_client_error() { + tracing::error!("Cluster request failed: {:?}", res); + return Err(anyhow!("Server error")); + } + Ok(()) + } Err(e) => Err(e.into()), } } diff --git a/src/http/clustering.rs b/src/http/clustering.rs index df2605c..0314dd6 100644 --- a/src/http/clustering.rs +++ b/src/http/clustering.rs @@ -10,6 +10,8 @@ use lavina_core::repo::Storage; use lavina_core::room::RoomId; use lavina_core::LavinaCore; +// TODO move this into core + pub async fn route( core: &LavinaCore, storage: &Storage,