From a26162dbcaf54edd1cf075688d1849cfc7c1bb80 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Fri, 8 Dec 2023 15:13:34 +0100 Subject: [PATCH] core: add configuration for clustering --- config.toml | 6 +++++ crates/lavina-core/src/clustering/mod.rs | 34 ++++++++++++++++++++++++ crates/lavina-core/src/lib.rs | 1 + src/main.rs | 2 ++ 4 files changed, 43 insertions(+) create mode 100644 crates/lavina-core/src/clustering/mod.rs diff --git a/config.toml b/config.toml index 6104dce..84fe4ea 100644 --- a/config.toml +++ b/config.toml @@ -12,3 +12,9 @@ key = "./certs/xmpp.key" [storage] db_path = "db.sqlite" + +[clustering] +self_id = 1 +listen_on = "0.0.0.0:23732" +advertised_address = "127.0.0.1:23732" +bootstrap_via = ["0.0.0.0:23733"] diff --git a/crates/lavina-core/src/clustering/mod.rs b/crates/lavina-core/src/clustering/mod.rs new file mode 100644 index 0000000..98a0187 --- /dev/null +++ b/crates/lavina-core/src/clustering/mod.rs @@ -0,0 +1,34 @@ +use std::net::SocketAddr; + +use anyhow::Result; +use serde::Deserialize; + +#[derive(Deserialize, Debug, Clone)] +pub struct ClusteringConfig { + /// The unique identifier of the node in the cluster, needed to distinguish it form other nodes. + pub self_id: u32, + /// The local address where this node listens incoming for node-to-node communication. + pub listen_on: SocketAddr, + /// This address is advertised via a gossip mechanism and used by other nodes in the cluster to communicate with this node. + /// + /// This is useful when a node is behind a NAT or a proxy, where the publicly accessible IP + /// address can differ from the local IP address. + pub advertised_address: SocketAddr, + /// A list of network addresses with the node's initial set of peers in the cluster. + /// These nodes will be contacted first in order to discover additional nodes and to initialize the local state. + pub bootstrap_via: Box<[SocketAddr]>, +} + +/// Cluster registry is a service which handles all connections to other nodes of the cluster. +/// +/// It maintains the local view of the cluster state, including the set of nodes, +/// the status of each node and the shard allocation metadata. +struct ClusterRegistry {} + +impl ClusterRegistry { + /// Creates a new cluster registry and launches all necessary daemon fibers. + pub async fn launch(config: ClusteringConfig) -> Result { + todo!() + } +} + diff --git a/crates/lavina-core/src/lib.rs b/crates/lavina-core/src/lib.rs index 401e49e..e9ea057 100644 --- a/crates/lavina-core/src/lib.rs +++ b/crates/lavina-core/src/lib.rs @@ -4,5 +4,6 @@ pub mod prelude; pub mod repo; pub mod room; pub mod terminator; +pub mod clustering; mod table; diff --git a/src/main.rs b/src/main.rs index 53d7c21..0bcc612 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ struct ServerConfig { irc: projection_irc::ServerConfig, xmpp: projection_xmpp::ServerConfig, storage: lavina_core::repo::StorageConfig, + clustering: lavina_core::clustering::ClusteringConfig, } #[derive(Parser)] @@ -48,6 +49,7 @@ async fn main() -> Result<()> { irc: irc_config, xmpp: xmpp_config, storage: storage_config, + clustering: clustering_config, } = config; let mut metrics = MetricsRegistry::new(); let storage = Storage::open(storage_config).await?;