diff --git a/Cargo.toml b/Cargo.toml index 4cc519a..ec43140 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ repository = "https://forgejo.fireturlte.net/lazy-supplements" [workspace.dependencies] ciborium = "0.2.2" +clap = { version = "4.5.38", features = ["derive"] } dioxus = { version = "0.6.0", features = [] } lazy-supplements-core.path = "lazy-supplements-core" libp2p = { version = "0.55.0", features = ["macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux" ] } diff --git a/lazy-supplements-core/Cargo.toml b/lazy-supplements-core/Cargo.toml index 05779a3..508cee9 100644 --- a/lazy-supplements-core/Cargo.toml +++ b/lazy-supplements-core/Cargo.toml @@ -8,12 +8,15 @@ repository.workspace = true [features] default = [] +desktop = ["dep:clap"] test = ["dep:tempfile"] [dependencies] base64 = "0.22.1" chrono = "0.4.41" chrono-tz = "0.10.3" +ciborium.workspace = true +clap = {workspace = true, optional = true} futures = "0.3.31" libp2p.workspace = true sea-orm = { version = "1.1.11", features = ["sqlx-sqlite", "runtime-tokio-native-tls", "macros", "with-chrono", "with-uuid"] } diff --git a/lazy-supplements-core/src/config/node.rs b/lazy-supplements-core/src/config/core.rs similarity index 74% rename from lazy-supplements-core/src/config/node.rs rename to lazy-supplements-core/src/config/core.rs index 3040448..5477e86 100644 --- a/lazy-supplements-core/src/config/node.rs +++ b/lazy-supplements-core/src/config/core.rs @@ -1,20 +1,25 @@ use std::{net::IpAddr, ops, path::{Path, PathBuf}}; use base64::{prelude::BASE64_STANDARD, Engine}; +#[cfg(feature="desktop")] +use clap::Args; use libp2p::{identity::{self, DecodingError, Keypair}, noise, ping, tcp, yamux, Swarm}; use serde::{Deserialize, Serialize}; use tokio::{fs::File, io::{AsyncReadExt, AsyncWriteExt}}; use tracing_subscriber::EnvFilter; -use crate::{error::Error, p2p}; +use crate::{ + config::PartialConfig, + error::Error, p2p +}; -use super::{PartialConfig}; - -fn keypair_to_base64(keypair: &Keypair) -> Result { - let vec = keypair.to_protobuf_encoding()?; - let base64 = BASE64_STANDARD.encode(vec); - Ok(base64) +fn keypair_to_base64(keypair: &Keypair) -> String { + let vec = match keypair.to_protobuf_encoding() { + Ok(x) => x, + Err(_) => unreachable!(), + }; + BASE64_STANDARD.encode(vec) } fn base64_to_keypair(base64: &str) -> Result { @@ -23,15 +28,14 @@ fn base64_to_keypair(base64: &str) -> Result { } #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct NodeConfig { +pub struct CoreConfig { #[serde(with = "keypair_parser")] pub secret: Keypair, - pub database_path: PathBuf, pub listen_ips: Vec, pub port: u16, } -impl NodeConfig { +impl CoreConfig { pub async fn try_into_swarm (self) -> Result, Error> { let mut swarm = libp2p::SwarmBuilder::with_existing_identity(self.secret) .with_tokio() @@ -47,12 +51,11 @@ impl NodeConfig { } } -impl TryFrom for NodeConfig { +impl TryFrom for CoreConfig { type Error = Error; - fn try_from(raw: RawNodeConfig) -> Result { - Ok(NodeConfig { + fn try_from(raw: PartialCoreConfig) -> Result { + Ok(CoreConfig { secret: base64_to_keypair(&raw.secret.ok_or(Error::MissingConfig("secret"))?)?, - database_path: raw.database_path.ok_or(Error::MissingConfig("database_path"))?, listen_ips: raw.listen_ips.ok_or(Error::MissingConfig("listen_ips"))?, port: raw.port.ok_or(Error::MissingConfig("port"))? }) @@ -66,10 +69,7 @@ mod keypair_parser { pub fn serialize(keypair: &Keypair, serializer: S) -> Result where S: Serializer { - match super::keypair_to_base64(keypair) { - Ok(x) => serializer.serialize_str(&x), - Err(_) => Err(serde::ser::Error::custom("Decoding keypair error")) - } + serializer.serialize_str(&super::keypair_to_base64(keypair)) } pub fn deserialize<'de, D>(deserializer: D) -> Result where D: Deserializer<'de> @@ -82,35 +82,28 @@ mod keypair_parser { } } +#[cfg_attr(feature="desktop",derive(Args))] #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct RawNodeConfig { +pub struct PartialCoreConfig { + #[cfg_attr(feature="desktop",arg(long))] pub secret: Option, - pub database_path: Option, + #[cfg_attr(feature="desktop",arg(long))] pub listen_ips: Option>, + #[cfg_attr(feature="desktop",arg(long))] pub port: Option, } -impl RawNodeConfig { +impl PartialCoreConfig { pub fn with_new_secret(mut self) -> Self { - self.secret = Some(keypair_to_base64(&Keypair::generate_ed25519()).unwrap()); + self.secret = Some(keypair_to_base64(&Keypair::generate_ed25519())); self } - - pub fn new() -> Self { - RawNodeConfig { - secret: None, - database_path: None, - listen_ips: None, - port: None, - } - } - pub async fn read_or_create(path: T) -> Result where T: AsRef { if !path.as_ref().exists() { - Self::new().write_to(&path).await?; + Self::empty().write_to(&path).await?; } Self::read_from(&path).await } @@ -121,7 +114,7 @@ impl RawNodeConfig { let mut file = File::open(path.as_ref()).await?; let mut content = String::new(); file.read_to_string(&mut content).await?; - let config: RawNodeConfig = toml::from_str(&content)?; + let config: Self = toml::from_str(&content)?; Ok(config) } pub async fn write_to(&self, path:T) -> Result<(), Error> @@ -138,14 +131,29 @@ impl RawNodeConfig { file.write_all(toml::to_string(self)?.as_bytes()).await?; Ok(()) } +} - pub fn merge(&mut self, another: RawNodeConfig) { +impl From for PartialCoreConfig { + fn from(config: CoreConfig) -> Self { + Self { + secret: Some(keypair_to_base64(&config.secret)), + listen_ips: Some(config.listen_ips), + port: Some(config.port) + } + } +} +impl PartialConfig for PartialCoreConfig { + fn empty() -> Self { + Self { + secret: None, + listen_ips: None, + port: None, + } + } + fn merge(&mut self, another: Self) { if let Some(x) = another.secret { self.secret = Some(x); }; - if let Some(x) = another.database_path { - self.database_path = Some(x); - }; if let Some(x) = another.listen_ips { self.listen_ips = Some(x); }; @@ -153,18 +161,12 @@ impl RawNodeConfig { self.port = Some(x); }; } -} - -impl ops::Add for RawNodeConfig { - type Output = RawNodeConfig; - fn add(mut self, another: RawNodeConfig) -> RawNodeConfig { - self.merge(another); - self + + fn default() -> Self { + todo!() } } - - #[cfg(test)] mod tests { use libp2p::identity; @@ -174,7 +176,7 @@ mod tests { #[tokio::test] async fn parse_keypair() { let keypair = identity::Keypair::generate_ed25519(); - let keypair2 = base64_to_keypair(&keypair_to_base64(&keypair).unwrap()).unwrap(); + let keypair2 = base64_to_keypair(&keypair_to_base64(&keypair)).unwrap(); assert_eq!(keypair.public(), keypair2.public()); } diff --git a/lazy-supplements-core/src/config/error.rs b/lazy-supplements-core/src/config/error.rs new file mode 100644 index 0000000..27f7e56 --- /dev/null +++ b/lazy-supplements-core/src/config/error.rs @@ -0,0 +1,5 @@ +#[derive(thiserror::Error, Debug)] +pub enum ConfigError { + #[error("missing config: {0}")] + MissingConfig(String), +} \ No newline at end of file diff --git a/lazy-supplements-core/src/config/mod.rs b/lazy-supplements-core/src/config/mod.rs index 4c823ad..41d9304 100644 --- a/lazy-supplements-core/src/config/mod.rs +++ b/lazy-supplements-core/src/config/mod.rs @@ -1,14 +1,55 @@ -mod node; +pub mod error; +mod core; use std::path::Path; use crate::error::Error; -pub use node::{ NodeConfig, RawNodeConfig }; -use serde::{Deserialize, Serialize}; +pub use core::{ CoreConfig, PartialCoreConfig }; +pub use error::ConfigError; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; use tokio::{fs::File, io::{AsyncReadExt, AsyncWriteExt}}; -#[derive(Debug, Deserialize, Serialize)] -pub struct PartialConfig { - node: Option, + +pub trait PartialConfig: From +where T: TryFrom { + fn default() -> Self; + fn empty() -> Self; + fn merge(&mut self, other: Self); } +pub trait ConfigFile: DeserializeOwned + Serialize { + fn new() -> Self; + async fn read_or_create(path: T) -> Result + where + T: AsRef + { + if !path.as_ref().exists() { + Self::new().write_to(&path).await?; + } + Self::read_from(&path).await + } + async fn read_from(path:T) -> Result + where + T: AsRef + { + let mut file = File::open(path.as_ref()).await?; + let mut content = String::new(); + file.read_to_string(&mut content).await?; + let config: Self = toml::from_str(&content)?; + Ok(config) + } + async fn write_to(&self, path:T) -> Result<(), Error> + where + T: AsRef + { + if !path.as_ref().exists() { + if let Some(x) = path.as_ref().parent() { + std::fs::create_dir_all(x)?; + }; + let _ = File::create(&path).await?; + } + let mut file = File::create(&path).await?; + file.write_all(toml::to_string(self)?.as_bytes()).await?; + Ok(()) + } +} \ No newline at end of file diff --git a/lazy-supplements-core/src/error.rs b/lazy-supplements-core/src/error.rs index 376b3e4..2fded2a 100644 --- a/lazy-supplements-core/src/error.rs +++ b/lazy-supplements-core/src/error.rs @@ -2,6 +2,10 @@ pub enum Error { #[error("Base64 decode error: {0}")] Base64Decode(#[from] base64::DecodeError), + #[error(transparent)] + CiborDeserialize(#[from] ciborium::de::Error), + #[error(transparent)] + CiborSerialize(#[from] ciborium::ser::Error), #[error("DB Error: {0}")] Db(#[from]sea_orm::DbErr), #[error("Dial Error: {0}")] @@ -18,10 +22,13 @@ pub enum Error { Multiaddr(#[from] libp2p::multiaddr::Error), #[error("Noise error: {0}")] Noise(#[from] libp2p::noise::Error), + #[cfg(feature="desktop")] + #[error("Parse args error: {0}")] + ParseCommand(#[from] clap::Error), #[error("toml deserialization error: {0}")] TomlDe(#[from] toml::de::Error), #[error("toml serialization error: {0}")] - TomlSer(#[from] toml::ser::Error), + TomlSer(#[from] toml::ser::Error), #[error("Transport error: {0}")] Transport(#[from]libp2p::TransportError) } \ No newline at end of file diff --git a/lazy-supplements-core/src/global/mod.rs b/lazy-supplements-core/src/global/mod.rs index 7a470d1..7184b2e 100644 --- a/lazy-supplements-core/src/global/mod.rs +++ b/lazy-supplements-core/src/global/mod.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, net::{IpAddr, Ipv4Addr}, path::{Path, PathBuf}, sync::LazyLock}; -use crate::{config::{NodeConfig, RawNodeConfig}, error::Error}; +use crate::{config::{CoreConfig, PartialCoreConfig}, error::Error}; use futures::StreamExt; use libp2p::{swarm::SwarmEvent, Multiaddr, PeerId}; use sea_orm::{prelude::*, Database}; @@ -33,25 +33,25 @@ pub static DEFAULT_DATABASE_FILE_NAME: LazyLock = LazyLock::new(|| { pub static GLOBAL: Global = Global{ - node_config: OnceCell::const_new(), + core_config: OnceCell::const_new(), main_database: OnceCell::const_new(), cache_database: OnceCell::const_new(), peers: OnceCell::const_new(), }; pub struct Global { - pub node_config: OnceCell, + pub core_config: OnceCell, pub main_database: OnceCell, pub cache_database: OnceCell, pub peers: OnceCell>>, } impl Global { - pub fn get_node_config(&self) -> Option<&NodeConfig> { - self.node_config.get() + pub fn get_core_config(&self) -> Option<&CoreConfig> { + self.core_config.get() } - pub async fn get_or_init_node_config(&self, config: NodeConfig) -> &NodeConfig { - self.node_config.get_or_init(|| async {config}).await + pub async fn get_or_init_core_config(&self, config: CoreConfig) -> &CoreConfig { + self.core_config.get_or_init(|| async {config}).await } pub async fn get_or_init_peers(&self) -> &RwLock> { self.peers.get_or_init(|| async { @@ -65,7 +65,7 @@ impl Global { self.get_or_init_peers().await.write().await } pub async fn launch_swarm(&self) -> Result<(), Error> { - let mut swarm = self.get_node_config().unwrap().clone().try_into_swarm().await?; + let mut swarm = self.get_core_config().unwrap().clone().try_into_swarm().await?; loop{ let swarm_event = swarm.select_next_some().await; tokio::spawn(async move{ diff --git a/lazy-supplements-desktop/Cargo.toml b/lazy-supplements-desktop/Cargo.toml index ddaafc4..6e0c3c7 100644 --- a/lazy-supplements-desktop/Cargo.toml +++ b/lazy-supplements-desktop/Cargo.toml @@ -12,9 +12,9 @@ test = ["lazy-supplements-core/test"] [dependencies] ciborium.workspace = true -clap = { version = "4.5.38", features = ["derive"] } +clap.workspace = true dirs = "6.0.0" -lazy-supplements-core.workspace = true +lazy-supplements-core = { workspace = true, features = ["desktop"] } libp2p.workspace = true serde.workspace = true thiserror.workspace = true diff --git a/lazy-supplements-desktop/src/cli/config.rs b/lazy-supplements-desktop/src/cli/config.rs index b3e1e23..4f2bc0e 100644 --- a/lazy-supplements-desktop/src/cli/config.rs +++ b/lazy-supplements-desktop/src/cli/config.rs @@ -1,19 +1,22 @@ use std::{net::IpAddr, path::PathBuf}; use clap::Args; -use lazy_supplements_core::config::RawNodeConfig; +use lazy_supplements_core::config::{PartialConfig, PartialCoreConfig}; use serde::{Deserialize, Serialize}; -use crate::{config::NodeConfig, error::Error, global::{DEFAULT_CONFIG_FILE_PATH, DEFAULT_RAW_NODE_CONFIG}}; +use crate::{config::{desktop::PartialDesktopConfig, CoreConfig}, error::Error, global::{DEFAULT_CONFIG_FILE_PATH, DEFAULT_PARTIAL_CORE_CONFIG,}}; #[derive(Args, Clone, Debug)] pub struct ConfigArgs { #[arg(long)] pub config: Option, #[command(flatten)] - pub config_values: ConfigValueArgs, + pub core_config: PartialCoreConfig, + #[command(flatten)] + pub desktop_config: PartialDesktopConfig, } + impl ConfigArgs { pub fn get_config_path_or_default(&self) -> PathBuf { if let Some(x) = self.config.as_ref() { @@ -22,33 +25,14 @@ impl ConfigArgs { DEFAULT_CONFIG_FILE_PATH.to_path_buf() } } - pub async fn try_into_raw_node_config(self) -> Result { - Ok(RawNodeConfig::read_from(self.get_config_path_or_default()).await? + self.config_values.into()) + pub async fn try_into_partial_core_config(self) -> Result { + let mut config = PartialCoreConfig::read_from(self.get_config_path_or_default()).await?; + config.merge(self.core_config.into()); + Ok(config) } - pub async fn try_into_node_config(self) -> Result { - Ok((DEFAULT_RAW_NODE_CONFIG.clone() + self.try_into_raw_node_config().await?).try_into()?) + pub async fn try_into_core_config(self) -> Result { + let mut config = DEFAULT_PARTIAL_CORE_CONFIG.clone(); + config.merge(self.try_into_partial_core_config().await?); + config.try_into() } } - -#[derive(Args, Clone, Debug, Deserialize, Serialize)] -pub struct ConfigValueArgs { - #[arg(skip)] - pub secret: Option, - #[arg(long)] - pub database_path: Option, - #[arg(long)] - pub listen_ips: Option>, - #[arg(long)] - pub port: Option, -} - -impl Into for ConfigValueArgs { - fn into(self) -> RawNodeConfig { - RawNodeConfig { - secret : self.secret, - database_path: self.database_path, - listen_ips: self.listen_ips, - port: self.port - } - } -} \ No newline at end of file diff --git a/lazy-supplements-desktop/src/cli/node.rs b/lazy-supplements-desktop/src/cli/node.rs index 81e430b..be048b2 100644 --- a/lazy-supplements-desktop/src/cli/node.rs +++ b/lazy-supplements-desktop/src/cli/node.rs @@ -5,7 +5,7 @@ use libp2p::{ multiaddr::Protocol, noise, ping, swarm::SwarmEvent, tcp, yamux, Multiaddr, PeerId }; -use crate::{cli::ServerArgs, error::{CoreError, DesktopError, Error}}; +use crate::{cli::ServerArgs, error::Error}; use super::ConfigArgs; diff --git a/lazy-supplements-desktop/src/cli/server.rs b/lazy-supplements-desktop/src/cli/server.rs index cfd1b3b..337de7a 100644 --- a/lazy-supplements-desktop/src/cli/server.rs +++ b/lazy-supplements-desktop/src/cli/server.rs @@ -1,7 +1,7 @@ use clap::Args; use libp2p::{noise, ping, swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, Swarm}; -use crate::{error::Error, global::GLOBAL, error::CoreError}; +use crate::{error::Error, global::GLOBAL}; use super::ConfigArgs; @@ -12,7 +12,7 @@ pub struct ServerArgs { } impl ServerArgs { pub async fn start_server(self) -> Result<(), Error>{ - let _ = crate::global::GLOBAL.get_or_init_node_config(self.config.try_into_node_config().await?).await; - GLOBAL.launch_swarm().await.or_else(|e| {Err(Error::from(CoreError::from(e)))}) + let _ = crate::global::GLOBAL.get_or_init_core_config(self.config.try_into_core_config().await?).await; + GLOBAL.launch_swarm().await } } \ No newline at end of file diff --git a/lazy-supplements-desktop/src/config/desktop.rs b/lazy-supplements-desktop/src/config/desktop.rs new file mode 100644 index 0000000..8d065ba --- /dev/null +++ b/lazy-supplements-desktop/src/config/desktop.rs @@ -0,0 +1,77 @@ +use std::path::PathBuf; + +use clap::Args; +use lazy_supplements_core::config::{ConfigError, PartialConfig}; +use libp2p::mdns::Config; +use serde::{Deserialize, Serialize}; + +pub struct DesktopConfig { + pub data_directory: PathBuf, + pub data_database: PathBuf, + pub cache_directory: PathBuf, + pub cache_database: PathBuf, +} + +impl TryFrom for DesktopConfig { + type Error = ConfigError; + + fn try_from(value: PartialDesktopConfig) -> Result { + Ok(Self { + data_directory: value.data_directory.ok_or(ConfigError::MissingConfig("data_directory".to_string()))?, + data_database: value.data_database.ok_or(ConfigError::MissingConfig("data_database".to_string()))?, + cache_directory: value.cache_directory.ok_or(ConfigError::MissingConfig("cache_directory".to_string()))?, + cache_database: value.cache_database.ok_or(ConfigError::MissingConfig("cache_database".to_string()))?, + }) + } +} + +#[derive(Args, Clone, Debug, Deserialize, Serialize)] +pub struct PartialDesktopConfig { + #[arg(long)] + pub data_directory: Option, + #[arg(long)] + pub data_database: Option, + #[arg(long)] + pub cache_directory: Option, + #[arg(long)] + pub cache_database: Option, +} + +impl From for PartialDesktopConfig { + fn from(config: DesktopConfig) -> PartialDesktopConfig { + Self { + data_database: Some(config.data_database), + data_directory: Some(config.data_directory), + cache_database: Some(config.cache_database), + cache_directory: Some(config.cache_directory), + } + } +} + +impl PartialConfig for PartialDesktopConfig { + fn empty() -> Self { + Self{ + data_database: None, + cache_database: None, + data_directory: None, + cache_directory: None, + } + } + fn default() -> Self { + todo!() + } + fn merge(&mut self, other: Self) { + if let Some(x) = other.data_directory { + self.data_directory = Some(x); + } + if let Some(x) = other.data_database { + self.data_database = Some(x); + } + if let Some(x) = other.cache_directory { + self.cache_directory = Some(x); + } + if let Some(x) = other.cache_database { + self.cache_database = Some(x); + } + } +} \ No newline at end of file diff --git a/lazy-supplements-desktop/src/config/mod.rs b/lazy-supplements-desktop/src/config/mod.rs new file mode 100644 index 0000000..c64446b --- /dev/null +++ b/lazy-supplements-desktop/src/config/mod.rs @@ -0,0 +1,15 @@ +#[cfg(unix)] +pub mod unix; + +#[cfg(windows)] +pub mod windows; +pub mod desktop; +pub use lazy_supplements_core::config::*; + + + +#[cfg(unix)] +pub use unix::*; + +#[cfg(windows)] +pub use windows::*; \ No newline at end of file diff --git a/lazy-supplements-desktop/src/config/unix.rs b/lazy-supplements-desktop/src/config/unix.rs new file mode 100644 index 0000000..3ff4af3 --- /dev/null +++ b/lazy-supplements-desktop/src/config/unix.rs @@ -0,0 +1,48 @@ +use std::path::PathBuf; +use clap::Args; +use lazy_supplements_core::config::PartialConfig; +use libp2p::mdns::Config; +use serde::{Deserialize, Serialize}; + +use crate::config::error::ConfigError; + + +pub struct UnixConfig { + pub socket_path: PathBuf, +} + +impl TryFrom for UnixConfig { + type Error = ConfigError; + fn try_from(config: PartialUnixConfig) -> Result { + Ok(Self{ + socket_path: config.socket_path.ok_or(ConfigError::MissingConfig("socket_path".to_string()))? + }) + } +} + +#[derive(Args, Clone, Debug, Deserialize, Serialize)] +pub struct PartialUnixConfig { + pub socket_path: Option, +} + +impl From for PartialUnixConfig { + fn from(source: UnixConfig) -> Self { + Self { + socket_path: Some(source.socket_path) + } + } +} + +impl PartialConfig for PartialUnixConfig { + fn empty() -> Self { + Self { socket_path: None } + } + fn default() -> Self { + todo!() + } + fn merge(&mut self, other: Self) { + if let Some(x) = other.socket_path { + self.socket_path = Some(x); + }; + } +} \ No newline at end of file diff --git a/lazy-supplements-desktop/src/config/windows.rs b/lazy-supplements-desktop/src/config/windows.rs new file mode 100644 index 0000000..d9a6589 --- /dev/null +++ b/lazy-supplements-desktop/src/config/windows.rs @@ -0,0 +1,3 @@ +pub struct WindowsConfig { + pub pipe_name: String +} diff --git a/lazy-supplements-desktop/src/error.rs b/lazy-supplements-desktop/src/error.rs deleted file mode 100644 index 29fd02d..0000000 --- a/lazy-supplements-desktop/src/error.rs +++ /dev/null @@ -1,16 +0,0 @@ -pub use lazy_supplements_core::error::Error as CoreError; - -#[derive(thiserror::Error, Debug)] -pub enum DesktopError { - #[error("Parse args error: {0}")] - ParseCommand(#[from] clap::Error), -} - -#[derive(thiserror::Error, Debug)] -pub enum Error { - #[error("{0}")] - Core(#[from] CoreError), - #[error("{0}")] - Desktop(#[from] DesktopError), -} - diff --git a/lazy-supplements-desktop/src/global.rs b/lazy-supplements-desktop/src/global.rs index 90ac30f..b5024b5 100644 --- a/lazy-supplements-desktop/src/global.rs +++ b/lazy-supplements-desktop/src/global.rs @@ -1,6 +1,6 @@ use std::{path::PathBuf, sync::LazyLock}; -use lazy_supplements_core::config::RawNodeConfig; +use lazy_supplements_core::config::PartialCoreConfig; pub use lazy_supplements_core::global::*; pub static DEFAULT_DATA_DIR_PATH: LazyLock = LazyLock::new(|| { @@ -29,10 +29,9 @@ pub static DEFAULT_DATABASE_FILE_PATH: LazyLock = LazyLock::new(|| { DEFAULT_DATA_DIR_PATH.join(&*DEFAULT_DATABASE_FILE_NAME) }); -pub static DEFAULT_RAW_NODE_CONFIG: LazyLock = LazyLock::new(|| { - RawNodeConfig { +pub static DEFAULT_PARTIAL_CORE_CONFIG: LazyLock = LazyLock::new(|| { + PartialCoreConfig { secret: None, - database_path: Some(DEFAULT_DATABASE_FILE_PATH.to_path_buf()), listen_ips: Some(DEFAULT_LISTEN_IPS.to_vec()), port: Some(0), } diff --git a/lazy-supplements-desktop/src/lib.rs b/lazy-supplements-desktop/src/lib.rs index 1b0e39c..bfa056c 100644 --- a/lazy-supplements-desktop/src/lib.rs +++ b/lazy-supplements-desktop/src/lib.rs @@ -1,9 +1,9 @@ pub mod cli; -pub mod error; +pub mod config; pub mod global; pub mod ipc; pub use lazy_supplements_core::{ cache, - config, data, + error, }; diff --git a/lazy-supplements-desktop/src/main.rs b/lazy-supplements-desktop/src/main.rs index 5c8317b..a3b3f69 100644 --- a/lazy-supplements-desktop/src/main.rs +++ b/lazy-supplements-desktop/src/main.rs @@ -19,7 +19,7 @@ enum Command { #[tokio::main] async fn main() { let cli = Cli::parse(); - let _ = GLOBAL.get_or_init_node_config(cli.config.try_into_node_config().await.unwrap()).await; + let _ = GLOBAL.get_or_init_core_config(cli.config.try_into_core_config().await.unwrap()).await; match cli.command { Command::Node(x) => x.run().await.unwrap(), Command::Server(x) => x.start_server().await.unwrap(),