Skip to main content

wowlab_node/
lib.rs

1//! Shared library for distributed simulation nodes.
2
3#![expect(
4    clippy::multiple_crate_versions,
5    reason = "the engine, updater, and network stacks currently resolve independently versioned transitive crates"
6)]
7
8/// Crate version.
9pub const VERSION: &str = env!("CARGO_PKG_VERSION");
10
11mod claim;
12mod config;
13mod core;
14mod realtime;
15mod sentinel;
16mod update;
17mod utils;
18mod work_context;
19mod worker;
20
21use wowlab_common::time::Instant;
22
23#[rustfmt::skip]
24#[doc(inline)]
25pub use claim::validate_token as validate_claim_token;
26#[rustfmt::skip]
27#[doc(inline)]
28pub use config::{NodeConfig, NodeConfigError};
29#[rustfmt::skip]
30#[doc(inline)]
31pub use sentinel::SentinelError;
32#[rustfmt::skip]
33#[doc(inline)]
34pub use update::{UpdateError, check_for_update, install_update};
35#[rustfmt::skip]
36#[doc(inline)]
37pub use utils::logging::{
38    LoggingGuard, UiLogEntry, init_headless_logging, init_ui_logging, log_dir,
39};
40#[rustfmt::skip]
41#[doc(inline)]
42pub use work_context::WorkContext;
43#[rustfmt::skip]
44#[doc(inline)]
45pub use worker::{WorkBatch, WorkBatchResult, WorkerPool};
46
47#[rustfmt::skip]
48#[doc(inline)]
49pub use crate::core::{
50    LocalIdentityOutcome, NodeApplication, NodeCore, NodeCoreEvent, NodeEvents,
51    RemoteUnlinkOutcome, UnlinkError, UnlinkErrorCategory, UnlinkOutcome,
52};
53
54/// Runtime statistics for UI display.
55#[derive(Clone, Debug, Default)]
56pub struct NodeStats {
57    pub active_jobs: u32,
58    pub completed_chunks: u64,
59    pub sims_per_second: f64,
60    pub busy_workers: u32,
61    pub max_workers: u32,
62    pub total_cores: u32,
63    pub cpu_usage: f32,
64}
65
66/// Log entry for UI display.
67#[derive(Clone, Debug)]
68pub struct LogEntry {
69    pub timestamp: Instant,
70    pub level: LogLevel,
71    pub message: String,
72}
73
74/// Log level for UI display.
75#[derive(Clone, Copy, Debug, Default, PartialEq)]
76// #t(rust_non_exhaustive_on_public) fixed log levels matched exhaustively in node-gui
77pub enum LogLevel {
78    #[default]
79    Info,
80    Warn,
81    Error,
82    Debug,
83}
84
85/// Node lifecycle state.
86// docref:start hosted-compute-node-state
87#[derive(Clone, Debug, Eq, PartialEq)]
88// #t(rust_non_exhaustive_on_public) internal state enum matched exhaustively in node-headless and node-gui
89pub enum NodeState {
90    Setup,
91    Verifying,
92    Registering,
93    Running,
94    NotFound,
95    Unavailable,
96    Unlinking,
97    Unlinked,
98}
99// docref:end hosted-compute-node-state
100
101/// Realtime connection status.
102#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
103// #t(rust_non_exhaustive_on_public) internal enum matched exhaustively in node-headless and node-gui
104pub enum ConnectionStatus {
105    #[default]
106    Connecting,
107    Connected,
108    Disconnected,
109}