lib

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

commit 8588e831cb166274fb7d3ed63922b5da6ba1dbe7
parent 7f1c6ca76b7c4fb531245ad82e4017f9bde351c9
Author: triesap <tyson@radroots.org>
Date:   Thu, 19 Feb 2026 16:11:19 +0000

nostr-runtime: add runtime crate scaffold


- add `radroots-nostr-runtime` crate manifest and workspace registration
- define initial runtime types for subscriptions events and connection snapshots
- add runtime error enum and builder/runtime api surface placeholders
- update cargo lock for the new crate dependency graph

Diffstat:
MCargo.lock | 9+++++++++
MCargo.toml | 2++
Anostr-runtime/Cargo.toml | 19+++++++++++++++++++
Anostr-runtime/src/error.rs | 19+++++++++++++++++++
Anostr-runtime/src/lib.rs | 20++++++++++++++++++++
Anostr-runtime/src/runtime.rs | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anostr-runtime/src/types.rs | 42++++++++++++++++++++++++++++++++++++++++++
7 files changed, 181 insertions(+), 0 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -1983,6 +1983,15 @@ dependencies = [ ] [[package]] +name = "radroots-nostr-runtime" +version = "0.1.0" +dependencies = [ + "radroots-nostr", + "thiserror 1.0.69", + "tokio", +] + +[[package]] name = "radroots-runtime" version = "0.1.0" dependencies = [ diff --git a/Cargo.toml b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "net", "net-core", "nostr", + "nostr-runtime", "runtime", "sql-wasm-bridge", "sql-wasm-core", @@ -47,6 +48,7 @@ radroots-runtime = { path = "runtime", version = "0.1.0", default-features = fal radroots-log = { path = "log", version = "0.1.0", default-features = false } radroots-net = { path = "net", version = "0.1.0", default-features = false } radroots-net-core = { path = "net-core", version = "0.1.0", default-features = false } +radroots-nostr-runtime = { path = "nostr-runtime", version = "0.1.0", default-features = false } radroots-sql-wasm-bridge = { path = "sql-wasm-bridge", version = "0.1.0" } radroots-sql-wasm-core = { path = "sql-wasm-core", version = "0.1.0", default-features = false } radroots-sql-core = { path = "sql-core", version = "0.1.0" } diff --git a/nostr-runtime/Cargo.toml b/nostr-runtime/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "radroots-nostr-runtime" +version.workspace = true +edition.workspace = true +authors = ["Radroots Authors"] +rust-version.workspace = true +license.workspace = true + +[features] +default = ["std", "nostr-client", "rt"] +std = [] +rt = ["std", "dep:tokio"] +nostr-client = ["std", "dep:radroots-nostr"] +nostr-ndb = ["nostr-client"] + +[dependencies] +radroots-nostr = { workspace = true, optional = true, default-features = true, features = ["client"] } +thiserror = { workspace = true } +tokio = { workspace = true, optional = true, features = ["rt", "sync", "time"] } diff --git a/nostr-runtime/src/error.rs b/nostr-runtime/src/error.rs @@ -0,0 +1,19 @@ +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum RadrootsNostrRuntimeError { + #[error("runtime not started")] + RuntimeNotStarted, + + #[error("runtime already started")] + RuntimeAlreadyStarted, + + #[error("runtime shutdown")] + RuntimeShutdown, + + #[error("missing required runtime configuration: {0}")] + MissingConfig(&'static str), + + #[error("runtime error: {0}")] + Runtime(String), +} diff --git a/nostr-runtime/src/lib.rs b/nostr-runtime/src/lib.rs @@ -0,0 +1,20 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +pub mod error; +pub mod types; + +#[cfg(all(feature = "nostr-client", feature = "rt"))] +pub mod runtime; + +pub mod prelude { + pub use crate::error::RadrootsNostrRuntimeError; + #[cfg(all(feature = "nostr-client", feature = "rt"))] + pub use crate::runtime::{RadrootsNostrRuntime, RadrootsNostrRuntimeBuilder}; + pub use crate::types::{ + RadrootsNostrConnectionSnapshot, RadrootsNostrRuntimeEvent, + RadrootsNostrSubscriptionHandle, RadrootsNostrSubscriptionPolicy, + RadrootsNostrSubscriptionSpec, RadrootsNostrTrafficLight, + }; +} diff --git a/nostr-runtime/src/runtime.rs b/nostr-runtime/src/runtime.rs @@ -0,0 +1,70 @@ +use crate::error::RadrootsNostrRuntimeError; +use crate::types::{ + RadrootsNostrConnectionSnapshot, RadrootsNostrRuntimeEvent, RadrootsNostrSubscriptionHandle, + RadrootsNostrSubscriptionSpec, RadrootsNostrTrafficLight, +}; + +#[derive(Debug, Default, Clone)] +pub struct RadrootsNostrRuntimeBuilder { + queue_capacity: Option<usize>, +} + +impl RadrootsNostrRuntimeBuilder { + pub fn new() -> Self { + Self::default() + } + + pub fn queue_capacity(mut self, capacity: usize) -> Self { + self.queue_capacity = Some(capacity); + self + } + + pub fn build(self) -> Result<RadrootsNostrRuntime, RadrootsNostrRuntimeError> { + let _ = self.queue_capacity; + Ok(RadrootsNostrRuntime {}) + } +} + +#[derive(Debug, Clone)] +pub struct RadrootsNostrRuntime {} + +impl RadrootsNostrRuntime { + pub async fn start(&self) -> Result<(), RadrootsNostrRuntimeError> { + Ok(()) + } + + pub async fn shutdown(&self) -> Result<(), RadrootsNostrRuntimeError> { + Ok(()) + } + + pub async fn subscribe( + &self, + _spec: RadrootsNostrSubscriptionSpec, + ) -> Result<RadrootsNostrSubscriptionHandle, RadrootsNostrRuntimeError> { + Err(RadrootsNostrRuntimeError::Runtime( + "subscribe not implemented".to_string(), + )) + } + + pub async fn unsubscribe( + &self, + _handle: &RadrootsNostrSubscriptionHandle, + ) -> Result<(), RadrootsNostrRuntimeError> { + Err(RadrootsNostrRuntimeError::Runtime( + "unsubscribe not implemented".to_string(), + )) + } + + pub fn drain_events(&self, _max: usize) -> alloc::vec::Vec<RadrootsNostrRuntimeEvent> { + alloc::vec::Vec::new() + } + + pub fn snapshot(&self) -> RadrootsNostrConnectionSnapshot { + RadrootsNostrConnectionSnapshot { + light: RadrootsNostrTrafficLight::Red, + connected: 0, + connecting: 0, + last_error: None, + } + } +} diff --git a/nostr-runtime/src/types.rs b/nostr-runtime/src/types.rs @@ -0,0 +1,42 @@ +use alloc::string::String; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RadrootsNostrSubscriptionPolicy { + Streaming, + OneShotOnEose, +} + +#[derive(Debug, Clone)] +pub struct RadrootsNostrSubscriptionSpec { + pub name: Option<String>, + pub policy: RadrootsNostrSubscriptionPolicy, +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RadrootsNostrSubscriptionHandle { + pub id: String, +} + +#[derive(Debug, Clone)] +pub enum RadrootsNostrRuntimeEvent { + SubscriptionOpened { id: String }, + SubscriptionClosed { id: String }, + Note { id: String, relay: String }, + Notice { relay: String, message: String }, + Error { message: String }, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RadrootsNostrTrafficLight { + Red, + Yellow, + Green, +} + +#[derive(Debug, Clone)] +pub struct RadrootsNostrConnectionSnapshot { + pub light: RadrootsNostrTrafficLight, + pub connected: usize, + pub connecting: usize, + pub last_error: Option<String>, +}