lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

commit 257730a483821b80e3cd1739ffefc7c10011141e
parent e3bca5a488f889040e04d1b4f383abdd5303edb0
Author: triesap <tyson@radroots.org>
Date:   Sun, 12 Apr 2026 04:05:43 +0000

net: collapse public wrapper surface

Diffstat:
MCargo.lock | 7-------
MCargo.toml | 2--
Mcrates/net/Cargo.toml | 53++++++++++++++++++++++++++++++++++++++++++++++++-----
Mcrates/net/README | 14++++++--------
Rcrates/net_core/build.rs -> crates/net/build.rs | 0
Rcrates/net_core/src/builder.rs -> crates/net/src/builder.rs | 0
Rcrates/net_core/src/config.rs -> crates/net/src/config.rs | 0
Rcrates/net_core/src/error.rs -> crates/net/src/error.rs | 0
Rcrates/net_core/src/keys.rs -> crates/net/src/keys.rs | 0
Mcrates/net/src/lib.rs | 36+++++++++++++++---------------------
Acrates/net/src/logging.rs | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rcrates/net_core/src/net.rs -> crates/net/src/net.rs | 0
Rcrates/net_core/src/nostr_client/connection.rs -> crates/net/src/nostr_client/connection.rs | 0
Rcrates/net_core/src/nostr_client/events/custom.rs -> crates/net/src/nostr_client/events/custom.rs | 0
Rcrates/net_core/src/nostr_client/events/post.rs -> crates/net/src/nostr_client/events/post.rs | 0
Rcrates/net_core/src/nostr_client/events/profile.rs -> crates/net/src/nostr_client/events/profile.rs | 0
Rcrates/net_core/src/nostr_client/inner.rs -> crates/net/src/nostr_client/inner.rs | 0
Rcrates/net_core/src/nostr_client/manager.rs -> crates/net/src/nostr_client/manager.rs | 0
Rcrates/net_core/src/nostr_client/mod.rs -> crates/net/src/nostr_client/mod.rs | 0
Rcrates/net_core/src/nostr_client/status.rs -> crates/net/src/nostr_client/status.rs | 0
Rcrates/net_core/src/nostr_client/types.rs -> crates/net/src/nostr_client/types.rs | 0
Acrates/net/tests/error.rs | 38++++++++++++++++++++++++++++++++++++++
Dcrates/net_core/Cargo.toml | 65-----------------------------------------------------------------
Dcrates/net_core/README | 23-----------------------
Dcrates/net_core/src/lib.rs | 20--------------------
Dcrates/net_core/src/logging.rs | 83-------------------------------------------------------------------------------
Dcrates/net_core/tests/error.rs | 38--------------------------------------
Mpolicy/coverage/policy.toml | 1-
28 files changed, 190 insertions(+), 273 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -2389,13 +2389,6 @@ dependencies = [ name = "radroots_net" version = "0.1.0-alpha.2" dependencies = [ - "radroots_net_core", -] - -[[package]] -name = "radroots_net_core" -version = "0.1.0-alpha.2" -dependencies = [ "directories", "futures", "hex", diff --git a/Cargo.toml b/Cargo.toml @@ -9,7 +9,6 @@ members = [ "crates/identity", "crates/log", "crates/net", - "crates/net_core", "crates/nostr", "crates/nostr_accounts", "crates/nostr_connect", @@ -72,7 +71,6 @@ radroots_runtime_distribution = { path = "crates/runtime_distribution", version radroots_runtime_manager = { path = "crates/runtime_manager", version = "0.1.0-alpha.2", default-features = false } radroots_log = { path = "crates/log", version = "0.1.0-alpha.2", default-features = false } radroots_net = { path = "crates/net", version = "0.1.0-alpha.2", default-features = false } -radroots_net_core = { path = "crates/net_core", version = "0.1.0-alpha.2", default-features = false } radroots_nostr_runtime = { path = "crates/nostr_runtime", version = "0.1.0-alpha.2", default-features = false } radroots_simplex_agent_proto = { path = "crates/simplex_agent_proto", version = "0.1.0-alpha.1", default-features = false } radroots_simplex_agent_runtime = { path = "crates/simplex_agent_runtime", version = "0.1.0-alpha.1", default-features = false } diff --git a/crates/net/Cargo.toml b/crates/net/Cargo.toml @@ -6,7 +6,7 @@ edition.workspace = true authors = ["Tyson Lupul <tyson@radroots.org>"] rust-version.workspace = true license.workspace = true -description = "Unified networking facade over radroots-net-core" +description = "Network orchestration and runtime interfaces" repository.workspace = true homepage.workspace = true documentation = "https://docs.rs/radroots_net" @@ -14,9 +14,52 @@ readme = "README" [features] default = ["std"] -std = ["radroots_net_core/std"] -rt = ["radroots_net_core/rt"] -all = ["std", "rt"] +std = ["serde/std"] +rt = ["std", "dep:tokio"] +nostr-client = [ + "std", + "dep:radroots_events", + "dep:radroots_events_codec", + "radroots_events/serde", + "dep:radroots_nostr_accounts", + "dep:radroots_nostr_signer", + "dep:secrecy", + "dep:hex", + "dep:tempfile", + "dep:serde_json", + "dep:radroots_nostr", +] +directories = ["std", "dep:directories"] +fs-persistence = ["std", "dep:radroots_runtime_paths"] [dependencies] -radroots_net_core = { workspace = true, optional = false } +radroots_events = { workspace = true, optional = true, default-features = true, features = [ + "std", + "serde", + "typeshare", +] } +radroots_log = { workspace = true, features = ["std"] } +radroots_nostr_accounts = { workspace = true, optional = true, default-features = true } +radroots_nostr_signer = { workspace = true, optional = true } +radroots_events_codec = { workspace = true, optional = true, default-features = true, features = [ + "std", +] } +radroots_nostr = { workspace = true, optional = true, default-features = true, features = [ + "client", + "events", + "codec", +] } +directories = { workspace = true, optional = true } +hex = { workspace = true, optional = true } +radroots_runtime_paths = { workspace = true, optional = true } +secrecy = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true, optional = true } +tempfile = { workspace = true, optional = true } +thiserror = { workspace = true } +tokio = { workspace = true, optional = true, features = ["rt-multi-thread"] } +tracing = { workspace = true } +futures = { workspace = true } + +[dev-dependencies] +radroots_identity = { workspace = true, default-features = true } diff --git a/crates/net/README b/crates/net/README @@ -1,16 +1,14 @@ # radroots_net -This is the README for `radroots_net`, which re-exports the unified networking -facade from `radroots_net_core` for the `radroots` core libraries. +This is the README for `radroots_net`, which provides network orchestration and +runtime interfaces for the `radroots` core libraries. ## Overview - * reexports `radroots_net_core` as the public `core` module; - * forwards the `std`, `rt`, and aggregate feature surface used by networking - consumers; - * adds no additional networking logic beyond the reexport layer; - * keeps the workspace-facing network entry point separate from the lower-level - implementation crate. + * networking configuration and builders; + * runtime-aware network handle and lifecycle support; + * optional Nostr client integration and key management helpers; + * optional logging and runtime-path persistence integration. ## Copyright diff --git a/crates/net_core/build.rs b/crates/net/build.rs diff --git a/crates/net_core/src/builder.rs b/crates/net/src/builder.rs diff --git a/crates/net_core/src/config.rs b/crates/net/src/config.rs diff --git a/crates/net_core/src/error.rs b/crates/net/src/error.rs diff --git a/crates/net_core/src/keys.rs b/crates/net/src/keys.rs diff --git a/crates/net/src/lib.rs b/crates/net/src/lib.rs @@ -1,26 +1,20 @@ -pub use radroots_net_core as core; +#![cfg_attr(not(feature = "std"), no_std)] -pub fn coverage_core_alias_available() -> bool { - let _ = core::config::NetConfig::default(); - true -} +extern crate alloc; -pub fn coverage_branch_probe(input: bool) -> bool { - if input { true } else { false } -} +pub mod error; +pub mod net; -#[cfg(test)] -mod tests { - use super::{coverage_branch_probe, coverage_core_alias_available}; +#[cfg(feature = "std")] +pub mod logging; - #[test] - fn core_alias_probe_is_callable() { - assert!(coverage_core_alias_available()); - } +pub mod builder; +pub mod config; - #[test] - fn coverage_branch_probe_hits_both_paths() { - assert!(coverage_branch_probe(true)); - assert!(!coverage_branch_probe(false)); - } -} +#[cfg(feature = "nostr-client")] +pub mod keys; + +#[cfg(feature = "nostr-client")] +pub mod nostr_client; + +pub use net::{Net, NetHandle, NetInfo}; diff --git a/crates/net/src/logging.rs b/crates/net/src/logging.rs @@ -0,0 +1,83 @@ +use crate::error::{NetError, Result}; +use std::path::PathBuf; +use tracing::info; + +#[derive(Debug, Clone)] +pub struct LoggingOptions { + pub dir: Option<PathBuf>, + pub file_name: String, + pub also_stdout: bool, +} + +impl Default for LoggingOptions { + fn default() -> Self { + Self { + dir: None, + file_name: "radroots_net.log".into(), + also_stdout: true, + } + } +} + +pub fn init_logging(opts: LoggingOptions) -> Result<()> { + let log_opts = radroots_log::LoggingOptions { + dir: opts.dir.clone(), + file_name: opts.file_name.clone(), + stdout: opts.also_stdout, + default_level: None, + file_layout: radroots_log::LogFileLayout::PrefixedDate, + }; + match radroots_log::init_logging(log_opts) { + Ok(()) => {} + Err(_) => return Err(NetError::LoggingInit("init")), + } + let file_path = opts + .dir + .as_ref() + .map(|d| d.join(&opts.file_name).display().to_string()) + .unwrap_or_else(|| "<disabled>".into()); + info!( + "logging initialized (file: {}, stdout: {})", + file_path, opts.also_stdout + ); + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::{LoggingOptions, init_logging}; + use crate::error::NetError; + use std::path::PathBuf; + + #[test] + fn logging_options_default_values_are_stable() { + let defaults = LoggingOptions::default(); + assert_eq!(defaults.dir, None); + assert_eq!(defaults.file_name, "radroots_net.log"); + assert!(defaults.also_stdout); + } + + #[test] + fn init_logging_covers_error_and_success_paths() { + let invalid = init_logging(LoggingOptions { + dir: Some(PathBuf::from("/dev/null/file")), + file_name: "x.log".to_string(), + also_stdout: false, + }); + assert!(matches!(invalid, Err(NetError::LoggingInit("init")))); + + let valid_with_dir = init_logging(LoggingOptions { + dir: Some(std::env::temp_dir().join("radroots_net-log-tests")), + file_name: "ok.log".to_string(), + also_stdout: false, + }); + assert!(valid_with_dir.is_ok()); + + let valid_without_dir = init_logging(LoggingOptions { + dir: None, + file_name: "ok2.log".to_string(), + also_stdout: true, + }); + assert!(valid_without_dir.is_ok()); + } +} diff --git a/crates/net_core/src/net.rs b/crates/net/src/net.rs diff --git a/crates/net_core/src/nostr_client/connection.rs b/crates/net/src/nostr_client/connection.rs diff --git a/crates/net_core/src/nostr_client/events/custom.rs b/crates/net/src/nostr_client/events/custom.rs diff --git a/crates/net_core/src/nostr_client/events/post.rs b/crates/net/src/nostr_client/events/post.rs diff --git a/crates/net_core/src/nostr_client/events/profile.rs b/crates/net/src/nostr_client/events/profile.rs diff --git a/crates/net_core/src/nostr_client/inner.rs b/crates/net/src/nostr_client/inner.rs diff --git a/crates/net_core/src/nostr_client/manager.rs b/crates/net/src/nostr_client/manager.rs diff --git a/crates/net_core/src/nostr_client/mod.rs b/crates/net/src/nostr_client/mod.rs diff --git a/crates/net_core/src/nostr_client/status.rs b/crates/net/src/nostr_client/status.rs diff --git a/crates/net_core/src/nostr_client/types.rs b/crates/net/src/nostr_client/types.rs diff --git a/crates/net/tests/error.rs b/crates/net/tests/error.rs @@ -0,0 +1,38 @@ +use radroots_net::error::NetError; +use std::panic::{AssertUnwindSafe, catch_unwind}; + +#[test] +fn msg_constructor_creates_msg_variant() { + let err = NetError::msg("hello"); + assert!(matches!(err, NetError::Msg(ref message) if message == "hello")); +} + +#[test] +fn clone_covers_non_io_variants() { + let variants = [ + NetError::msg("hello"), + NetError::Poisoned, + NetError::MissingKey, + NetError::InvalidHex32, + NetError::InvalidBech32, + NetError::InvalidKeyFile, + NetError::KeyIo, + NetError::OverwriteDenied, + NetError::PersistencePathRequired, + NetError::PersistenceUnsupported, + NetError::LoggingInit("init"), + ]; + for variant in variants { + let cloned = variant.clone(); + assert_eq!(format!("{variant}"), format!("{cloned}")); + } +} + +#[test] +fn clone_panics_for_io_variant() { + let io_err = NetError::Io(std::io::Error::other("io")); + let result = catch_unwind(AssertUnwindSafe(|| { + let _ = io_err.clone(); + })); + assert!(result.is_err()); +} diff --git a/crates/net_core/Cargo.toml b/crates/net_core/Cargo.toml @@ -1,65 +0,0 @@ -[package] -name = "radroots_net_core" -publish = ["crates-io"] -version = "0.1.0-alpha.2" -edition.workspace = true -authors = ["Tyson Lupul <tyson@radroots.org>"] -rust-version.workspace = true -license.workspace = true -description = "Network orchestration and runtime interfaces" -repository.workspace = true -homepage.workspace = true -documentation = "https://docs.rs/radroots_net_core" -readme = "README" - -[features] -default = ["std"] -std = ["serde/std"] -rt = ["std", "dep:tokio"] -nostr-client = [ - "std", - "dep:radroots_events", - "dep:radroots_events_codec", - "radroots_events/serde", - "dep:radroots_nostr_accounts", - "dep:radroots_nostr_signer", - "dep:secrecy", - "dep:hex", - "dep:tempfile", - "dep:serde_json", - "dep:radroots_nostr", -] -directories = ["std", "dep:directories"] -fs-persistence = ["std", "dep:radroots_runtime_paths"] - -[dependencies] -radroots_events = { workspace = true, optional = true, default-features = true, features = [ - "std", - "serde", - "typeshare", -] } -radroots_log = { workspace = true, features = ["std"] } -radroots_nostr_accounts = { workspace = true, optional = true, default-features = true } -radroots_nostr_signer = { workspace = true, optional = true } -radroots_events_codec = { workspace = true, optional = true, default-features = true, features = [ - "std", -] } -radroots_nostr = { workspace = true, optional = true, default-features = true, features = [ - "client", - "events", - "codec", -] } -directories = { workspace = true, optional = true } -hex = { workspace = true, optional = true } -radroots_runtime_paths = { workspace = true, optional = true } -secrecy = { workspace = true, optional = true } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, optional = true } -tempfile = { workspace = true, optional = true } -thiserror = { workspace = true } -tokio = { workspace = true, optional = true, features = ["rt-multi-thread"] } -tracing = { workspace = true } -futures = { workspace = true } - -[dev-dependencies] -radroots_identity = { workspace = true, default-features = true } diff --git a/crates/net_core/README b/crates/net_core/README @@ -1,23 +0,0 @@ -# radroots_net_core - -This is the README for `radroots_net_core`, which provides network -orchestration and runtime interfaces for the `radroots` core libraries. - -## Overview - - * `Net`, `NetHandle`, and `NetInfo` types for managing shared network state - and build metadata; - * runtime-aware wiring for accounts, signer state, relay sets, and the Nostr - runtime; - * key format and persistence configuration for local key material handling; - * feature-gated `std`, runtime, client, and filesystem persistence support. - -## Copyright - -Except as otherwise noted, all files in the `radroots_net_core` distribution -are - - Copyright (c) 2020-2026 Tyson Lupul - -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see LICENSE included in the `radroots_net_core` distribution. diff --git a/crates/net_core/src/lib.rs b/crates/net_core/src/lib.rs @@ -1,20 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -extern crate alloc; - -pub mod error; -pub mod net; - -#[cfg(feature = "std")] -pub mod logging; - -pub mod builder; -pub mod config; - -#[cfg(feature = "nostr-client")] -pub mod keys; - -#[cfg(feature = "nostr-client")] -pub mod nostr_client; - -pub use net::{Net, NetHandle, NetInfo}; diff --git a/crates/net_core/src/logging.rs b/crates/net_core/src/logging.rs @@ -1,83 +0,0 @@ -use crate::error::{NetError, Result}; -use std::path::PathBuf; -use tracing::info; - -#[derive(Debug, Clone)] -pub struct LoggingOptions { - pub dir: Option<PathBuf>, - pub file_name: String, - pub also_stdout: bool, -} - -impl Default for LoggingOptions { - fn default() -> Self { - Self { - dir: None, - file_name: "radroots_net_core.log".into(), - also_stdout: true, - } - } -} - -pub fn init_logging(opts: LoggingOptions) -> Result<()> { - let log_opts = radroots_log::LoggingOptions { - dir: opts.dir.clone(), - file_name: opts.file_name.clone(), - stdout: opts.also_stdout, - default_level: None, - file_layout: radroots_log::LogFileLayout::PrefixedDate, - }; - match radroots_log::init_logging(log_opts) { - Ok(()) => {} - Err(_) => return Err(NetError::LoggingInit("init")), - } - let file_path = opts - .dir - .as_ref() - .map(|d| d.join(&opts.file_name).display().to_string()) - .unwrap_or_else(|| "<disabled>".into()); - info!( - "logging initialized (file: {}, stdout: {})", - file_path, opts.also_stdout - ); - Ok(()) -} - -#[cfg(test)] -mod tests { - use super::{LoggingOptions, init_logging}; - use crate::error::NetError; - use std::path::PathBuf; - - #[test] - fn logging_options_default_values_are_stable() { - let defaults = LoggingOptions::default(); - assert_eq!(defaults.dir, None); - assert_eq!(defaults.file_name, "radroots_net_core.log"); - assert!(defaults.also_stdout); - } - - #[test] - fn init_logging_covers_error_and_success_paths() { - let invalid = init_logging(LoggingOptions { - dir: Some(PathBuf::from("/dev/null/file")), - file_name: "x.log".to_string(), - also_stdout: false, - }); - assert!(matches!(invalid, Err(NetError::LoggingInit("init")))); - - let valid_with_dir = init_logging(LoggingOptions { - dir: Some(std::env::temp_dir().join("radroots_net_core-log-tests")), - file_name: "ok.log".to_string(), - also_stdout: false, - }); - assert!(valid_with_dir.is_ok()); - - let valid_without_dir = init_logging(LoggingOptions { - dir: None, - file_name: "ok2.log".to_string(), - also_stdout: true, - }); - assert!(valid_without_dir.is_ok()); - } -} diff --git a/crates/net_core/tests/error.rs b/crates/net_core/tests/error.rs @@ -1,38 +0,0 @@ -use radroots_net_core::error::NetError; -use std::panic::{AssertUnwindSafe, catch_unwind}; - -#[test] -fn msg_constructor_creates_msg_variant() { - let err = NetError::msg("hello"); - assert!(matches!(err, NetError::Msg(ref message) if message == "hello")); -} - -#[test] -fn clone_covers_non_io_variants() { - let variants = [ - NetError::msg("hello"), - NetError::Poisoned, - NetError::MissingKey, - NetError::InvalidHex32, - NetError::InvalidBech32, - NetError::InvalidKeyFile, - NetError::KeyIo, - NetError::OverwriteDenied, - NetError::PersistencePathRequired, - NetError::PersistenceUnsupported, - NetError::LoggingInit("init"), - ]; - for variant in variants { - let cloned = variant.clone(); - assert_eq!(format!("{variant}"), format!("{cloned}")); - } -} - -#[test] -fn clone_panics_for_io_variant() { - let io_err = NetError::Io(std::io::Error::other("io")); - let result = catch_unwind(AssertUnwindSafe(|| { - let _ = io_err.clone(); - })); - assert!(result.is_err()); -} diff --git a/policy/coverage/policy.toml b/policy/coverage/policy.toml @@ -151,7 +151,6 @@ crates = [ "radroots_sql_wasm_core", "radroots_nostr_accounts", "radroots_replica_sync", - "radroots_net_core", "radroots_replica_db_wasm", "radroots_replica_sync_wasm", "radroots_net",