Jason Tudisco 620966872e Add plain-English comments to all functions across src/ and examples/
Comments help non-Rust users understand what each function, struct, and
module does. Covers the core service (18 source files) and all four
example projects (can-sync, canfs, filemanager, paste).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 14:35:24 -06:00

43 lines
1.4 KiB
Rust

use serde::Deserialize;
use std::path::Path;
/// All settings needed to run the sync agent, loaded from a YAML file.
#[derive(Debug, Clone, Deserialize)]
pub struct SyncConfig {
/// Base URL of the local CAN service (e.g. "http://127.0.0.1:3210")
pub can_service_url: String,
/// API key for CAN service's sync endpoints (must match config.sync_api_key)
pub sync_api_key: String,
/// Shared passphrase for peer discovery (all peers must use the same one)
pub sync_passphrase: String,
/// Seconds between polls for new local assets
#[serde(default = "default_poll_interval")]
pub poll_interval_secs: u64,
/// Optional: path to write this node's ticket to (for direct connection)
#[serde(default)]
pub ticket_file: Option<String>,
/// Optional: path to a file containing a peer's node ticket (for direct connection).
/// If set, the agent will read this ticket and connect directly instead of waiting
/// for gossip discovery. The file is polled until it exists and is non-empty.
#[serde(default)]
pub connect_ticket_file: Option<String>,
}
fn default_poll_interval() -> u64 {
3
}
impl SyncConfig {
/// Read a YAML config file from disk and parse it into a SyncConfig.
pub fn load(path: &Path) -> anyhow::Result<Self> {
let contents = std::fs::read_to_string(path)?;
let config: Self = serde_yaml::from_str(&contents)?;
Ok(config)
}
}