caretta-sync/lazy-supplements-core/src/global/mod.rs

50 lines
1.6 KiB
Rust
Raw Normal View History

2025-06-10 07:47:37 +09:00
use std::{collections::HashMap, net::{IpAddr, Ipv4Addr}, path::{Path, PathBuf}, sync::LazyLock};
2025-05-30 09:26:47 +09:00
2025-06-19 07:24:44 +09:00
use crate::{config::{P2pConfig, PartialP2pConfig, StorageConfig}, error::Error};
2025-06-05 09:23:24 +09:00
use futures::StreamExt;
use libp2p::{swarm::SwarmEvent, Multiaddr, PeerId};
2025-06-10 07:47:37 +09:00
use sea_orm::{prelude::*, Database};
use sea_orm_migration::MigratorTrait;
2025-06-04 07:13:37 +09:00
use tokio::sync::{OnceCell, RwLock};
2025-05-25 17:19:37 +09:00
2025-06-19 07:24:44 +09:00
mod peers;
pub use peers::GlobalPeers;
mod storage_config;
mod database_connection;
pub use database_connection::GlobalDatabaseConnection;
2025-06-17 07:20:24 +09:00
use uuid::{ContextV7, Timestamp, Uuid};
pub fn generate_uuid() -> Uuid {
Uuid::new_v7(Timestamp::now(ContextV7::new()))
}
2025-05-25 17:19:37 +09:00
2025-05-30 09:26:47 +09:00
pub static PRODUCT_NAME: LazyLock<String> = LazyLock::new(|| {
env!("CARGO_PKG_NAME").to_string()
});
2025-06-01 15:18:17 +09:00
pub static DEFAULT_LISTEN_IPS: &[IpAddr] = &[IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))];
2025-05-30 09:26:47 +09:00
pub static DEFAULT_CONFIG_FILE_NAME: LazyLock<PathBuf> = LazyLock::new(|| {
PathBuf::from(String::new() + env!("CARGO_PKG_NAME") + ".toml")
});
pub static DEFAULT_DATABASE_FILE_NAME: LazyLock<PathBuf> = LazyLock::new(|| {
PathBuf::from(String::new() + env!("CARGO_PKG_NAME") + ".sqlite")
});
2025-06-19 07:24:44 +09:00
#[cfg(any(test, feature="test"))]
pub struct TestGlobal {
p2p_config: OnceCell<P2pConfig>,
storage_config: OnceCell<StorageConfig>,
data_database_connection: OnceCell<DatabaseConnection>,
cache_database_connection: OnceCell<DatabaseConnection>,
2025-06-10 07:47:37 +09:00
}
2025-06-19 07:24:44 +09:00
#[cfg(any(test, feature="test"))]
pub static GLOBAL: TestGlobal = TestGlobal{
p2p_config: OnceCell::const_new(),
storage_config: OnceCell::const_new(),
data_database_connection: OnceCell::const_new(),
cache_database_connection: OnceCell::const_new(),
};