Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ uninlined_format_args = "warn"

[workspace.lints.rust]
unreachable_pub = "warn"
manual_let_else = "warn"
manual_let_else = "warn"
2 changes: 1 addition & 1 deletion crates/worker/src/checks/hardware/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct GpuDevice {
indices: Vec<u32>,
}

pub fn detect_gpu() -> Vec<GpuSpecs> {
pub(crate) fn detect_gpu() -> Vec<GpuSpecs> {
Console::title("GPU Detection");

let gpu_devices = get_gpu_status();
Expand Down
6 changes: 3 additions & 3 deletions crates/worker/src/checks/hardware/hardware_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use std::sync::Arc;
use sysinfo::{self, System};
use tokio::sync::RwLock;

pub struct HardwareChecker {
pub(crate) struct HardwareChecker {
sys: System,
issues: Arc<RwLock<IssueReport>>,
}

impl HardwareChecker {
pub fn new(issues: Option<Arc<RwLock<IssueReport>>>) -> Self {
pub(crate) fn new(issues: Option<Arc<RwLock<IssueReport>>>) -> Self {
let mut sys = System::new_all();

sys.refresh_all();
Expand All @@ -30,7 +30,7 @@ impl HardwareChecker {
}
}

pub async fn check_hardware(
pub(crate) async fn check_hardware(
&mut self,
node_config: Node,
storage_path_override: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions crates/worker/src/checks/hardware/interconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use rand::RngCore;
use reqwest::Client;
use std::time::Instant;

pub struct InterconnectCheck;
pub(crate) struct InterconnectCheck;

impl InterconnectCheck {
pub async fn check_speeds() -> Result<(f64, f64), Box<dyn std::error::Error>> {
pub(crate) async fn check_speeds() -> Result<(f64, f64), Box<dyn std::error::Error>> {
let client = Client::new();

// Download test: Request a 10 MB file using the query parameter.
Expand Down
6 changes: 3 additions & 3 deletions crates/worker/src/checks/hardware/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use sysinfo::System;

const BYTES_TO_GB: u64 = 1024 * 1024 * 1024;

pub fn get_memory_info(sys: &System) -> (u64, u64) {
pub(crate) fn get_memory_info(sys: &System) -> (u64, u64) {
let total_memory = sys.total_memory();
let free_memory = sys.available_memory();
(total_memory, free_memory)
}

pub fn convert_to_mb(memory: u64) -> u64 {
pub(crate) fn convert_to_mb(memory: u64) -> u64 {
memory / (1024 * 1024)
}

pub fn print_memory_info(total_memory: u64, free_memory: u64) {
pub(crate) fn print_memory_info(total_memory: u64, free_memory: u64) {
let total_gb = (total_memory + BYTES_TO_GB / 2) / BYTES_TO_GB;
let free_gb = (free_memory + BYTES_TO_GB / 2) / BYTES_TO_GB;
Console::title("Memory Information:");
Expand Down
14 changes: 7 additions & 7 deletions crates/worker/src/checks/hardware/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod gpu;
pub mod hardware_check;
pub mod interconnect;
pub mod memory;
pub mod storage;
pub mod storage_path;
pub use hardware_check::HardwareChecker;
pub(crate) mod gpu;
pub(crate) mod hardware_check;
pub(crate) mod interconnect;
pub(crate) mod memory;
pub(crate) mod storage;
pub(crate) mod storage_path;
pub(crate) use hardware_check::HardwareChecker;
14 changes: 7 additions & 7 deletions crates/worker/src/checks/hardware/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ use std::env;
use std::ffi::CString;
#[cfg(target_os = "linux")]
use std::fs;
pub const BYTES_TO_GB: f64 = 1024.0 * 1024.0 * 1024.0;
pub const APP_DIR_NAME: &str = "prime-worker";
pub(crate) const BYTES_TO_GB: f64 = 1024.0 * 1024.0 * 1024.0;
pub(crate) const APP_DIR_NAME: &str = "prime-worker";

#[derive(Clone)]
pub struct MountPoint {
pub(crate) struct MountPoint {
pub path: String,
pub available_space: u64,
}

#[cfg(unix)]
pub fn get_storage_info() -> Result<(f64, f64), std::io::Error> {
pub(crate) fn get_storage_info() -> Result<(f64, f64), std::io::Error> {
let mut stat: libc::statvfs = unsafe { std::mem::zeroed() };

// Use current directory instead of hardcoded "."
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn get_storage_info() -> Result<(f64, f64), std::io::Error> {
))
}
#[cfg(target_os = "linux")]
pub fn find_largest_storage() -> Option<MountPoint> {
pub(crate) fn find_largest_storage() -> Option<MountPoint> {
const VALID_FS: [&str; 4] = ["ext4", "xfs", "btrfs", "zfs"];
const MIN_SPACE: u64 = 1_000_000_000; // 1GB minimum

Expand Down Expand Up @@ -221,7 +221,7 @@ pub fn find_largest_storage() -> Option<MountPoint> {
}

#[cfg(target_os = "linux")]
pub fn get_available_space(path: &str) -> Option<u64> {
pub(crate) fn get_available_space(path: &str) -> Option<u64> {
let mut stats: statvfs_t = unsafe { std::mem::zeroed() };
if let Ok(path_c) = CString::new(path) {
if unsafe { statvfs(path_c.as_ptr(), &mut stats) } == 0 {
Expand All @@ -238,7 +238,7 @@ pub fn get_available_space(_path: &str) -> Option<u64> {
}

#[allow(dead_code)]
pub fn print_storage_info() {
pub(crate) fn print_storage_info() {
match get_storage_info() {
Ok((total, free)) => {
Console::title("Storage Information:");
Expand Down
6 changes: 3 additions & 3 deletions crates/worker/src/checks/hardware/storage_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use log::info;
use std::sync::Arc;
use tokio::sync::RwLock;

pub struct StoragePathDetector {
pub(crate) struct StoragePathDetector {
issues: Arc<RwLock<IssueReport>>,
}

impl StoragePathDetector {
pub fn new(issues: Arc<RwLock<IssueReport>>) -> Self {
pub(crate) fn new(issues: Arc<RwLock<IssueReport>>) -> Self {
Self { issues }
}

pub async fn detect_storage_path(
pub(crate) async fn detect_storage_path(
&self,
storage_path_override: Option<String>,
) -> Result<(String, Option<u64>), Box<dyn std::error::Error>> {
Expand Down
24 changes: 12 additions & 12 deletions crates/worker/src/checks/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::fmt;
use std::sync::{Arc, RwLock};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Severity {
pub(crate) enum Severity {
Warning,
Error,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IssueType {
pub(crate) enum IssueType {
NoGpu, // GPU required for compute
DockerNotInstalled, // Docker required for containers
ContainerToolkitNotInstalled, // Container toolkit required for GPU
Expand All @@ -22,7 +22,7 @@ pub enum IssueType {
}

impl IssueType {
pub const fn severity(&self) -> Severity {
pub(crate) const fn severity(&self) -> Severity {
match self {
Self::NetworkConnectivityIssue
| Self::InsufficientCpu
Expand All @@ -38,24 +38,24 @@ impl IssueType {
}

#[derive(Debug, Clone)]
pub struct Issue {
pub(crate) struct Issue {
issue_type: IssueType,
message: String,
}

impl Issue {
pub fn new(issue_type: IssueType, message: impl Into<String>) -> Self {
pub(crate) fn new(issue_type: IssueType, message: impl Into<String>) -> Self {
Self {
issue_type,
message: message.into(),
}
}

pub const fn severity(&self) -> Severity {
pub(crate) const fn severity(&self) -> Severity {
self.issue_type.severity()
}

pub fn print(&self) {
pub(crate) fn print(&self) {
match self.severity() {
Severity::Error => Console::user_error(&format!("{self}")),
Severity::Warning => Console::warning(&format!("{self}")),
Expand All @@ -70,22 +70,22 @@ impl fmt::Display for Issue {
}

#[derive(Debug, Default, Clone)]
pub struct IssueReport {
pub(crate) struct IssueReport {
issues: Arc<RwLock<Vec<Issue>>>,
}

impl IssueReport {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
Self::default()
}

pub fn add_issue(&self, issue_type: IssueType, message: impl Into<String>) {
pub(crate) fn add_issue(&self, issue_type: IssueType, message: impl Into<String>) {
if let Ok(mut issues) = self.issues.write() {
issues.push(Issue::new(issue_type, message));
}
}

pub fn print_issues(&self) {
pub(crate) fn print_issues(&self) {
if let Ok(issues) = self.issues.read() {
if issues.is_empty() {
Console::success("No issues found");
Expand All @@ -104,7 +104,7 @@ impl IssueReport {
}
}

pub fn has_critical_issues(&self) -> bool {
pub(crate) fn has_critical_issues(&self) -> bool {
if let Ok(issues) = self.issues.read() {
return issues
.iter()
Expand Down
8 changes: 4 additions & 4 deletions crates/worker/src/checks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod hardware;
pub mod issue;
pub mod software;
pub mod stun;
pub(crate) mod hardware;
pub(crate) mod issue;
pub(crate) mod software;
pub(crate) mod stun;
2 changes: 1 addition & 1 deletion crates/worker/src/checks/software/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bollard::Docker;
use std::sync::Arc;
use tokio::sync::RwLock;

pub async fn check_docker_installed(
pub(crate) async fn check_docker_installed(
issues: &Arc<RwLock<IssueReport>>,
) -> Result<(), Box<dyn std::error::Error>> {
let issue_tracker = issues.read().await;
Expand Down
8 changes: 4 additions & 4 deletions crates/worker/src/checks/software/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod docker;
pub mod port;
pub mod software_check;
pub use software_check::SoftwareChecker;
pub(crate) mod docker;
pub(crate) mod port;
pub(crate) mod software_check;
pub(crate) use software_check::SoftwareChecker;
5 changes: 4 additions & 1 deletion crates/worker/src/checks/software/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ fn try_bind_port(port: u16) -> Result<()> {
Ok(())
}

pub async fn check_port_available(issues: &Arc<RwLock<IssueReport>>, port: u16) -> Result<()> {
pub(crate) async fn check_port_available(
issues: &Arc<RwLock<IssueReport>>,
port: u16,
) -> Result<()> {
let issue_tracker = issues.read().await;

match try_bind_port(port) {
Expand Down
6 changes: 3 additions & 3 deletions crates/worker/src/checks/software/software_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ use shared::models::node::Node;
use std::sync::Arc;
use tokio::sync::RwLock;

pub struct SoftwareChecker {
pub(crate) struct SoftwareChecker {
issues: Arc<RwLock<IssueReport>>,
}

impl SoftwareChecker {
pub fn new(issues: Option<Arc<RwLock<IssueReport>>>) -> Self {
pub(crate) fn new(issues: Option<Arc<RwLock<IssueReport>>>) -> Self {
Self {
issues: issues.unwrap_or_else(|| Arc::new(RwLock::new(IssueReport::new()))),
}
}

pub async fn check_software(
pub(crate) async fn check_software(
&self,
node_config: &Node,
) -> Result<(), Box<dyn std::error::Error>> {
Expand Down
8 changes: 5 additions & 3 deletions crates/worker/src/checks/stun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use stun::xoraddr::*;

use tracing::{debug, error, info};

pub struct StunCheck {
pub(crate) struct StunCheck {
pub timeout: Duration,
pub port: u16,
}

impl StunCheck {
pub fn new(timeout: Duration, port: u16) -> Self {
pub(crate) fn new(timeout: Duration, port: u16) -> Self {
Self { timeout, port }
}

Expand Down Expand Up @@ -101,7 +101,9 @@ impl StunCheck {
Ok(public_ip.to_string())
}

pub async fn get_public_ip(&self) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
pub(crate) async fn get_public_ip(
&self,
) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
let stun_servers = [
"stun.l.google.com:19302",
"stun.stunprotocol.org:3478",
Expand Down
1 change: 1 addition & 0 deletions crates/worker/src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
Run {
Expand Down
2 changes: 1 addition & 1 deletion crates/worker/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod command;
pub(crate) mod command;
pub use command::{execute_command, Cli};
Loading