thenodes 0.2.0

TheNodes is a modular, plugin-driven P2P node framework for Rust, supporting node-embedded plugins (NEP) and core-as-a-library (CAL) modes with async-first APIs.
Documentation
pub mod bootstrap;
pub(crate) mod events;
pub mod listener;
pub mod message;
pub mod peer;
pub mod peer_manager;
pub mod peer_store;
pub mod relay;
pub mod transport;

pub use bootstrap::connect_to_bootstrap_nodes;
pub use listener::start_listener;
pub use message::{Message, MessageType};
pub use peer::Peer;
pub use peer_manager::PeerManager;
pub use peer_store::{PeerSource, PeerStore};
pub use transport::connect_to_peer;

pub(crate) fn advertised_capabilities(config: &crate::config::Config) -> Option<Vec<String>> {
    let mut caps = Vec::new();
    if let Some(relay) = config.network.as_ref().and_then(|n| n.relay.as_ref()) {
        if relay.enabled.unwrap_or(false) {
            caps.push("relay".to_string());
            if relay.store_forward.unwrap_or(false) {
                caps.push("relay_store_forward".to_string());
            }
        }
    }
    if caps.is_empty() {
        None
    } else {
        Some(caps)
    }
}

// Quality-of-Service preferences for relay bindings and forwards
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum QoS {
    // Prioritize lowest latency; bypass queues when possible
    LowLatency,
    // Favor throughput; enqueue at front for faster draining
    HighThroughput,
    // Deprioritized traffic; enqueue at back and soft-drop under pressure
    Bulk,
}

pub struct Network {
    pub peers: Vec<String>, // Placeholder
}

impl Default for Network {
    fn default() -> Self {
        Self::new()
    }
}

impl Network {
    pub fn new() -> Self {
        Self { peers: vec![] }
    }

    pub fn add_peer(&mut self, peer: String) {
        self.peers.push(peer);
    }
}